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 1636449 2014-11-03 21:27:36Z khmarbaise $ 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 // CHECKSTYLE_OFF: LineLength 126 throw new EarPluginException( "Invalid JBoss configuration, version[" + version + "] is not supported." ); 127 // CHECKSTYLE_ON: LineLength 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 4, 4.2 or 5). 174 * 175 * @return true if the targeted version is 4+ 176 */ 177 public boolean isJbossFourOrHigher() 178 { 179 return jbossFour || jbossFourDotTwo || jbossFive; 180 } 181 182 /** 183 * Returns true if the targeted JBoss version is 4.2. 184 * 185 * @return if the targeted version is 4.2 186 */ 187 public boolean isJbossFourDotTwo() 188 { 189 return jbossFourDotTwo; 190 } 191 192 /** 193 * Returns true if the targeted JBoss version if 4.2 or higher (that is 4.2 or 5). 194 * 195 * @return true if the targeted version is 4.2+ 196 */ 197 public boolean isJbossFourDotTwoOrHigher() 198 { 199 return jbossFourDotTwo || jbossFive; 200 } 201 202 /** 203 * Returns true if the targeted JBoss version is 5. 204 * 205 * @return if the targeted version is 5 206 */ 207 public boolean isJbossFive() 208 { 209 return jbossFive; 210 } 211 212 /** 213 * The security-domain element specifies the JNDI name of the security manager that implements the 214 * EJBSecurityManager and RealmMapping for the domain. When specified at the jboss level it specifies the security 215 * domain for all j2ee components in the deployment unit. 216 * <p/> 217 * One can override the global security-domain at the container level using the security-domain element at the 218 * container-configuration level. 219 * <p/> 220 * Only available as from JBoss 4. 221 * 222 * @return the JNDI name of the security manager 223 */ 224 public String getSecurityDomain() 225 { 226 return securityDomain; 227 } 228 229 /** 230 * The unauthenticated-principal element specifies the name of the principal that will be returned by the 231 * EJBContext.getCallerPrincipal() method if there is no authenticated user. This Principal has no roles or 232 * privileges to call any other beans. 233 * <p/> 234 * Only available as from JBoss 4. 235 * 236 * @return the unauthenticated principal 237 */ 238 public String getUnauthenticatedPrincipal() 239 { 240 return unauthenticatedPrincipal; 241 } 242 243 /** 244 * The jmx-name element allows one to specify the JMX ObjectName to use for the MBean associated with the ear 245 * module. This must be a unique name and valid JMX ObjectName string. 246 * 247 * @return the object name of the ear mbean 248 */ 249 public String getJmxName() 250 { 251 return jmxName; 252 } 253 254 /** 255 * The loader-repository specifies the name of the UnifiedLoaderRepository MBean to use for the ear to provide ear 256 * level scoping of classes deployed in the ear. It is a unique JMX ObjectName string. 257 * <p/> 258 * <P> 259 * Example: 260 * </P> 261 * <loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear</loader-repository> 262 * 263 * @return the object name of the ear mbean 264 */ 265 public String getLoaderRepository() 266 { 267 return loaderRepository; 268 } 269 270 /** 271 * The module-order specifies the order in which the modules specified in the application.xml file gets loaded. 272 * Allowed values are: 273 * <p/> 274 * <module-order>strict</module-order> The strict value indicates that the deployments of the modules will be done 275 * in the order that would be specified in the application.xml and jboss-app.xml file. 276 * <p/> 277 * <module-order>implicit</module-order> The implicit value indicates the deployment would follow the order which 278 * would be specified in the DeploymentSorter. 279 * <p/> 280 * Returns <tt>null</tt> if no module order is set. 281 * <p/> 282 * Only available in JBoss 4.2 and 4.3. Has no effect in JBoss 5 and is not added when mentioned version is used. 283 * 284 * @return the module order 285 */ 286 public String getModuleOrder() 287 { 288 return moduleOrder; 289 } 290 291 /** 292 * Returns the list of datasources to include in the <tt>jboss-app.xml</tt> file as services. Each element of the 293 * list is the relative path to the datasource file contained in the EAR archive. 294 * 295 * @return the list of datasources paths 296 */ 297 public List<String> getDataSources() 298 { 299 return dataSources; 300 } 301 302 /** 303 * Returns the library directory to include in the <tt>jboss-app.xml</tt> file. It tells JBoss where to find 304 * non-Java EE libraries included in the EAR. 305 * 306 * @return the library directory 307 */ 308 public String getLibraryDirectory() 309 { 310 return libraryDirectory; 311 } 312 313 /** 314 * Returns the class loader repository configuration to include in the <tt>jboss-app.xml</tt> file. The content of 315 * this element is handed to the class loader, thereby altering it's default behaviour. 316 * <p/> 317 * This element is added as a child to the <tt>loader-repository</tt> element. If the element is not present in the 318 * configuration, it will be added. 319 * <p/> 320 * Example: <loader-repository-config>java2ParentDelegaton=true</loader-repository-config> 321 * 322 * @return the class loader repository configuration 323 */ 324 public String getLoaderRepositoryConfig() 325 { 326 return loaderRepositoryConfig; 327 } 328 329 /** 330 * Returns the class loader repository class to include in the <tt>jboss-app.xml</tt> file. It tells JBoss which 331 * loader repository implementation to use. 332 * <p/> 333 * This element is added as an attribute to the <tt>loader-repository</tt> element, therefore it is not added if no 334 * such element configuration is present. 335 * <p/> 336 * Example: <loader-repository-class>org.mindbug.jboss.AlternateLoaderRepository</loader-repository-class> 337 * 338 * @return the class loader repository class 339 */ 340 public String getLoaderRepositoryClass() 341 { 342 return loaderRepositoryClass; 343 } 344 345 /** 346 * Returns the class loader's configuration parser class to include in the <tt>jboss-app.xml</tt> file. It tells 347 * JBoss how to parse the configuration given in the <tt>loader-repository-config</tt> element. 348 * <p/> 349 * This element is added as an attribute to the <tt>loader-repository-config</tt> element, therefore it is not added 350 * if no such element configuration is present. 351 * <p/> 352 * Example: <config-parser-class>org.mindbug.jboss.AlternateLoaderRepositoryConfigParser</config-parser-class> 353 * 354 * @return the class loader's configuration parser class 355 */ 356 public String getConfigParserClass() 357 { 358 return configParserClass; 359 } 360 }