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