View Javadoc

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