PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/osgi/service/src/main/java/org/jboss/as/osgi/parser/OSGiExtension.java

#
Java | 91 lines | 48 code | 12 blank | 31 comment | 2 complexity | c4f854c72244b98bad8cb1a43da16d0e MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.osgi.parser;
  23. import java.util.EnumSet;
  24. import org.jboss.as.controller.Extension;
  25. import org.jboss.as.controller.ExtensionContext;
  26. import org.jboss.as.controller.PathElement;
  27. import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
  28. import org.jboss.as.controller.SubsystemRegistration;
  29. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  30. import org.jboss.as.controller.parsing.ExtensionParsingContext;
  31. import org.jboss.as.controller.registry.AttributeAccess;
  32. import org.jboss.as.controller.registry.AttributeAccess.Storage;
  33. import org.jboss.as.controller.registry.ManagementResourceRegistration;
  34. import org.jboss.as.controller.registry.OperationEntry;
  35. /**
  36. * Domain extension used to initialize the OSGi subsystem.
  37. *
  38. * @author Thomas.Diesler@jboss.com
  39. * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
  40. * @author David Bosschaert
  41. */
  42. public class OSGiExtension implements Extension {
  43. public static final String SUBSYSTEM_NAME = "osgi";
  44. @Override
  45. public void initializeParsers(ExtensionParsingContext context) {
  46. context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_0.getUriString(), OSGiNamespace10Parser.INSTANCE);
  47. context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_1.getUriString(), OSGiNamespace11Parser.INSTANCE);
  48. context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_2.getUriString(), OSGiNamespace12Parser.INSTANCE);
  49. }
  50. @Override
  51. public void initialize(ExtensionContext context) {
  52. boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid();
  53. final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0);
  54. final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(OSGiSubsystemProviders.SUBSYSTEM);
  55. registration.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiSubsystemAdd.INSTANCE, OSGiSubsystemAdd.DESCRIPTION, false);
  56. registration.registerReadWriteAttribute(ModelConstants.ACTIVATION, null, ActivationAttributeHandler.INSTANCE, EnumSet.of(AttributeAccess.Flag.STORAGE_CONFIGURATION, AttributeAccess.Flag.RESTART_JVM));
  57. if (registerRuntimeOnly) {
  58. registration.registerReadWriteAttribute(ModelConstants.STARTLEVEL, StartLevelHandler.READ_HANDLER, StartLevelHandler.WRITE_HANDLER, Storage.RUNTIME);
  59. registration.registerOperationHandler(ModelConstants.ACTIVATE, ActivateOperationHandler.INSTANCE, ActivateOperationHandler.INSTANCE, EnumSet.of(OperationEntry.Flag.RESTART_NONE));
  60. }
  61. registration.registerOperationHandler(ModelDescriptionConstants.DESCRIBE, OSGiSubsystemDescribeHandler.INSTANCE, OSGiSubsystemAdd.DESCRIPTION, false, OperationEntry.EntryType.PRIVATE);
  62. registration.registerOperationHandler(ModelDescriptionConstants.REMOVE, ReloadRequiredRemoveStepHandler.INSTANCE, OSGiSubsystemProviders.SUBSYSTEM_REMOVE, false);
  63. // Framework Properties
  64. ManagementResourceRegistration properties = registration.registerSubModel(PathElement.pathElement(ModelConstants.PROPERTY), OSGiSubsystemProviders.PROPERTY_DESCRIPTION);
  65. properties.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiFrameworkPropertyAdd.INSTANCE, OSGiFrameworkPropertyAdd.DESCRIPTION, false);
  66. properties.registerOperationHandler(ModelDescriptionConstants.REMOVE, OSGiFrameworkPropertyRemove.INSTANCE, OSGiFrameworkPropertyRemove.DESCRIPTION, false);
  67. properties.registerReadWriteAttribute(ModelConstants.VALUE, null, OSGiFrameworkPropertyWrite.INSTANCE, Storage.CONFIGURATION);
  68. // Framework Capabilities
  69. ManagementResourceRegistration capabilities = registration.registerSubModel(PathElement.pathElement(ModelConstants.CAPABILITY), OSGiSubsystemProviders.CAPABILITY_DESCRIPTION);
  70. capabilities.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiCapabilityAdd.INSTANCE, OSGiCapabilityAdd.DESCRIPTION, false);
  71. capabilities.registerOperationHandler(ModelDescriptionConstants.REMOVE, OSGiCapabilityRemove.INSTANCE, OSGiCapabilityRemove.DESCRIPTION, false);
  72. if (registerRuntimeOnly) {
  73. // Bundles present at runtime, this info is not available for controllers
  74. ManagementResourceRegistration bundles = registration.registerSubModel(PathElement.pathElement(ModelConstants.BUNDLE), OSGiSubsystemProviders.BUNDLE_DESCRIPTION);
  75. BundleRuntimeHandler.INSTANCE.register(bundles);
  76. }
  77. subsystem.registerXMLElementWriter(OSGiSubsystemWriter.INSTANCE);
  78. }
  79. }