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 throw new EarPluginException( 125 "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 * <loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear</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 {@code null} 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 {@code jboss-app.xml} 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 {@code jboss-app.xml} 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 {@code jboss-app.xml} 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 {@code loader-repository} element. If the element is not present in the 316 * configuration, it will be added. 317 * <p/> 318 * Example: <loader-repository-config>java2ParentDelegaton=true</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 {@code jboss-app.xml} file. It tells JBoss which 329 * loader repository implementation to use. 330 * <p/> 331 * This element is added as an attribute to the {@code loader-repository} element, therefore it is not added if no 332 * such element configuration is present. 333 * <p/> 334 * Example: <loader-repository-class>org.mindbug.jboss.AlternateLoaderRepository</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 {@code jboss-app.xml} file. It tells 345 * JBoss how to parse the configuration given in the {@code loader-repository-config} element. 346 * <p/> 347 * This element is added as an attribute to the {@code loader-repository-config} element, therefore it is not added 348 * if no such element configuration is present. 349 * <p/> 350 * Example: <config-parser-class>org.mindbug.jboss.AlternateLoaderRepositoryConfigParser</config-parser-class> 351 * 352 * @return the class loader's configuration parser class 353 */ 354 public String getConfigParserClass() 355 { 356 return configParserClass; 357 } 358 }