View Javadoc

1   /*
2    * Copyright 2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.jboss.extension;
17  
18  import static de.smartics.properties.jboss.extension.resources.SubsystemDefinition.SUBSYSTEM_NAME;
19  
20  import org.jboss.as.controller.Extension;
21  import org.jboss.as.controller.ExtensionContext;
22  import org.jboss.as.controller.SubsystemRegistration;
23  import org.jboss.as.controller.parsing.ExtensionParsingContext;
24  import org.jboss.as.controller.registry.ManagementResourceRegistration;
25  import org.jboss.logging.Logger;
26  
27  import de.smartics.properties.jboss.extension.parser.SubsystemParser;
28  import de.smartics.properties.jboss.extension.resources.PropertiesConfigurationResourceDefinition;
29  import de.smartics.properties.jboss.extension.resources.SubsystemDefinition;
30  
31  /**
32   * An extension to integrate smartics-properties with JBoss AS.
33   */
34  public class SubsystemExtension implements Extension
35  {
36    // ********************************* Fields *********************************
37  
38    // --- constants ------------------------------------------------------------
39  
40    /**
41     * The name space used for the {@code subsystem} element
42     * <p>
43     * The value of this constant is {@value}.
44     * </p>
45     */
46    public static final String NAMESPACE = "urn:de.smartics:properties:1.0";
47  
48    /**
49     * The major version of the extension.
50     */
51    public static final int MODEL_VERSION_MAJOR = 1;
52  
53    /**
54     * The minor version of the extension.
55     */
56    public static final int MODEL_VERSION_MINOR = 0;
57  
58    /**
59     * The micro version of the extension.
60     */
61    public static final int MODEL_VERSION_MICRO = 0;
62  
63    /**
64     * Reference to the logger for this class.
65     */
66    private static final Logger LOG = Logger.getLogger(SubsystemExtension.class);
67  
68    // --- members --------------------------------------------------------------
69  
70    /**
71     * The parser used for parsing the subsystem configuration.
72     */
73    private final SubsystemParser parser = new SubsystemParser();
74  
75    // ****************************** Initializer *******************************
76  
77    // ****************************** Constructors ******************************
78  
79    // ****************************** Inner Classes *****************************
80  
81    // ********************************* Methods ********************************
82  
83    // --- init -----------------------------------------------------------------
84  
85    // --- get&set --------------------------------------------------------------
86  
87    // --- business -------------------------------------------------------------
88  
89    @Override
90    public void initializeParsers(final ExtensionParsingContext context)
91    {
92      context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, parser);
93    }
94  
95    @Override
96    public void initialize(final ExtensionContext context)
97    {
98      LOG.debug("Initializing properties extension");
99      final SubsystemRegistration subsystem =
100         context.registerSubsystem(SUBSYSTEM_NAME, MODEL_VERSION_MAJOR,
101             MODEL_VERSION_MINOR); // not in 7.1.1: , MODEL_VERSION_MICRO);
102     final ManagementResourceRegistration registration =
103         subsystem.registerSubsystemModel(SubsystemDefinition.INSTANCE);
104     registration
105         .registerSubModel(PropertiesConfigurationResourceDefinition.INSTANCE);
106 
107     subsystem.registerXMLElementWriter(parser);
108   }
109 
110   // --- object basics --------------------------------------------------------
111 
112 }