/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 */
22package org.jboss.as.osgi.parser;
23
24import java.util.EnumSet;
25
26import org.jboss.as.controller.Extension;
27import org.jboss.as.controller.ExtensionContext;
28import org.jboss.as.controller.PathElement;
29import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
30import org.jboss.as.controller.SubsystemRegistration;
31import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
32import org.jboss.as.controller.parsing.ExtensionParsingContext;
33import org.jboss.as.controller.registry.AttributeAccess;
34import org.jboss.as.controller.registry.AttributeAccess.Storage;
35import org.jboss.as.controller.registry.ManagementResourceRegistration;
36import org.jboss.as.controller.registry.OperationEntry;
37
38/**
39 * Domain extension used to initialize the OSGi subsystem.
40 *
41 * @author Thomas.Diesler@jboss.com
42 * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
43 * @author David Bosschaert
44 */
45public class OSGiExtension implements Extension {
46
47 public static final String SUBSYSTEM_NAME = "osgi";
48
49 @Override
50 public void initializeParsers(ExtensionParsingContext context) {
51 context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_0.getUriString(), OSGiNamespace10Parser.INSTANCE);
52 context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_1.getUriString(), OSGiNamespace11Parser.INSTANCE);
53 context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.VERSION_1_2.getUriString(), OSGiNamespace12Parser.INSTANCE);
54 }
55
56 @Override
57 public void initialize(ExtensionContext context) {
58
59 boolean registerRuntimeOnly = context.isRuntimeOnlyRegistrationValid();
60
61 final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0);
62 final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(OSGiSubsystemProviders.SUBSYSTEM);
63 registration.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiSubsystemAdd.INSTANCE, OSGiSubsystemAdd.DESCRIPTION, false);
64 registration.registerReadWriteAttribute(ModelConstants.ACTIVATION, null, ActivationAttributeHandler.INSTANCE, EnumSet.of(AttributeAccess.Flag.STORAGE_CONFIGURATION, AttributeAccess.Flag.RESTART_JVM));
65 if (registerRuntimeOnly) {
66 registration.registerReadWriteAttribute(ModelConstants.STARTLEVEL, StartLevelHandler.READ_HANDLER, StartLevelHandler.WRITE_HANDLER, Storage.RUNTIME);
67 registration.registerOperationHandler(ModelConstants.ACTIVATE, ActivateOperationHandler.INSTANCE, ActivateOperationHandler.INSTANCE, EnumSet.of(OperationEntry.Flag.RESTART_NONE));
68 }
69 registration.registerOperationHandler(ModelDescriptionConstants.DESCRIBE, OSGiSubsystemDescribeHandler.INSTANCE, OSGiSubsystemAdd.DESCRIPTION, false, OperationEntry.EntryType.PRIVATE);
70 registration.registerOperationHandler(ModelDescriptionConstants.REMOVE, ReloadRequiredRemoveStepHandler.INSTANCE, OSGiSubsystemProviders.SUBSYSTEM_REMOVE, false);
71
72 // Framework Properties
73 ManagementResourceRegistration properties = registration.registerSubModel(PathElement.pathElement(ModelConstants.PROPERTY), OSGiSubsystemProviders.PROPERTY_DESCRIPTION);
74 properties.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiFrameworkPropertyAdd.INSTANCE, OSGiFrameworkPropertyAdd.DESCRIPTION, false);
75 properties.registerOperationHandler(ModelDescriptionConstants.REMOVE, OSGiFrameworkPropertyRemove.INSTANCE, OSGiFrameworkPropertyRemove.DESCRIPTION, false);
76 properties.registerReadWriteAttribute(ModelConstants.VALUE, null, OSGiFrameworkPropertyWrite.INSTANCE, Storage.CONFIGURATION);
77
78 // Framework Capabilities
79 ManagementResourceRegistration capabilities = registration.registerSubModel(PathElement.pathElement(ModelConstants.CAPABILITY), OSGiSubsystemProviders.CAPABILITY_DESCRIPTION);
80 capabilities.registerOperationHandler(ModelDescriptionConstants.ADD, OSGiCapabilityAdd.INSTANCE, OSGiCapabilityAdd.DESCRIPTION, false);
81 capabilities.registerOperationHandler(ModelDescriptionConstants.REMOVE, OSGiCapabilityRemove.INSTANCE, OSGiCapabilityRemove.DESCRIPTION, false);
82
83 if (registerRuntimeOnly) {
84 // Bundles present at runtime, this info is not available for controllers
85 ManagementResourceRegistration bundles = registration.registerSubModel(PathElement.pathElement(ModelConstants.BUNDLE), OSGiSubsystemProviders.BUNDLE_DESCRIPTION);
86 BundleRuntimeHandler.INSTANCE.register(bundles);
87 }
88
89 subsystem.registerXMLElementWriter(OSGiSubsystemWriter.INSTANCE);
90 }
91}