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.resources;
17  
18  import org.jboss.as.controller.PathElement;
19  import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
20  import org.jboss.as.controller.SimpleAttributeDefinition;
21  import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
22  import org.jboss.as.controller.SimpleResourceDefinition;
23  import org.jboss.as.controller.registry.AttributeAccess;
24  import org.jboss.as.controller.registry.ManagementResourceRegistration;
25  import org.jboss.dmr.ModelNode;
26  import org.jboss.dmr.ModelType;
27  
28  import de.smartics.properties.jboss.extension.resources.components.CacheComponent;
29  import de.smartics.properties.jboss.extension.resources.components.DataSourceComponent;
30  import de.smartics.properties.jboss.extension.resources.components.AdminResourceComponent;
31  import de.smartics.properties.jboss.extension.resources.components.FactoriesComponent;
32  import de.smartics.properties.jboss.extension.resources.components.SecurityComponent;
33  import de.smartics.properties.spi.config.config.PropertiesConfiguration;
34  
35  /**
36   * The definition for the cache resource.
37   */
38  public class PropertiesConfigurationResourceDefinition extends
39      SimpleResourceDefinition
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    /**
46     * The name of the XML element that contains the configuration information.
47     */
48    public static final String CONFIGS_ELEMENT_NAME = "configurations";
49  
50    /**
51     * The name of the attribute that identifies the configuration.
52     * <p>
53     * The value of this constant is {@value}.
54     * </p>
55     */
56    public static final String AN_NAME = "name";
57  
58    /**
59     * The name of the XML element that contains the configuration information.
60     */
61    public static final String CONFIG_ELEMENT_NAME = "configuration";
62  
63    /**
64     * The path to the configuration element.
65     */
66    public static final PathElement CONFIG_PATH = PathElement
67        .pathElement(CONFIGS_ELEMENT_NAME);
68  
69    /**
70     * The path to the element with the name of the configuration.
71     */
72    public static final PathElement NAME_PATH = PathElement.pathElement(AN_NAME);
73  
74    /**
75     * The attribute that holds the name of the configuration.
76     */
77    public static final SimpleAttributeDefinition NAME =
78        new SimpleAttributeDefinitionBuilder(AN_NAME, ModelType.STRING, true)
79            .setXmlName(AN_NAME).setAllowExpression(true)
80            .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES).build();
81  
82    /**
83     * The definition singleton.
84     */
85    public static final PropertiesConfigurationResourceDefinition INSTANCE =
86        new PropertiesConfigurationResourceDefinition();
87  
88    // --- members --------------------------------------------------------------
89  
90    /**
91     * The component for administration of property declarations and definitions
92     * information for a configuration.
93     */
94    private final AdminResourceComponent adminResourceComponent =
95        new AdminResourceComponent(
96            PropertiesConfigurationResourceAttributeHandler.INSTANCE);
97  
98    /**
99     * The component for administration of cache information for a configuration.
100    */
101   private final CacheComponent cacheComponent = new CacheComponent(
102       PropertiesConfigurationResourceAttributeHandler.INSTANCE);
103 
104   /**
105    * The component for administration of data source information for a
106    * configuration.
107    */
108   private final DataSourceComponent dataSourceComponent =
109       new DataSourceComponent(
110           PropertiesConfigurationResourceAttributeHandler.INSTANCE);
111 
112   /**
113    * The component for administration of security information for a
114    * configuration.
115    */
116   private final SecurityComponent securityComponent = new SecurityComponent(
117       PropertiesConfigurationResourceAttributeHandler.INSTANCE);
118 
119   /**
120    * The component for administration of factories information for a
121    * configuration.
122    */
123   private final FactoriesComponent factoriesComponent = new FactoriesComponent(
124       PropertiesConfigurationResourceAttributeHandler.INSTANCE);
125 
126   // ****************************** Initializer *******************************
127 
128   // ****************************** Constructors ******************************
129 
130   /**
131    * Default constructor.
132    */
133   public PropertiesConfigurationResourceDefinition()
134   {
135     super(CONFIG_PATH, DescriptionUtils
136         .getResourceDescriptionResolver("configuration"),
137         PropertiesConfigurationResourceAdd.INSTANCE,
138         ReloadRequiredRemoveStepHandler.INSTANCE);
139   }
140 
141   // ****************************** Inner Classes *****************************
142 
143   // ********************************* Methods ********************************
144 
145   // --- init -----------------------------------------------------------------
146 
147   // --- get&set --------------------------------------------------------------
148 
149   /**
150    * Returns the component for administration of property declarations and
151    * definitions information for a configuration.
152    *
153    * @return the component for administration of property declarations and
154    *         definitions information for a configuration.
155    */
156   public AdminResourceComponent getDefinitionsComponent()
157   {
158     return adminResourceComponent;
159   }
160 
161   /**
162    * Returns the component for administration of cache information for a
163    * configuration.
164    *
165    * @return the component for administration of cache information for a
166    *         configuration.
167    */
168   public CacheComponent getCacheComponent()
169   {
170     return cacheComponent;
171   }
172 
173   /**
174    * Returns the component for administration of data source information for a
175    * configuration.
176    *
177    * @return the component for administration of data source information for a
178    *         configuration.
179    */
180   public DataSourceComponent getDataSourceComponent()
181   {
182     return dataSourceComponent;
183   }
184 
185   /**
186    * Returns the component for administration of security information for a
187    * configuration.
188    *
189    * @return the component for administration of security information for a
190    *         configuration.
191    */
192   public SecurityComponent getSecurityComponent()
193   {
194     return securityComponent;
195   }
196 
197   /**
198    * Returns the component for administration of factories information for a
199    * configuration.
200    *
201    * @return the component for administration of factories information for a
202    *         configuration.
203    */
204   public FactoriesComponent getFactoriesComponent()
205   {
206     return factoriesComponent;
207   }
208 
209   // --- business -------------------------------------------------------------
210 
211   @Override
212   public void registerAttributes(
213       final ManagementResourceRegistration resourceRegistration)
214   {
215     resourceRegistration.registerReadWriteAttribute(NAME, null,
216         PropertiesConfigurationResourceAttributeHandler.INSTANCE);
217 
218     adminResourceComponent.registerAttributes(resourceRegistration);
219     cacheComponent.registerAttributes(resourceRegistration);
220     dataSourceComponent.registerAttributes(resourceRegistration);
221     securityComponent.registerAttributes(resourceRegistration);
222     factoriesComponent.registerAttributes(resourceRegistration);
223   }
224 
225   public void apply(final String identifier,
226       final PropertiesConfiguration propertiesConfig, final ModelNode model)
227   {
228     adminResourceComponent.apply(propertiesConfig, model);
229     cacheComponent.apply(identifier, propertiesConfig, model);
230     dataSourceComponent.apply(propertiesConfig, model);
231     securityComponent.apply(propertiesConfig, model);
232     factoriesComponent.apply(propertiesConfig, model);
233   }
234 
235   // --- object basics --------------------------------------------------------
236 
237 }