View Javadoc

1   package org.apache.maven.plugin.ear;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  /**
25   * The JBoss specific configuration, used to generate the jboss-app.xml deployment descriptor file
26   * 
27   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
28   * @version $Id: JbossConfiguration.java 1542508 2013-11-16 13:21:35Z rfscholte $
29   */
30  class JbossConfiguration
31  {
32      static final String VERSION_3_2 = "3.2";
33  
34      static final String VERSION_4 = "4";
35  
36      static final String VERSION_4_2 = "4.2";
37  
38      static final String VERSION_5 = "5";
39  
40      static final String VERSION = "version";
41  
42      static final String SECURITY_DOMAIN = "security-domain";
43  
44      static final String UNAUHTHENTICTED_PRINCIPAL = "unauthenticated-principal";
45  
46      static final String JMX_NAME = "jmx-name";
47  
48      static final String LOADER_REPOSITORY = "loader-repository";
49  
50      static final String LOADER_REPOSITORY_CLASS_ATTRIBUTE = "loaderRepositoryClass";
51  
52      static final String LOADER_REPOSITORY_CONFIG = "loader-repository-config";
53  
54      static final String CONFIG_PARSER_CLASS_ATTRIBUTE = "configParserClass";
55  
56      static final String MODULE_ORDER = "module-order";
57  
58      static final String DATASOURCES = "data-sources";
59  
60      static final String DATASOURCE = "data-source";
61  
62      static final String LIBRARY_DIRECTORY = "library-directory";
63  
64      private final String version;
65  
66      private boolean jbossThreeDotTwo;
67  
68      private boolean jbossFour;
69  
70      private boolean jbossFourDotTwo;
71  
72      private boolean jbossFive;
73  
74      private final String securityDomain;
75  
76      private final String unauthenticatedPrincipal;
77  
78      private final String jmxName;
79  
80      private final String loaderRepository;
81  
82      private final String loaderRepositoryConfig;
83  
84      private final String loaderRepositoryClass;
85  
86      private final String configParserClass;
87  
88      private final String moduleOrder;
89  
90      private final List<String> dataSources;
91  
92      private final String libraryDirectory;
93  
94      public JbossConfiguration( String version, String securityDomain, String unauthenticatedPrincipal, String jmxName,
95                                 String loaderRepository, String moduleOrder, List<String> dataSources,
96                                 String libraryDirectory, String loaderRepositoryConfig, String loaderRepositoryClass,
97                                 String configParserClass )
98          throws EarPluginException
99      {
100         if ( version == null )
101         {
102             throw new EarPluginException( "jboss version could not be null." );
103         }
104         else
105         {
106             this.version = version;
107             if ( version.equals( JbossConfiguration.VERSION_3_2 ) )
108             {
109                 this.jbossThreeDotTwo = true;
110             }
111             else if ( version.equals( JbossConfiguration.VERSION_4 ) )
112             {
113                 this.jbossFour = true;
114             }
115             else if ( version.equals( JbossConfiguration.VERSION_4_2 ) )
116             {
117                 this.jbossFourDotTwo = true;
118             }
119             else if ( version.equals( JbossConfiguration.VERSION_5 ) )
120             {
121                 this.jbossFive = true;
122             }
123             else
124             {
125                 throw new EarPluginException( "Invalid JBoss configuration, version[" + version + "] is not supported." );
126             }
127             this.securityDomain = securityDomain;
128             this.unauthenticatedPrincipal = unauthenticatedPrincipal;
129             this.jmxName = jmxName;
130             this.loaderRepository = loaderRepository;
131             this.moduleOrder = moduleOrder;
132             this.dataSources = dataSources;
133             this.libraryDirectory = libraryDirectory;
134             this.loaderRepositoryConfig = loaderRepositoryConfig;
135             this.loaderRepositoryClass = loaderRepositoryClass;
136             this.configParserClass = configParserClass;
137         }
138     }
139 
140     /**
141      * Returns the targeted version of JBoss.
142      * 
143      * @return the jboss version
144      */
145     public String getVersion()
146     {
147         return version;
148     }
149 
150     /**
151      * Returns true if the targeted JBoss version is 3.2.
152      * 
153      * @return if the targeted version is 3.2
154      */
155     public boolean isJbossThreeDotTwo()
156     {
157         return jbossThreeDotTwo;
158     }
159 
160     /**
161      * Returns true if the targeted JBoss version is 4.
162      * 
163      * @return if the targeted version is 4
164      */
165     public boolean isJbossFour()
166     {
167         return jbossFour;
168     }
169 
170     /**
171      * Returns true if the targeted JBoss version if 4 or higher (that is 4, 4.2 or 5).
172      * 
173      * @return true if the targeted version is 4+
174      */
175     public boolean isJbossFourOrHigher()
176     {
177         return jbossFour || jbossFourDotTwo || jbossFive;
178     }
179 
180     /**
181      * Returns true if the targeted JBoss version is 4.2.
182      * 
183      * @return if the targeted version is 4.2
184      */
185     public boolean isJbossFourDotTwo()
186     {
187         return jbossFourDotTwo;
188     }
189 
190     /**
191      * Returns true if the targeted JBoss version if 4.2 or higher (that is 4.2 or 5).
192      * 
193      * @return true if the targeted version is 4.2+
194      */
195     public boolean isJbossFourDotTwoOrHigher()
196     {
197         return jbossFourDotTwo || jbossFive;
198     }
199 
200     /**
201      * Returns true if the targeted JBoss version is 5.
202      * 
203      * @return if the targeted version is 5
204      */
205     public boolean isJbossFive()
206     {
207         return jbossFive;
208     }
209 
210     /**
211      * The security-domain element specifies the JNDI name of the security manager that implements the
212      * EJBSecurityManager and RealmMapping for the domain. When specified at the jboss level it specifies the security
213      * domain for all j2ee components in the deployment unit.
214      * <p/>
215      * One can override the global security-domain at the container level using the security-domain element at the
216      * container-configuration level.
217      * <p/>
218      * Only available as from JBoss 4.
219      * 
220      * @return the JNDI name of the security manager
221      */
222     public String getSecurityDomain()
223     {
224         return securityDomain;
225     }
226 
227     /**
228      * The unauthenticated-principal element specifies the name of the principal that will be returned by the
229      * EJBContext.getCallerPrincipal() method if there is no authenticated user. This Principal has no roles or
230      * privileges to call any other beans.
231      * <p/>
232      * Only available as from JBoss 4.
233      * 
234      * @return the unauthenticated principal
235      */
236     public String getUnauthenticatedPrincipal()
237     {
238         return unauthenticatedPrincipal;
239     }
240 
241     /**
242      * The jmx-name element allows one to specify the JMX ObjectName to use for the MBean associated with the ear
243      * module. This must be a unique name and valid JMX ObjectName string.
244      * 
245      * @return the object name of the ear mbean
246      */
247     public String getJmxName()
248     {
249         return jmxName;
250     }
251 
252     /**
253      * The loader-repository specifies the name of the UnifiedLoaderRepository MBean to use for the ear to provide ear
254      * level scoping of classes deployed in the ear. It is a unique JMX ObjectName string.
255      * <p/>
256      * <P>
257      * Example:
258      * </P>
259      * &lt;loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear&lt;/loader-repository>
260      * 
261      * @return the object name of the ear mbean
262      */
263     public String getLoaderRepository()
264     {
265         return loaderRepository;
266     }
267 
268     /**
269      * The module-order specifies the order in which the modules specified in the application.xml file gets loaded.
270      * Allowed values are:
271      * <p/>
272      * <module-order>strict</module-order> The strict value indicates that the deployments of the modules will be done
273      * in the order that would be specified in the application.xml and jboss-app.xml file.
274      * <p/>
275      * <module-order>implicit</module-order> The implicit value indicates the deployment would follow the order which
276      * would be specified in the DeploymentSorter.
277      * <p/>
278      * Returns <tt>null</tt> if no module order is set.
279      * <p/>
280      * Only available in JBoss 4.2 and 4.3. Has no effect in JBoss 5 and is not added when mentioned version is used.
281      * 
282      * @return the module order
283      */
284     public String getModuleOrder()
285     {
286         return moduleOrder;
287     }
288 
289     /**
290      * Returns the list of datasources to include in the <tt>jboss-app.xml</tt> file as services. Each element of the
291      * list is the relative path to the datasource file contained in the EAR archive.
292      * 
293      * @return the list of datasources paths
294      */
295     public List<String> getDataSources()
296     {
297         return dataSources;
298     }
299 
300     /**
301      * Returns the library directory to include in the <tt>jboss-app.xml</tt> file. It tells JBoss where to find
302      * non-Java EE libraries included in the EAR.
303      * 
304      * @return the library directory
305      */
306     public String getLibraryDirectory()
307     {
308         return libraryDirectory;
309     }
310 
311     /**
312      * Returns the class loader repository configuration to include in the <tt>jboss-app.xml</tt> file. The content of
313      * this element is handed to the class loader, thereby altering it's default behaviour.
314      * <p/>
315      * This element is added as a child to the <tt>loader-repository</tt> element. If the element is not present in the
316      * configuration, it will be added.
317      * <p/>
318      * Example: &lt;loader-repository-config>java2ParentDelegaton=true&lt;/loader-repository-config>
319      * 
320      * @return the class loader repository configuration
321      */
322     public String getLoaderRepositoryConfig()
323     {
324         return loaderRepositoryConfig;
325     }
326 
327     /**
328      * Returns the class loader repository class to include in the <tt>jboss-app.xml</tt> file. It tells JBoss which
329      * loader repository implementation to use.
330      * <p/>
331      * This element is added as an attribute to the <tt>loader-repository</tt> element, therefore it is not added if no
332      * such element configuration is present.
333      * <p/>
334      * Example: &lt;loader-repository-class>org.mindbug.jboss.AlternateLoaderRepository&lt;/loader-repository-class>
335      * 
336      * @return the class loader repository class
337      */
338     public String getLoaderRepositoryClass()
339     {
340         return loaderRepositoryClass;
341     }
342 
343     /**
344      * Returns the class loader's configuration parser class to include in the <tt>jboss-app.xml</tt> file. It tells
345      * JBoss how to parse the configuration given in the <tt>loader-repository-config</tt> element.
346      * <p/>
347      * This element is added as an attribute to the <tt>loader-repository-config</tt> element, therefore it is not added
348      * if no such element configuration is present.
349      * <p/>
350      * Example: &lt;config-parser-class>org.mindbug.jboss.AlternateLoaderRepositoryConfigParser&lt;/config-parser-class>
351      * 
352      * @return the class loader's configuration parser class
353      */
354     public String getConfigParserClass()
355     {
356         return configParserClass;
357     }
358 }