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