Source Code Cross Referenced for EARConfigBuilder.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » j2ee » deployment » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.j2ee.deployment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */package org.apache.geronimo.j2ee.deployment;
0017:
0018:        import java.io.File;
0019:        import java.io.IOException;
0020:        import java.net.MalformedURLException;
0021:        import java.net.URI;
0022:        import java.net.URL;
0023:        import java.util.ArrayList;
0024:        import java.util.Collection;
0025:        import java.util.Collections;
0026:        import java.util.Enumeration;
0027:        import java.util.HashMap;
0028:        import java.util.HashSet;
0029:        import java.util.LinkedHashMap;
0030:        import java.util.LinkedHashSet;
0031:        import java.util.LinkedList;
0032:        import java.util.List;
0033:        import java.util.Map;
0034:        import java.util.Set;
0035:        import java.util.jar.JarEntry;
0036:        import java.util.jar.JarFile;
0037:        import java.util.jar.Manifest;
0038:        import java.util.jar.Attributes;
0039:        import java.util.zip.ZipEntry;
0040:
0041:        import javax.xml.namespace.QName;
0042:
0043:        import org.apache.commons.logging.Log;
0044:        import org.apache.commons.logging.LogFactory;
0045:        import org.apache.geronimo.common.DeploymentException;
0046:        import org.apache.geronimo.deployment.ConfigurationBuilder;
0047:        import org.apache.geronimo.deployment.DeploymentContext;
0048:        import org.apache.geronimo.deployment.ModuleIDBuilder;
0049:        import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
0050:        import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection;
0051:        import org.apache.geronimo.deployment.ClassPathList;
0052:        import org.apache.geronimo.deployment.ModuleList;
0053:        import org.apache.geronimo.deployment.service.EnvironmentBuilder;
0054:        import org.apache.geronimo.deployment.service.GBeanBuilder;
0055:        import org.apache.geronimo.deployment.util.DeploymentUtil;
0056:        import org.apache.geronimo.deployment.util.NestedJarFile;
0057:        import org.apache.geronimo.deployment.xbeans.ArtifactType;
0058:        import org.apache.geronimo.deployment.xbeans.EnvironmentType;
0059:        import org.apache.geronimo.deployment.xbeans.PatternType;
0060:        import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
0061:        import org.apache.geronimo.gbean.AbstractName;
0062:        import org.apache.geronimo.gbean.AbstractNameQuery;
0063:        import org.apache.geronimo.gbean.GBeanData;
0064:        import org.apache.geronimo.gbean.GBeanInfo;
0065:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
0066:        import org.apache.geronimo.gbean.ReferencePatterns;
0067:        import org.apache.geronimo.gbean.SingleElementCollection;
0068:        import org.apache.geronimo.gbean.GBeanLifecycle;
0069:        import org.apache.geronimo.j2ee.ApplicationInfo;
0070:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
0071:        import org.apache.geronimo.j2ee.management.impl.J2EEApplicationImpl;
0072:        import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
0073:        import org.apache.geronimo.kernel.Kernel;
0074:        import org.apache.geronimo.kernel.Naming;
0075:        import org.apache.geronimo.kernel.config.ConfigurationAlreadyExistsException;
0076:        import org.apache.geronimo.kernel.config.ConfigurationData;
0077:        import org.apache.geronimo.kernel.config.ConfigurationManager;
0078:        import org.apache.geronimo.kernel.config.ConfigurationModuleType;
0079:        import org.apache.geronimo.kernel.config.ConfigurationStore;
0080:        import org.apache.geronimo.kernel.config.ConfigurationUtil;
0081:        import org.apache.geronimo.kernel.config.SimpleConfigurationManager;
0082:        import org.apache.geronimo.kernel.repository.Artifact;
0083:        import org.apache.geronimo.kernel.repository.ArtifactResolver;
0084:        import org.apache.geronimo.kernel.repository.Environment;
0085:        import org.apache.geronimo.kernel.repository.Repository;
0086:        import org.apache.geronimo.kernel.repository.MissingDependencyException;
0087:        import org.apache.geronimo.management.J2EEResource;
0088:        import org.apache.geronimo.management.J2EEServer;
0089:        import org.apache.geronimo.schema.SchemaConversionUtils;
0090:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerApplicationDocument;
0091:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerApplicationType;
0092:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerExtModuleType;
0093:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerModuleType;
0094:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerSecurityDocument;
0095:        import org.apache.geronimo.xbeans.javaee.ApplicationDocument;
0096:        import org.apache.geronimo.xbeans.javaee.ApplicationType;
0097:        import org.apache.geronimo.xbeans.javaee.ModuleType;
0098:        import org.apache.xmlbeans.XmlCursor;
0099:        import org.apache.xmlbeans.XmlException;
0100:        import org.apache.xmlbeans.XmlObject;
0101:
0102:        /**
0103:         * @version $Rev: 617648 $ $Date: 2008-02-01 13:09:16 -0800 (Fri, 01 Feb 2008) $
0104:         */
0105:        public class EARConfigBuilder implements  ConfigurationBuilder,
0106:                CorbaGBeanNameSource, GBeanLifecycle {
0107:
0108:            private static final Log log = LogFactory
0109:                    .getLog(EARConfigBuilder.class);
0110:            private static final String LINE_SEP = System
0111:                    .getProperty("line.separator");
0112:
0113:            private final static QName APPLICATION_QNAME = GerApplicationDocument.type
0114:                    .getDocumentElementName();
0115:            private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String, String>();
0116:            static {
0117:                NAMESPACE_UPDATES
0118:                        .put(
0119:                                "http://geronimo.apache.org/xml/ns/j2ee/application",
0120:                                "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
0121:                NAMESPACE_UPDATES
0122:                        .put(
0123:                                "http://geronimo.apache.org/xml/ns/j2ee/application-1.1",
0124:                                "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
0125:                NAMESPACE_UPDATES
0126:                        .put(
0127:                                "http://geronimo.apache.org/xml/ns/j2ee/application-1.2",
0128:                                "http://geronimo.apache.org/xml/ns/j2ee/application-2.0");
0129:            }
0130:
0131:            private final ConfigurationManager configurationManager;
0132:            private final Collection<? extends Repository> repositories;
0133:            private final SingleElementCollection ejbConfigBuilder;
0134:            private final SingleElementCollection webConfigBuilder;
0135:            private final SingleElementCollection connectorConfigBuilder;
0136:            private final SingleElementCollection appClientConfigBuilder;
0137:            private final SingleElementCollection resourceReferenceBuilder;
0138:            private final NamespaceDrivenBuilderCollection securityBuilders;
0139:            private final NamespaceDrivenBuilderCollection serviceBuilders;
0140:            private final Collection<ModuleBuilderExtension> persistenceUnitBuilders;
0141:
0142:            private final Environment defaultEnvironment;
0143:            private final AbstractNameQuery serverName;
0144:            private final AbstractNameQuery transactionManagerObjectName;
0145:            private final AbstractNameQuery connectionTrackerObjectName;
0146:            private final AbstractNameQuery transactionalTimerObjectName;
0147:            private final AbstractNameQuery nonTransactionalTimerObjectName;
0148:            private final AbstractNameQuery corbaGBeanObjectName;
0149:            private final Naming naming;
0150:            private final Collection<? extends ArtifactResolver> artifactResolvers;
0151:
0152:            public EARConfigBuilder(Environment defaultEnvironment,
0153:                    AbstractNameQuery transactionManagerAbstractName,
0154:                    AbstractNameQuery connectionTrackerAbstractName,
0155:                    AbstractNameQuery transactionalTimerAbstractName,
0156:                    AbstractNameQuery nonTransactionalTimerAbstractName,
0157:                    AbstractNameQuery corbaGBeanAbstractName,
0158:                    AbstractNameQuery serverName,
0159:                    Collection<? extends Repository> repositories,
0160:                    Collection ejbConfigBuilder, Collection webConfigBuilder,
0161:                    Collection connectorConfigBuilder,
0162:                    Collection resourceReferenceBuilder,
0163:                    Collection appClientConfigBuilder,
0164:                    Collection securityBuilders, Collection serviceBuilders,
0165:                    Collection<ModuleBuilderExtension> persistenceUnitBuilders,
0166:                    Collection<? extends ArtifactResolver> artifactResolvers,
0167:                    Kernel kernel) {
0168:                this (defaultEnvironment, transactionManagerAbstractName,
0169:                        connectionTrackerAbstractName,
0170:                        transactionalTimerAbstractName,
0171:                        nonTransactionalTimerAbstractName,
0172:                        corbaGBeanAbstractName, serverName, ConfigurationUtil
0173:                                .getConfigurationManager(kernel), repositories,
0174:                        new SingleElementCollection(ejbConfigBuilder),
0175:                        new SingleElementCollection(webConfigBuilder),
0176:                        new SingleElementCollection(connectorConfigBuilder),
0177:                        new SingleElementCollection(resourceReferenceBuilder),
0178:                        new SingleElementCollection(appClientConfigBuilder),
0179:                        securityBuilders, serviceBuilders,
0180:                        persistenceUnitBuilders, kernel.getNaming(),
0181:                        artifactResolvers);
0182:            }
0183:
0184:            public EARConfigBuilder(Environment defaultEnvironment,
0185:                    AbstractNameQuery transactionManagerAbstractName,
0186:                    AbstractNameQuery connectionTrackerAbstractName,
0187:                    AbstractNameQuery transactionalTimerAbstractName,
0188:                    AbstractNameQuery nonTransactionalTimerAbstractName,
0189:                    AbstractNameQuery corbaGBeanAbstractName,
0190:                    AbstractNameQuery serverName,
0191:                    Collection<? extends Repository> repositories,
0192:                    ModuleBuilder ejbConfigBuilder,
0193:                    ModuleBuilder webConfigBuilder,
0194:                    ModuleBuilder connectorConfigBuilder,
0195:                    ActivationSpecInfoLocator activationSpecInfoLocator,
0196:                    ModuleBuilder appClientConfigBuilder,
0197:                    NamespaceDrivenBuilder securityBuilder,
0198:                    NamespaceDrivenBuilder serviceBuilder,
0199:                    ModuleBuilderExtension persistenceUnitBuilder,
0200:                    Naming naming,
0201:                    Collection<? extends ArtifactResolver> artifactResolvers) {
0202:                this (
0203:                        defaultEnvironment,
0204:                        transactionManagerAbstractName,
0205:                        connectionTrackerAbstractName,
0206:                        transactionalTimerAbstractName,
0207:                        nonTransactionalTimerAbstractName,
0208:                        corbaGBeanAbstractName,
0209:                        serverName,
0210:                        null,
0211:                        repositories,
0212:                        new SingleElementCollection(ejbConfigBuilder),
0213:                        new SingleElementCollection(webConfigBuilder),
0214:                        new SingleElementCollection(connectorConfigBuilder),
0215:                        new SingleElementCollection(activationSpecInfoLocator),
0216:                        new SingleElementCollection(appClientConfigBuilder),
0217:                        securityBuilder == null ? Collections.EMPTY_SET
0218:                                : Collections.singleton(securityBuilder),
0219:                        serviceBuilder == null ? Collections.EMPTY_SET
0220:                                : Collections.singleton(serviceBuilder),
0221:                        persistenceUnitBuilder == null ? Collections.EMPTY_SET
0222:                                : Collections.singleton(persistenceUnitBuilder),
0223:                        naming, artifactResolvers);
0224:            }
0225:
0226:            private EARConfigBuilder(Environment defaultEnvironment,
0227:                    AbstractNameQuery transactionManagerAbstractName,
0228:                    AbstractNameQuery connectionTrackerAbstractName,
0229:                    AbstractNameQuery transactionalTimerAbstractName,
0230:                    AbstractNameQuery nonTransactionalTimerAbstractName,
0231:                    AbstractNameQuery corbaGBeanAbstractName,
0232:                    AbstractNameQuery serverName,
0233:                    ConfigurationManager configurationManager,
0234:                    Collection<? extends Repository> repositories,
0235:                    SingleElementCollection ejbConfigBuilder,
0236:                    SingleElementCollection webConfigBuilder,
0237:                    SingleElementCollection connectorConfigBuilder,
0238:                    SingleElementCollection resourceReferenceBuilder,
0239:                    SingleElementCollection appClientConfigBuilder,
0240:                    Collection securityBuilders, Collection serviceBuilders,
0241:                    Collection<ModuleBuilderExtension> persistenceUnitBuilders,
0242:                    Naming naming,
0243:                    Collection<? extends ArtifactResolver> artifactResolvers) {
0244:                this .configurationManager = configurationManager;
0245:                this .repositories = repositories;
0246:                this .defaultEnvironment = defaultEnvironment;
0247:
0248:                this .ejbConfigBuilder = ejbConfigBuilder;
0249:                this .resourceReferenceBuilder = resourceReferenceBuilder;
0250:                this .webConfigBuilder = webConfigBuilder;
0251:                this .connectorConfigBuilder = connectorConfigBuilder;
0252:                this .appClientConfigBuilder = appClientConfigBuilder;
0253:                this .securityBuilders = new NamespaceDrivenBuilderCollection(
0254:                        securityBuilders, GerSecurityDocument.type
0255:                                .getDocumentElementName());
0256:                this .serviceBuilders = new NamespaceDrivenBuilderCollection(
0257:                        serviceBuilders, GBeanBuilder.SERVICE_QNAME);
0258:                this .persistenceUnitBuilders = persistenceUnitBuilders;
0259:
0260:                this .transactionManagerObjectName = transactionManagerAbstractName;
0261:                this .connectionTrackerObjectName = connectionTrackerAbstractName;
0262:                this .transactionalTimerObjectName = transactionalTimerAbstractName;
0263:                this .nonTransactionalTimerObjectName = nonTransactionalTimerAbstractName;
0264:                this .corbaGBeanObjectName = corbaGBeanAbstractName;
0265:                this .serverName = serverName;
0266:                this .naming = naming;
0267:                this .artifactResolvers = artifactResolvers;
0268:            }
0269:
0270:            public void doStart() throws Exception {
0271:                XmlBeansUtil.registerNamespaceUpdates(NAMESPACE_UPDATES);
0272:            }
0273:
0274:            public void doStop() {
0275:                XmlBeansUtil.unregisterNamespaceUpdates(NAMESPACE_UPDATES);
0276:            }
0277:
0278:            public void doFail() {
0279:                doStop();
0280:            }
0281:
0282:            public AbstractNameQuery getCorbaGBeanName() {
0283:                return corbaGBeanObjectName;
0284:            }
0285:
0286:            private ModuleBuilder getEjbConfigBuilder() {
0287:                return (ModuleBuilder) ejbConfigBuilder.getElement();
0288:            }
0289:
0290:            private ModuleBuilder getWebConfigBuilder() {
0291:                return (ModuleBuilder) webConfigBuilder.getElement();
0292:            }
0293:
0294:            private ModuleBuilder getConnectorConfigBuilder() {
0295:                return (ModuleBuilder) connectorConfigBuilder.getElement();
0296:            }
0297:
0298:            private ModuleBuilder getAppClientConfigBuilder() {
0299:                return (ModuleBuilder) appClientConfigBuilder.getElement();
0300:            }
0301:
0302:            public Object getDeploymentPlan(File planFile, JarFile jarFile,
0303:                    ModuleIDBuilder idBuilder) throws DeploymentException {
0304:                if (planFile == null && jarFile == null) {
0305:                    return null;
0306:                }
0307:                ApplicationInfo plan = getEarPlan(planFile, jarFile, idBuilder);
0308:                if (plan != null) {
0309:                    return plan;
0310:                }
0311:                //Only "synthetic" ears with only external modules can have no jar file.
0312:                if (jarFile == null) {
0313:                    return null;
0314:                }
0315:
0316:                // get the modules either the application plan or for a stand alone module from the specific deployer
0317:                Module module = null;
0318:                if (getWebConfigBuilder() != null) {
0319:                    module = getWebConfigBuilder().createModule(planFile,
0320:                            jarFile, naming, idBuilder);
0321:                }
0322:                if (module == null && getEjbConfigBuilder() != null) {
0323:                    module = getEjbConfigBuilder().createModule(planFile,
0324:                            jarFile, naming, idBuilder);
0325:                }
0326:                if (module == null && getConnectorConfigBuilder() != null) {
0327:                    module = getConnectorConfigBuilder().createModule(planFile,
0328:                            jarFile, naming, idBuilder);
0329:                }
0330:                if (module == null && getAppClientConfigBuilder() != null) {
0331:                    module = getAppClientConfigBuilder().createModule(planFile,
0332:                            jarFile, naming, idBuilder);
0333:                }
0334:                if (module == null) {
0335:                    return null;
0336:                }
0337:
0338:                if (module instanceof  ApplicationInfo) {
0339:                    return module;
0340:                }
0341:
0342:                return new ApplicationInfo(module.getType(), module
0343:                        .getEnvironment(), module.getModuleName(), jarFile,
0344:                        null, null, new LinkedHashSet<Module>(Collections
0345:                                .singleton(module)), new ModuleList(), null);
0346:            }
0347:
0348:            private ApplicationInfo getEarPlan(File planFile, JarFile earFile,
0349:                    ModuleIDBuilder idBuilder) throws DeploymentException {
0350:                String specDD;
0351:                ApplicationType application = null;
0352:                if (earFile != null) {
0353:                    try {
0354:                        URL applicationXmlUrl = DeploymentUtil.createJarURL(
0355:                                earFile, "META-INF/application.xml");
0356:                        specDD = DeploymentUtil.readAll(applicationXmlUrl);
0357:                        //we found something called application.xml in the right place, if we can't parse it it's an error
0358:                        XmlObject xmlObject = XmlBeansUtil.parse(specDD);
0359:                        application = convertToApplicationSchema(xmlObject)
0360:                                .getApplication();
0361:                    } catch (XmlException e) {
0362:                        throw new DeploymentException(
0363:                                "Could not parse application.xml", e);
0364:                    } catch (Exception e) {
0365:                        //ee5 spec allows optional application.xml, continue with application == null
0366:                        if (!earFile.getName().endsWith(".ear")) {
0367:                            return null;
0368:                        }
0369:                        //TODO return application.xml that we can make metadata complete?
0370:                    }
0371:                }
0372:
0373:                GerApplicationType gerApplication = null;
0374:                try {
0375:                    // load the geronimo-application.xml from either the supplied plan or from the earFile
0376:                    XmlObject rawPlan;
0377:                    try {
0378:                        if (planFile != null) {
0379:                            rawPlan = XmlBeansUtil.parse(planFile.toURL(),
0380:                                    getClass().getClassLoader());
0381:                            gerApplication = (GerApplicationType) SchemaConversionUtils
0382:                                    .fixGeronimoSchema(rawPlan,
0383:                                            APPLICATION_QNAME,
0384:                                            GerApplicationType.type);
0385:                            if (gerApplication == null) {
0386:                                return null;
0387:                            }
0388:                        } else {
0389:                            URL path = DeploymentUtil.createJarURL(earFile,
0390:                                    "META-INF/geronimo-application.xml");
0391:                            rawPlan = XmlBeansUtil.parse(path, getClass()
0392:                                    .getClassLoader());
0393:                            gerApplication = (GerApplicationType) SchemaConversionUtils
0394:                                    .fixGeronimoSchema(rawPlan,
0395:                                            APPLICATION_QNAME,
0396:                                            GerApplicationType.type);
0397:                        }
0398:                    } catch (IOException e) {
0399:                        //TODO isn't this an error?
0400:                    }
0401:
0402:                    // if we got one extract the validate it otherwise create a default one
0403:                    if (gerApplication == null) {
0404:                        gerApplication = createDefaultPlan(application, earFile);
0405:                    }
0406:                } catch (XmlException e) {
0407:                    throw new DeploymentException(e);
0408:                }
0409:
0410:                EnvironmentType environmentType = gerApplication
0411:                        .getEnvironment();
0412:                Environment environment = EnvironmentBuilder.buildEnvironment(
0413:                        environmentType, defaultEnvironment);
0414:                idBuilder.resolve(environment, earFile == null ? planFile
0415:                        .getName() : new File(earFile.getName()).getName(),
0416:                        "ear");
0417:                // Make this EAR's settings the default for child modules
0418:                idBuilder.setDefaultGroup(environment.getConfigId()
0419:                        .getGroupId());
0420:                idBuilder.setDefaultVersion(environment.getConfigId()
0421:                        .getVersion());
0422:
0423:                Artifact artifact = environment.getConfigId();
0424:                AbstractName earName = naming.createRootName(artifact, artifact
0425:                        .toString(), NameFactory.J2EE_APPLICATION);
0426:
0427:                // get the modules either the application plan or for a stand alone module from the specific deployer
0428:                // todo change module so you can extract the real module path back out.. then we can eliminate
0429:                // the moduleLocations and have addModules return the modules
0430:                ModuleList moduleLocations = new ModuleList();
0431:                LinkedHashSet<Module> modules = new LinkedHashSet<Module>();
0432:                try {
0433:                    addModules(earFile, application, gerApplication,
0434:                            moduleLocations, modules, environment, earName,
0435:                            idBuilder);
0436:                    if (application == null && modules.isEmpty()) {
0437:                        //if no application.xml and no modules detected, return null for stand-alone module processing
0438:                        return null;
0439:                    }
0440:                } catch (Throwable e) {
0441:                    // close all the modules
0442:                    for (Module module : modules) {
0443:                        module.close();
0444:                    }
0445:
0446:                    if (e instanceof  DeploymentException) {
0447:                        throw (DeploymentException) e;
0448:                    } else if (e instanceof  RuntimeException) {
0449:                        throw (RuntimeException) e;
0450:                    } else if (e instanceof  Error) {
0451:                        throw (Error) e;
0452:                    }
0453:                    throw new DeploymentException(e);
0454:                }
0455:
0456:                return new ApplicationInfo(ConfigurationModuleType.EAR,
0457:                        environment, earName, earFile, application,
0458:                        gerApplication, modules, moduleLocations,
0459:                        application == null ? null : application.toString());
0460:            }
0461:
0462:            private GerApplicationType createDefaultPlan(
0463:                    ApplicationType application, JarFile module) {
0464:                // construct the empty geronimo-application.xml
0465:                GerApplicationType gerApplication = GerApplicationType.Factory
0466:                        .newInstance();
0467:                EnvironmentType environmentType = gerApplication
0468:                        .addNewEnvironment();
0469:                ArtifactType artifactType = environmentType.addNewModuleId();
0470:
0471:                artifactType.setGroupId(Artifact.DEFAULT_GROUP_ID);
0472:
0473:                // set the configId
0474:                String id = application != null ? application.getId() : null;
0475:                if (id == null) {
0476:                    File fileName = new File(module.getName());
0477:                    id = fileName.getName();
0478:                    if (id.endsWith(".ear")) {
0479:                        id = id.substring(0, id.length() - 4);
0480:                    }
0481:                    if (id.endsWith("/")) {
0482:                        id = id.substring(0, id.length() - 1);
0483:                    }
0484:                }
0485:
0486:                artifactType.setArtifactId(id);
0487:                artifactType.setVersion("" + System.currentTimeMillis());
0488:                artifactType.setType("car");
0489:                return gerApplication;
0490:            }
0491:
0492:            static ApplicationDocument convertToApplicationSchema(
0493:                    XmlObject xmlObject) throws XmlException {
0494:                if (ApplicationDocument.type.equals(xmlObject.schemaType())) {
0495:                    XmlBeansUtil.validateDD(xmlObject);
0496:                    return (ApplicationDocument) xmlObject;
0497:                }
0498:                XmlCursor cursor = xmlObject.newCursor();
0499:                XmlCursor moveable = xmlObject.newCursor();
0500:                String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application_5.xsd";
0501:                String version = "5";
0502:                try {
0503:                    cursor.toStartDoc();
0504:                    cursor.toFirstChild();
0505:                    if ("http://java.sun.com/xml/ns/j2ee".equals(cursor
0506:                            .getName().getNamespaceURI())) {
0507:                        SchemaConversionUtils.convertSchemaVersion(cursor,
0508:                                SchemaConversionUtils.JAVAEE_NAMESPACE,
0509:                                schemaLocationURL, version);
0510:                        XmlObject result = xmlObject
0511:                                .changeType(ApplicationDocument.type);
0512:                        XmlBeansUtil.validateDD(result);
0513:                        return (ApplicationDocument) result;
0514:                    }
0515:
0516:                    // otherwise assume DTD
0517:                    SchemaConversionUtils.convertToSchema(cursor,
0518:                            SchemaConversionUtils.JAVAEE_NAMESPACE,
0519:                            schemaLocationURL, version);
0520:                    cursor.toStartDoc();
0521:                    cursor.toChild(SchemaConversionUtils.JAVAEE_NAMESPACE,
0522:                            "application");
0523:                    cursor.toFirstChild();
0524:                    SchemaConversionUtils.convertToDescriptionGroup(
0525:                            SchemaConversionUtils.JAVAEE_NAMESPACE, cursor,
0526:                            moveable);
0527:                } finally {
0528:                    cursor.dispose();
0529:                    moveable.dispose();
0530:                }
0531:                XmlObject result = xmlObject
0532:                        .changeType(ApplicationDocument.type);
0533:                if (result != null) {
0534:                    XmlBeansUtil.validateDD(result);
0535:                    return (ApplicationDocument) result;
0536:                }
0537:                XmlBeansUtil.validateDD(xmlObject);
0538:                return (ApplicationDocument) xmlObject;
0539:            }
0540:
0541:            public Artifact getConfigurationID(Object plan, JarFile module,
0542:                    ModuleIDBuilder idBuilder) throws IOException,
0543:                    DeploymentException {
0544:                ApplicationInfo applicationInfo = (ApplicationInfo) plan;
0545:                Artifact test = applicationInfo.getEnvironment().getConfigId();
0546:                if (!test.isResolved()) {
0547:                    throw new IllegalStateException(
0548:                            "Module ID should be fully resolved by now (not "
0549:                                    + test + ")");
0550:                }
0551:                return test;
0552:            }
0553:
0554:            public DeploymentContext buildConfiguration(
0555:                    boolean inPlaceDeployment, Artifact configId, Object plan,
0556:                    JarFile earFile, Collection configurationStores,
0557:                    ArtifactResolver artifactResolver,
0558:                    ConfigurationStore targetConfigurationStore)
0559:                    throws IOException, DeploymentException {
0560:                assert plan != null;
0561:                ApplicationInfo applicationInfo = (ApplicationInfo) plan;
0562:
0563:                EARContext earContext = null;
0564:                ConfigurationModuleType applicationType = applicationInfo
0565:                        .getType();
0566:                applicationInfo.getEnvironment().setConfigId(configId);
0567:                File configurationDir = null;
0568:                try {
0569:                    try {
0570:                        configurationDir = targetConfigurationStore
0571:                                .createNewConfigurationDir(configId);
0572:                    } catch (ConfigurationAlreadyExistsException e) {
0573:                        throw new DeploymentException(e);
0574:                    }
0575:
0576:                    ConfigurationManager configurationManager = this .configurationManager;
0577:                    if (configurationManager == null) {
0578:                        configurationManager = new SimpleConfigurationManager(
0579:                                configurationStores, artifactResolver,
0580:                                repositories);
0581:                    }
0582:
0583:                    // Create the output ear context
0584:                    earContext = new EARContext(configurationDir,
0585:                            inPlaceDeployment ? DeploymentUtil.toFile(earFile)
0586:                                    : null, applicationInfo.getEnvironment(),
0587:                            applicationType, naming, configurationManager,
0588:                            repositories, serverName, applicationInfo
0589:                                    .getModuleName(),
0590:                            transactionManagerObjectName,
0591:                            connectionTrackerObjectName,
0592:                            transactionalTimerObjectName,
0593:                            nonTransactionalTimerObjectName,
0594:                            corbaGBeanObjectName);
0595:                    applicationInfo.setEarContext(earContext);
0596:                    applicationInfo.setRootEarContext(earContext);
0597:                    earContext.getGeneralData().put(ModuleList.class,
0598:                            applicationInfo.getModuleLocations());
0599:
0600:                    // Copy over all files that are _NOT_ modules (e.g. META-INF and APP-INF files)
0601:                    Set moduleLocations = applicationInfo.getModuleLocations();
0602:                    ClassPathList libClasspath = new ClassPathList();
0603:                    if (ConfigurationModuleType.EAR == applicationType
0604:                            && earFile != null) {
0605:                        //get the value of the library-directory element in spec DD
0606:                        ApplicationType specDD = (ApplicationType) applicationInfo
0607:                                .getSpecDD();
0608:                        String libDir = getLibraryDirectory(specDD);
0609:                        for (Enumeration<JarEntry> e = earFile.entries(); e
0610:                                .hasMoreElements();) {
0611:                            ZipEntry entry = e.nextElement();
0612:                            String entryName = entry.getName();
0613:                            boolean addEntry = true;
0614:                            for (Object moduleLocation : moduleLocations) {
0615:                                String location = (String) moduleLocation;
0616:                                if (entryName.startsWith(location)) {
0617:                                    addEntry = false;
0618:                                    break;
0619:                                }
0620:                            }
0621:                            if (libDir != null
0622:                                    && entry.getName().startsWith(libDir)
0623:                                    && entry.getName().endsWith(".jar")) {
0624:                                NestedJarFile library = new NestedJarFile(
0625:                                        earFile, entry.getName());
0626:                                earContext.addIncludeAsPackedJar(URI
0627:                                        .create(entry.getName()), library);
0628:                                libClasspath.add(entry.getName());
0629:                            } else if (addEntry) {
0630:                                earContext.addFile(URI.create(entry.getName()),
0631:                                        earFile, entry);
0632:                            }
0633:                        }
0634:                        if (!libClasspath.isEmpty()) {
0635:                            earContext.getGeneralData().put(
0636:                                    ClassPathList.class, libClasspath);
0637:                        }
0638:                    }
0639:
0640:                    GerApplicationType geronimoApplication = (GerApplicationType) applicationInfo
0641:                            .getVendorDD();
0642:
0643:                    // each module installs it's files into the output context.. this is different for each module type
0644:                    LinkedHashSet modules = applicationInfo.getModules();
0645:                    for (Object module2 : modules) {
0646:                        Module module = (Module) module2;
0647:                        getBuilder(module).installModule(earFile, earContext,
0648:                                module, configurationStores,
0649:                                targetConfigurationStore, repositories);
0650:                    }
0651:
0652:                    earContext.flush();
0653:
0654:                    // give each module a chance to populate the earContext now that a classloader is available
0655:                    ClassLoader cl = earContext.getClassLoader();
0656:                    for (Object module3 : modules) {
0657:                        Module module = (Module) module3;
0658:                        getBuilder(module).initContext(earContext, module, cl);
0659:                    }
0660:
0661:                    // add gbeans declared in the geronimo-application.xml
0662:                    if (geronimoApplication != null) {
0663:                        securityBuilders.build(geronimoApplication, earContext,
0664:                                earContext);
0665:                        serviceBuilders.build(geronimoApplication, earContext,
0666:                                earContext);
0667:                    }
0668:
0669:                    if (ConfigurationModuleType.EAR == applicationType) {
0670:                        // process persistence unit in EAR library directory
0671:                        earContext.getGeneralData().put(ClassPathList.class,
0672:                                libClasspath);
0673:                        for (ModuleBuilderExtension mbe : persistenceUnitBuilders) {
0674:                            mbe.initContext(earContext, applicationInfo,
0675:                                    earContext.getClassLoader());
0676:                        }
0677:
0678:                        // Create the J2EEApplication managed object
0679:                        GBeanData gbeanData = new GBeanData(earContext
0680:                                .getModuleName(),
0681:                                J2EEApplicationImpl.GBEAN_INFO);
0682:                        try {
0683:                            String originalSpecDD = applicationInfo
0684:                                    .getOriginalSpecDD();
0685:                            if (originalSpecDD == null) {
0686:                                originalSpecDD = "Synthetic EAR";
0687:                            }
0688:                            gbeanData.setAttribute("deploymentDescriptor",
0689:                                    originalSpecDD);
0690:                        } catch (Exception e) {
0691:                            throw new DeploymentException(
0692:                                    "Error initializing J2EEApplication managed object",
0693:                                    e);
0694:                        }
0695:                        gbeanData.setReferencePatterns("Server",
0696:                                new ReferencePatterns(new AbstractNameQuery(
0697:                                        J2EEServer.class.getName())));
0698:
0699:                        Map<String, String> this App = Collections.singletonMap(
0700:                                NameFactory.J2EE_APPLICATION, earContext
0701:                                        .getModuleName().getNameProperty(
0702:                                                NameFactory.J2EE_NAME));
0703:                        LinkedHashSet<AbstractNameQuery> resourcePatterns = new LinkedHashSet<AbstractNameQuery>();
0704:                        resourcePatterns.add(new AbstractNameQuery(null,
0705:                                filter(this App, NameFactory.J2EE_TYPE,
0706:                                        NameFactory.JAVA_MAIL_RESOURCE),
0707:                                J2EEResource.class.getName()));
0708:                        resourcePatterns.add(new AbstractNameQuery(null,
0709:                                filter(this App, NameFactory.J2EE_TYPE,
0710:                                        NameFactory.JCA_CONNECTION_FACTORY),
0711:                                J2EEResource.class.getName()));
0712:                        resourcePatterns.add(new AbstractNameQuery(null,
0713:                                filter(this App, NameFactory.J2EE_TYPE,
0714:                                        NameFactory.JDBC_RESOURCE),
0715:                                J2EEResource.class.getName()));
0716:                        resourcePatterns.add(new AbstractNameQuery(null,
0717:                                filter(this App, NameFactory.J2EE_TYPE,
0718:                                        NameFactory.JDBC_DRIVER),
0719:                                J2EEResource.class.getName()));
0720:                        resourcePatterns.add(new AbstractNameQuery(null,
0721:                                filter(this App, NameFactory.J2EE_TYPE,
0722:                                        NameFactory.JMS_RESOURCE),
0723:                                J2EEResource.class.getName()));
0724:                        resourcePatterns.add(new AbstractNameQuery(null,
0725:                                filter(this App, NameFactory.J2EE_TYPE,
0726:                                        NameFactory.JNDI_RESOURCE),
0727:                                J2EEResource.class.getName()));
0728:                        resourcePatterns.add(new AbstractNameQuery(null,
0729:                                filter(this App, NameFactory.J2EE_TYPE,
0730:                                        NameFactory.JTA_RESOURCE),
0731:                                J2EEResource.class.getName()));
0732:                        resourcePatterns.add(new AbstractNameQuery(null,
0733:                                filter(this App, NameFactory.J2EE_TYPE,
0734:                                        NameFactory.RMI_IIOP_RESOURCE),
0735:                                J2EEResource.class.getName()));
0736:                        resourcePatterns.add(new AbstractNameQuery(null,
0737:                                filter(this App, NameFactory.J2EE_TYPE,
0738:                                        NameFactory.URL_RESOURCE),
0739:                                J2EEResource.class.getName()));
0740:                        gbeanData.setReferencePatterns("Resources",
0741:                                resourcePatterns);
0742:
0743:                        gbeanData
0744:                                .setReferencePatterns(
0745:                                        "AppClientModules",
0746:                                        new ReferencePatterns(
0747:                                                new AbstractNameQuery(
0748:                                                        null,
0749:                                                        this App,
0750:                                                        org.apache.geronimo.management.AppClientModule.class
0751:                                                                .getName())));
0752:                        gbeanData
0753:                                .setReferencePatterns(
0754:                                        "EJBModules",
0755:                                        new ReferencePatterns(
0756:                                                new AbstractNameQuery(
0757:                                                        null,
0758:                                                        this App,
0759:                                                        org.apache.geronimo.management.EJBModule.class
0760:                                                                .getName())));
0761:                        gbeanData
0762:                                .setReferencePatterns(
0763:                                        "ResourceAdapterModules",
0764:                                        new ReferencePatterns(
0765:                                                new AbstractNameQuery(
0766:                                                        null,
0767:                                                        this App,
0768:                                                        org.apache.geronimo.management.geronimo.ResourceAdapterModule.class
0769:                                                                .getName())));
0770:                        gbeanData
0771:                                .setReferencePatterns(
0772:                                        "WebModules",
0773:                                        new ReferencePatterns(
0774:                                                new AbstractNameQuery(
0775:                                                        null,
0776:                                                        this App,
0777:                                                        org.apache.geronimo.management.geronimo.WebModule.class
0778:                                                                .getName())));
0779:                        earContext.addGBean(gbeanData);
0780:                    }
0781:
0782:                    // each module can now add it's GBeans
0783:                    for (Object module1 : modules) {
0784:                        Module module = (Module) module1;
0785:                        getBuilder(module).addGBeans(earContext, module, cl,
0786:                                repositories);
0787:                    }
0788:
0789:                    // it's the caller's responsibility to close the context...
0790:                    return earContext;
0791:                } catch (GBeanAlreadyExistsException e) {
0792:                    cleanupContext(earContext, configurationDir);
0793:                    throw new DeploymentException(e);
0794:                } catch (IOException e) {
0795:                    cleanupContext(earContext, configurationDir);
0796:                    throw e;
0797:                } catch (DeploymentException e) {
0798:                    cleanupContext(earContext, configurationDir);
0799:                    throw e;
0800:                } catch (RuntimeException e) {
0801:                    cleanupContext(earContext, configurationDir);
0802:                    throw e;
0803:                } catch (Error e) {
0804:                    cleanupContext(earContext, configurationDir);
0805:                    throw e;
0806:                } finally {
0807:                    for (Object module1 : applicationInfo.getModules()) {
0808:                        Module module = (Module) module1;
0809:                        module.close();
0810:                    }
0811:                }
0812:            }
0813:
0814:            private String getLibraryDirectory(ApplicationType specDD) {
0815:                if (specDD == null || !specDD.isSetLibraryDirectory()) {
0816:                    //value 'lib' is used if element not set or ear does not contain a dd
0817:                    return "lib";
0818:                }
0819:
0820:                //only set if not empty value, empty value implies no library directory
0821:                String value = specDD.getLibraryDirectory().getStringValue();
0822:                return value.trim().length() > 0 ? value : null;
0823:            }
0824:
0825:            private void cleanupContext(EARContext earContext,
0826:                    File configurationDir) {
0827:                List<ConfigurationData> configurations = new ArrayList<ConfigurationData>();
0828:                if (earContext != null) {
0829:                    configurations.addAll(earContext.getAdditionalDeployment());
0830:                    try {
0831:                        earContext.close();
0832:                    } catch (IOException ioe) {
0833:                        // ignore any cleanup problems
0834:                    } catch (DeploymentException de) {
0835:                        // ignore any cleanup problems
0836:                    }
0837:                }
0838:                // configurationDir is created before we create an EARContext
0839:                if (configurationDir != null) {
0840:                    cleanupConfigurationDir(configurationDir);
0841:                }
0842:                // cleanup any other configurations generated (e.g. AppClient config dirs)
0843:                for (ConfigurationData configurationData : configurations) {
0844:                    cleanupConfigurationDir(configurationData
0845:                            .getConfigurationDir());
0846:                }
0847:            }
0848:
0849:            private boolean cleanupConfigurationDir(File configurationDir) {
0850:                LinkedList<String> cannotBeDeletedList = new LinkedList<String>();
0851:
0852:                if (!DeploymentUtil.recursiveDelete(configurationDir,
0853:                        cannotBeDeletedList)) {
0854:                    // Output a message to help user track down file problem
0855:                    log
0856:                            .warn("Unable to delete "
0857:                                    + cannotBeDeletedList.size()
0858:                                    + " files while recursively deleting directory "
0859:                                    + configurationDir.getAbsolutePath()
0860:                                    + LINE_SEP
0861:                                    + "The first file that could not be deleted was:"
0862:                                    + LINE_SEP
0863:                                    + "  "
0864:                                    + (!cannotBeDeletedList.isEmpty() ? cannotBeDeletedList
0865:                                            .getFirst()
0866:                                            : ""));
0867:                    return false;
0868:                }
0869:                return true;
0870:            }
0871:
0872:            private static Map<String, String> filter(
0873:                    Map<String, String> original, String key, String value) {
0874:                LinkedHashMap<String, String> filter = new LinkedHashMap<String, String>(
0875:                        original);
0876:                filter.put(key, value);
0877:                return filter;
0878:            }
0879:
0880:            private void addModules(JarFile earFile,
0881:                    ApplicationType application,
0882:                    GerApplicationType gerApplication,
0883:                    ModuleList moduleLocations, LinkedHashSet<Module> modules,
0884:                    Environment environment, AbstractName earName,
0885:                    ModuleIDBuilder idBuilder) throws DeploymentException {
0886:                Map<String, Object> altVendorDDs = new HashMap<String, Object>();
0887:                try {
0888:                    mapVendorPlans(gerApplication, altVendorDDs, earFile);
0889:                    if (earFile != null) {
0890:                        if (application != null) {
0891:                            ModuleType[] moduleTypes = application
0892:                                    .getModuleArray();
0893:
0894:                            //get a set containing all of the files in the ear that are actually modules
0895:                            for (ModuleType moduleXml : moduleTypes) {
0896:                                String modulePath;
0897:                                ModuleBuilder builder;
0898:
0899:                                Object moduleContextInfo = null;
0900:                                String moduleTypeName;
0901:                                if (moduleXml.isSetEjb()) {
0902:                                    modulePath = moduleXml.getEjb()
0903:                                            .getStringValue();
0904:                                    builder = getEjbConfigBuilder();
0905:                                    if (builder == null) {
0906:                                        throw new DeploymentException(
0907:                                                "Cannot deploy ejb application; No ejb deployer defined: "
0908:                                                        + modulePath);
0909:                                    }
0910:                                    moduleTypeName = "an EJB";
0911:                                } else if (moduleXml.isSetWeb()) {
0912:                                    modulePath = moduleXml.getWeb().getWebUri()
0913:                                            .getStringValue();
0914:                                    if (getWebConfigBuilder() == null) {
0915:                                        throw new DeploymentException(
0916:                                                "Cannot deploy web application; No war deployer defined: "
0917:                                                        + modulePath);
0918:                                    }
0919:                                    builder = getWebConfigBuilder();
0920:                                    moduleTypeName = "a war";
0921:                                    moduleContextInfo = moduleXml.getWeb()
0922:                                            .getContextRoot().getStringValue()
0923:                                            .trim();
0924:                                } else if (moduleXml.isSetConnector()) {
0925:                                    modulePath = moduleXml.getConnector()
0926:                                            .getStringValue();
0927:                                    if (getConnectorConfigBuilder() == null) {
0928:                                        throw new DeploymentException(
0929:                                                "Cannot deploy resource adapter; No rar deployer defined: "
0930:                                                        + modulePath);
0931:                                    }
0932:                                    builder = getConnectorConfigBuilder();
0933:                                    moduleTypeName = "a connector";
0934:                                } else if (moduleXml.isSetJava()) {
0935:                                    modulePath = moduleXml.getJava()
0936:                                            .getStringValue();
0937:                                    if (getAppClientConfigBuilder() == null) {
0938:                                        throw new DeploymentException(
0939:                                                "Cannot deploy app client; No app client deployer defined: "
0940:                                                        + modulePath);
0941:                                    }
0942:                                    builder = getAppClientConfigBuilder();
0943:                                    moduleTypeName = "an application client";
0944:                                } else {
0945:                                    throw new DeploymentException(
0946:                                            "Could not find a module builder for module: "
0947:                                                    + moduleXml);
0948:                                }
0949:
0950:                                moduleLocations.add(modulePath);
0951:
0952:                                NestedJarFile moduleFile;
0953:                                try {
0954:                                    moduleFile = new NestedJarFile(earFile,
0955:                                            modulePath);
0956:                                } catch (IOException e) {
0957:                                    throw new DeploymentException(
0958:                                            "Invalid moduleFile: " + modulePath,
0959:                                            e);
0960:                                }
0961:
0962:                                Module module = builder.createModule(
0963:                                        altVendorDDs.get(modulePath),
0964:                                        moduleFile, modulePath,
0965:                                        getAltSpecDDURL(earFile, moduleXml),
0966:                                        environment, moduleContextInfo,
0967:                                        earName, naming, idBuilder);
0968:
0969:                                if (module == null) {
0970:                                    throw new DeploymentException(
0971:                                            "Module was not " + moduleTypeName
0972:                                                    + ": " + modulePath);
0973:                                }
0974:
0975:                                modules.add(module);
0976:                            }
0977:                        } else {
0978:                            //no application.xml available, must inspect ear to locate and process modules
0979:                            Enumeration<JarEntry> entries = earFile.entries();
0980:                            while (entries.hasMoreElements()) {
0981:                                ModuleBuilder builder;
0982:                                Object moduleContextInfo = null;
0983:                                String moduleTypeName;
0984:                                ZipEntry entry = entries.nextElement();
0985:                                if (entry.getName().endsWith(".war")) {
0986:                                    if (getWebConfigBuilder() == null) {
0987:                                        throw new DeploymentException(
0988:                                                "Cannot deploy web application; No war deployer defined: "
0989:                                                        + entry.getName());
0990:                                    }
0991:                                    builder = getWebConfigBuilder();
0992:                                    moduleTypeName = "a war";
0993:                                    moduleContextInfo = entry.getName().split(
0994:                                            ".war")[0];
0995:                                } else if (entry.getName().endsWith(".rar")) {
0996:                                    if (getConnectorConfigBuilder() == null) {
0997:                                        throw new DeploymentException(
0998:                                                "Cannot deploy resource adapter; No rar deployer defined: "
0999:                                                        + entry.getName());
1000:                                    }
1001:                                    builder = getConnectorConfigBuilder();
1002:                                    moduleTypeName = "a connector";
1003:                                } else if (entry.getName().endsWith(".jar")
1004:                                        && !isLibraryEntry(application, entry)) {
1005:                                    try {
1006:                                        NestedJarFile moduleFile = new NestedJarFile(
1007:                                                earFile, entry.getName());
1008:                                        Manifest mf = moduleFile.getManifest();
1009:
1010:                                        if (mf.getMainAttributes().getValue(
1011:                                                Attributes.Name.MAIN_CLASS) != null) {
1012:                                            if (getAppClientConfigBuilder() == null) {
1013:                                                throw new DeploymentException(
1014:                                                        "Cannot deploy app client; No app client deployer defined: "
1015:                                                                + entry
1016:                                                                        .getName());
1017:                                            }
1018:                                            builder = getAppClientConfigBuilder();
1019:                                            moduleTypeName = "an application client";
1020:                                        } else {
1021:                                            //ask the ejb builder if its an ejb module
1022:                                            builder = getEjbConfigBuilder();
1023:                                            if (builder == null) {
1024:                                                //                                        throw new DeploymentException("Cannot deploy ejb application; No ejb deployer defined: " + entry.getName());
1025:                                                continue;
1026:                                            }
1027:
1028:                                            Module module = builder
1029:                                                    .createModule(
1030:                                                            altVendorDDs
1031:                                                                    .get(entry
1032:                                                                            .getName()),
1033:                                                            moduleFile, entry
1034:                                                                    .getName(),
1035:                                                            null, environment,
1036:                                                            moduleContextInfo,
1037:                                                            earName, naming,
1038:                                                            idBuilder);
1039:
1040:                                            if (module != null) {
1041:                                                moduleLocations.add(entry
1042:                                                        .getName());
1043:                                                modules.add(module);
1044:                                            }
1045:                                            continue;
1046:                                        }
1047:                                        //TODO if no ejb-jar.xml inspect classes for EJB component annotations to identify as EJBJar module
1048:                                    } catch (IOException e) {
1049:                                        throw new DeploymentException(
1050:                                                "Invalid moduleFile: "
1051:                                                        + entry.getName(), e);
1052:                                    }
1053:                                } else {
1054:                                    continue;
1055:                                }
1056:
1057:                                moduleLocations.add(entry.getName());
1058:
1059:                                NestedJarFile moduleFile;
1060:                                try {
1061:                                    moduleFile = new NestedJarFile(earFile,
1062:                                            entry.getName());
1063:                                } catch (IOException e) {
1064:                                    throw new DeploymentException(
1065:                                            "Invalid moduleFile: "
1066:                                                    + entry.getName(), e);
1067:                                }
1068:
1069:                                Module module = builder.createModule(
1070:                                        altVendorDDs.get(entry.getName()),
1071:                                        moduleFile, entry.getName(), null,
1072:                                        environment, moduleContextInfo,
1073:                                        earName, naming, idBuilder);
1074:
1075:                                if (module == null) {
1076:                                    throw new DeploymentException(
1077:                                            "Module was not " + moduleTypeName
1078:                                                    + ": " + entry.getName());
1079:                                }
1080:
1081:                                modules.add(module);
1082:                            }
1083:                        }
1084:                    }
1085:
1086:                    //all the modules in the geronimo plan should have been found by now.
1087:                    if (!moduleLocations.containsAll(altVendorDDs.keySet())) {
1088:                        throw new DeploymentException(
1089:                                "Geronimo ear plan contains modules that aren't in the ear: "
1090:                                        + new HashSet<String>(moduleLocations)
1091:                                                .removeAll(altVendorDDs
1092:                                                        .keySet()));
1093:                    }
1094:                    //deploy the extension modules
1095:                    for (GerExtModuleType gerExtModule : gerApplication
1096:                            .getExtModuleArray()) {
1097:                        String moduleName;
1098:                        ModuleBuilder builder;
1099:                        Object moduleContextInfo = null;
1100:                        String moduleTypeName;
1101:
1102:                        if (gerExtModule.isSetEjb()) {
1103:                            moduleName = gerExtModule.getEjb().getStringValue();
1104:                            builder = getEjbConfigBuilder();
1105:                            if (builder == null) {
1106:                                throw new DeploymentException(
1107:                                        "Cannot deploy ejb application; No ejb deployer defined: "
1108:                                                + moduleName);
1109:                            }
1110:                            moduleTypeName = "an EJB";
1111:                        } else if (gerExtModule.isSetWeb()) {
1112:                            moduleName = gerExtModule.getWeb().getStringValue();
1113:                            if (getWebConfigBuilder() == null) {
1114:                                throw new DeploymentException(
1115:                                        "Cannot deploy web application; No war deployer defined: "
1116:                                                + moduleName);
1117:                            }
1118:                            builder = getWebConfigBuilder();
1119:                            moduleTypeName = "a war";
1120:                            //ext modules must use vendor plan to set context-root
1121:                        } else if (gerExtModule.isSetConnector()) {
1122:                            moduleName = gerExtModule.getConnector()
1123:                                    .getStringValue();
1124:                            if (getConnectorConfigBuilder() == null) {
1125:                                throw new DeploymentException(
1126:                                        "Cannot deploy resource adapter; No rar deployer defined: "
1127:                                                + moduleName);
1128:                            }
1129:                            builder = getConnectorConfigBuilder();
1130:                            moduleTypeName = "a connector";
1131:                        } else if (gerExtModule.isSetJava()) {
1132:                            moduleName = gerExtModule.getJava()
1133:                                    .getStringValue();
1134:                            if (getAppClientConfigBuilder() == null) {
1135:                                throw new DeploymentException(
1136:                                        "Cannot deploy app client; No app client deployer defined: "
1137:                                                + moduleName);
1138:                            }
1139:                            builder = getAppClientConfigBuilder();
1140:                            moduleTypeName = "an application client";
1141:                        } else {
1142:                            throw new DeploymentException(
1143:                                    "Could not find a module builder for module: "
1144:                                            + gerExtModule);
1145:                        }
1146:                        //dd is included explicitly
1147:                        XmlObject[] anys = gerExtModule
1148:                                .selectChildren(GerExtModuleType.type
1149:                                        .qnameSetForWildcardElements());
1150:                        if (anys.length != 1) {
1151:                            throw new DeploymentException(
1152:                                    "Unexpected count of xs:any elements in embedded vendor plan "
1153:                                            + anys.length
1154:                                            + " qnameset: "
1155:                                            + GerExtModuleType.type
1156:                                                    .qnameSetForWildcardElements());
1157:                        }
1158:                        Object vendorDD = anys[0];
1159:
1160:                        JarFile moduleFile;
1161:                        if (gerExtModule.isSetInternalPath()) {
1162:                            String modulePath = gerExtModule.getInternalPath()
1163:                                    .trim();
1164:                            moduleLocations.add(modulePath);
1165:                            try {
1166:                                moduleFile = new NestedJarFile(earFile,
1167:                                        modulePath);
1168:                            } catch (IOException e) {
1169:                                throw new DeploymentException(
1170:                                        "Invalid moduleFile: " + modulePath, e);
1171:                            }
1172:                        } else {
1173:                            PatternType patternType = gerExtModule
1174:                                    .getExternalPath();
1175:                            String groupId = trim(patternType.getGroupId());
1176:                            String artifactId = trim(patternType
1177:                                    .getArtifactId());
1178:                            String version = trim(patternType.getVersion());
1179:                            String type = trim(patternType.getType());
1180:                            Artifact artifact = new Artifact(groupId,
1181:                                    artifactId, version, type);
1182:                            try {
1183:                                artifact = getArtifactResolver()
1184:                                        .resolveInClassLoader(artifact);
1185:                            } catch (MissingDependencyException e) {
1186:                                throw new DeploymentException(
1187:                                        "Could not resolve external rar location in repository: "
1188:                                                + artifact, e);
1189:                            }
1190:                            File location = null;
1191:                            for (Repository repository : repositories) {
1192:                                if (repository.contains(artifact)) {
1193:                                    location = repository.getLocation(artifact);
1194:                                    break;
1195:                                }
1196:                            }
1197:                            if (location == null) {
1198:                                throw new DeploymentException(moduleTypeName
1199:                                        + " is missing in repositories: "
1200:                                        + artifact);
1201:                            }
1202:                            try {
1203:                                moduleFile = new JarFile(location);
1204:                            } catch (IOException e) {
1205:                                throw new DeploymentException(
1206:                                        "Could not access contents of "
1207:                                                + moduleTypeName, e);
1208:                            }
1209:
1210:                        }
1211:
1212:                        Module module = builder.createModule(vendorDD,
1213:                                moduleFile, moduleName,
1214:                                null, //TODO implement an alt-spec-dd element
1215:                                environment, moduleContextInfo, earName,
1216:                                naming, idBuilder);
1217:
1218:                        if (module == null) {
1219:                            throw new DeploymentException("Module was not "
1220:                                    + moduleTypeName + ": " + moduleName);
1221:                        }
1222:
1223:                        modules.add(module);
1224:                    }
1225:                } finally {
1226:                    // delete all the temp files created for alt vendor dds
1227:                    for (Object altVendorDD : altVendorDDs.values()) {
1228:                        if (altVendorDD instanceof  File) {
1229:                            ((File) altVendorDD).delete();
1230:                        }
1231:                    }
1232:                }
1233:            }
1234:
1235:            private ArtifactResolver getArtifactResolver()
1236:                    throws DeploymentException {
1237:                if (artifactResolvers == null || artifactResolvers.isEmpty()) {
1238:                    throw new DeploymentException(
1239:                            "No artifact resolver supplied to resolve external module");
1240:                }
1241:                return artifactResolvers.iterator().next();
1242:            }
1243:
1244:            private String trim(String s) {
1245:                if (s == null) {
1246:                    return null;
1247:                }
1248:                return s.trim();
1249:            }
1250:
1251:            private boolean isLibraryEntry(ApplicationType application,
1252:                    ZipEntry entry) {
1253:                String libDir = getLibraryDirectory(application);
1254:                return libDir != null && entry.getName().startsWith(libDir);
1255:            }
1256:
1257:            private void mapVendorPlans(GerApplicationType gerApplication,
1258:                    Map<String, Object> altVendorDDs, JarFile earFile)
1259:                    throws DeploymentException {
1260:                //build map from module path to alt vendor dd
1261:                for (GerModuleType gerModule : gerApplication.getModuleArray()) {
1262:                    String path = null;
1263:                    if (gerModule.isSetEjb()) {
1264:                        path = gerModule.getEjb().getStringValue();
1265:                    } else if (gerModule.isSetWeb()) {
1266:                        path = gerModule.getWeb().getStringValue();
1267:                    } else if (gerModule.isSetConnector()) {
1268:                        path = gerModule.getConnector().getStringValue();
1269:                    } else if (gerModule.isSetJava()) {
1270:                        path = gerModule.getJava().getStringValue();
1271:                    }
1272:                    //            if (!paths.contains(path)) {
1273:                    //                throw new DeploymentException("Geronimo deployment plan refers to module '" + path + "' but that was not defined in the META-INF/application.xml");
1274:                    //            }
1275:
1276:                    if (gerModule.isSetAltDd()) {
1277:                        // the the url of the alt dd
1278:                        try {
1279:                            altVendorDDs.put(path, DeploymentUtil.toTempFile(
1280:                                    earFile, gerModule.getAltDd()
1281:                                            .getStringValue()));
1282:                        } catch (IOException e) {
1283:                            throw new DeploymentException(
1284:                                    "Invalid alt vendor dd url: "
1285:                                            + gerModule.getAltDd()
1286:                                                    .getStringValue(), e);
1287:                        }
1288:                    } else {
1289:                        //dd is included explicitly
1290:                        XmlObject[] anys = gerModule
1291:                                .selectChildren(GerModuleType.type
1292:                                        .qnameSetForWildcardElements());
1293:                        if (anys.length != 1) {
1294:                            throw new DeploymentException(
1295:                                    "Unexpected count of xs:any elements in embedded vendor plan "
1296:                                            + anys.length
1297:                                            + " qnameset: "
1298:                                            + GerModuleType.type
1299:                                                    .qnameSetForWildcardElements());
1300:                        }
1301:                        altVendorDDs.put(path, anys[0]);
1302:                    }
1303:                }
1304:            }
1305:
1306:            private URL getAltSpecDDURL(JarFile earFile, ModuleType moduleXml)
1307:                    throws DeploymentException {
1308:                if (moduleXml != null && moduleXml.isSetAltDd()) {
1309:                    try {
1310:                        return DeploymentUtil.createJarURL(earFile, moduleXml
1311:                                .getAltDd().getStringValue());
1312:                    } catch (MalformedURLException e) {
1313:                        throw new DeploymentException(
1314:                                "Invalid alt sped dd url: "
1315:                                        + moduleXml.getAltDd().getStringValue(),
1316:                                e);
1317:                    }
1318:                }
1319:                return null;
1320:            }
1321:
1322:            private ModuleBuilder getBuilder(Module module)
1323:                    throws DeploymentException {
1324:                if (module instanceof  EJBModule) {
1325:                    if (getEjbConfigBuilder() == null) {
1326:                        throw new DeploymentException(
1327:                                "Cannot deploy ejb application; No ejb deployer defined: "
1328:                                        + module.getModuleURI());
1329:                    }
1330:                    return getEjbConfigBuilder();
1331:                } else if (module instanceof  WebModule) {
1332:                    if (getWebConfigBuilder() == null) {
1333:                        throw new DeploymentException(
1334:                                "Cannot deploy web application; No war deployer defined: "
1335:                                        + module.getModuleURI());
1336:                    }
1337:                    return getWebConfigBuilder();
1338:                } else if (module instanceof  ConnectorModule) {
1339:                    if (getConnectorConfigBuilder() == null) {
1340:                        throw new DeploymentException(
1341:                                "Cannot deploy resource adapter; No rar deployer defined: "
1342:                                        + module.getModuleURI());
1343:                    }
1344:                    return getConnectorConfigBuilder();
1345:                } else if (module instanceof  AppClientModule) {
1346:                    if (getAppClientConfigBuilder() == null) {
1347:                        throw new DeploymentException(
1348:                                "Cannot deploy app client; No app client deployer defined: "
1349:                                        + module.getModuleURI());
1350:                    }
1351:                    return getAppClientConfigBuilder();
1352:                }
1353:                throw new IllegalArgumentException("Unknown module type: "
1354:                        + module.getClass().getName());
1355:            }
1356:
1357:            public static final GBeanInfo GBEAN_INFO;
1358:
1359:            static {
1360:                GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
1361:                        EARConfigBuilder.class, NameFactory.CONFIG_BUILDER);
1362:                infoBuilder.addAttribute("defaultEnvironment",
1363:                        Environment.class, true, true);
1364:                infoBuilder.addAttribute("transactionManagerAbstractName",
1365:                        AbstractNameQuery.class, true);
1366:                infoBuilder.addAttribute("connectionTrackerAbstractName",
1367:                        AbstractNameQuery.class, true);
1368:                infoBuilder.addAttribute("transactionalTimerAbstractName",
1369:                        AbstractNameQuery.class, true);
1370:                infoBuilder.addAttribute("nonTransactionalTimerAbstractName",
1371:                        AbstractNameQuery.class, true);
1372:                infoBuilder.addAttribute("corbaGBeanAbstractName",
1373:                        AbstractNameQuery.class, true);
1374:                infoBuilder.addAttribute("serverName", AbstractNameQuery.class,
1375:                        true);
1376:
1377:                infoBuilder.addReference("Repositories", Repository.class,
1378:                        "Repository");
1379:                infoBuilder.addReference("EJBConfigBuilder",
1380:                        ModuleBuilder.class, NameFactory.MODULE_BUILDER);
1381:                infoBuilder.addReference("WebConfigBuilder",
1382:                        ModuleBuilder.class, NameFactory.MODULE_BUILDER);
1383:                infoBuilder.addReference("ConnectorConfigBuilder",
1384:                        ModuleBuilder.class, NameFactory.MODULE_BUILDER);
1385:                infoBuilder.addReference("ActivationSpecInfoLocator",
1386:                        ActivationSpecInfoLocator.class,
1387:                        NameFactory.MODULE_BUILDER);
1388:                infoBuilder.addReference("AppClientConfigBuilder",
1389:                        ModuleBuilder.class, NameFactory.MODULE_BUILDER);
1390:                infoBuilder.addReference("SecurityBuilders",
1391:                        NamespaceDrivenBuilder.class,
1392:                        NameFactory.MODULE_BUILDER);
1393:                infoBuilder.addReference("ServiceBuilders",
1394:                        NamespaceDrivenBuilder.class,
1395:                        NameFactory.MODULE_BUILDER);
1396:                infoBuilder.addReference("PersistenceUnitBuilders",
1397:                        ModuleBuilderExtension.class,
1398:                        NameFactory.MODULE_BUILDER);
1399:                infoBuilder.addReference("ArtifactResolvers",
1400:                        ArtifactResolver.class, "ArtifactResolver");
1401:
1402:                infoBuilder.addAttribute("kernel", Kernel.class, false);
1403:
1404:                infoBuilder.setConstructor(new String[] { "defaultEnvironment",
1405:                        "transactionManagerAbstractName",
1406:                        "connectionTrackerAbstractName",
1407:                        "transactionalTimerAbstractName",
1408:                        "nonTransactionalTimerAbstractName",
1409:                        "corbaGBeanAbstractName", "serverName", "Repositories",
1410:                        "EJBConfigBuilder", "WebConfigBuilder",
1411:                        "ConnectorConfigBuilder", "ActivationSpecInfoLocator",
1412:                        "AppClientConfigBuilder", "SecurityBuilders",
1413:                        "ServiceBuilders", "PersistenceUnitBuilders",
1414:                        "ArtifactResolvers", "kernel" });
1415:
1416:                GBEAN_INFO = infoBuilder.getBeanInfo();
1417:            }
1418:
1419:            public static GBeanInfo getGBeanInfo() {
1420:                return GBEAN_INFO;
1421:            }
1422:
1423:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.