Source Code Cross Referenced for EjbModuleBuilder.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » openejb » 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.openejb.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.openejb.deployment;
0017:
0018:        import java.io.File;
0019:        import java.io.IOException;
0020:        import java.net.URI;
0021:        import java.net.URL;
0022:        import java.util.Collection;
0023:        import java.util.Collections;
0024:        import java.util.HashMap;
0025:        import java.util.Iterator;
0026:        import java.util.LinkedHashSet;
0027:        import java.util.LinkedList;
0028:        import java.util.Map;
0029:        import java.util.Properties;
0030:        import java.util.Set;
0031:        import java.util.TreeMap;
0032:        import java.util.TreeSet;
0033:        import java.util.jar.JarFile;
0034:
0035:        import javax.ejb.EntityContext;
0036:        import javax.ejb.MessageDrivenContext;
0037:        import javax.ejb.SessionContext;
0038:        import javax.ejb.TimerService;
0039:        import javax.xml.namespace.QName;
0040:
0041:        import org.apache.commons.logging.Log;
0042:        import org.apache.commons.logging.LogFactory;
0043:        import org.apache.geronimo.common.DeploymentException;
0044:        import org.apache.geronimo.connector.ResourceAdapterWrapperGBean;
0045:        import org.apache.geronimo.deployment.ClassPathList;
0046:        import org.apache.geronimo.deployment.ModuleIDBuilder;
0047:        import org.apache.geronimo.deployment.ModuleList;
0048:        import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
0049:        import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection;
0050:        import org.apache.geronimo.deployment.service.EnvironmentBuilder;
0051:        import org.apache.geronimo.deployment.service.GBeanBuilder;
0052:        import org.apache.geronimo.deployment.util.DeploymentUtil;
0053:        import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
0054:        import org.apache.geronimo.gbean.AbstractName;
0055:        import org.apache.geronimo.gbean.AbstractNameQuery;
0056:        import org.apache.geronimo.gbean.GBeanData;
0057:        import org.apache.geronimo.gbean.GBeanInfo;
0058:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
0059:        import org.apache.geronimo.gbean.ReferencePatterns;
0060:        import org.apache.geronimo.gbean.GBeanLifecycle;
0061:        import org.apache.geronimo.j2ee.deployment.EARContext;
0062:        import org.apache.geronimo.j2ee.deployment.Module;
0063:        import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
0064:        import org.apache.geronimo.j2ee.deployment.ModuleBuilderExtension;
0065:        import org.apache.geronimo.j2ee.deployment.NamingBuilder;
0066:        import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedEjbJar;
0067:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
0068:        import org.apache.geronimo.kernel.GBeanNotFoundException;
0069:        import org.apache.geronimo.kernel.Naming;
0070:        import org.apache.geronimo.kernel.classloader.TemporaryClassLoader;
0071:        import org.apache.geronimo.kernel.config.Configuration;
0072:        import org.apache.geronimo.kernel.config.ConfigurationModuleType;
0073:        import org.apache.geronimo.kernel.config.ConfigurationStore;
0074:        import org.apache.geronimo.kernel.repository.Artifact;
0075:        import org.apache.geronimo.kernel.repository.Environment;
0076:        import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
0077:        import org.apache.geronimo.openejb.EjbContainer;
0078:        import org.apache.geronimo.openejb.EjbDeployment;
0079:        import org.apache.geronimo.openejb.EjbModuleImplGBean;
0080:        import org.apache.geronimo.openejb.OpenEjbSystem;
0081:        import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbGeronimoEjbJarType;
0082:        import org.apache.geronimo.security.jacc.ComponentPermissions;
0083:        import org.apache.geronimo.xbeans.geronimo.j2ee.GerSecurityDocument;
0084:        import org.apache.geronimo.xbeans.javaee.EjbJarType;
0085:        import org.apache.geronimo.persistence.PersistenceUnitGBean;
0086:        import org.apache.openejb.OpenEJBException;
0087:        import org.apache.openejb.util.LinkResolver;
0088:        import org.apache.openejb.assembler.classic.AppInfo;
0089:        import org.apache.openejb.assembler.classic.CmpJarBuilder;
0090:        import org.apache.openejb.assembler.classic.ContainerInfo;
0091:        import org.apache.openejb.assembler.classic.ContainerSystemInfo;
0092:        import org.apache.openejb.assembler.classic.EjbJarInfo;
0093:        import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
0094:        import org.apache.openejb.assembler.classic.FacilitiesInfo;
0095:        import org.apache.openejb.assembler.classic.MdbContainerInfo;
0096:        import org.apache.openejb.assembler.classic.MessageDrivenBeanInfo;
0097:        import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
0098:        import org.apache.openejb.assembler.classic.StatefulBeanInfo;
0099:        import org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo;
0100:        import org.apache.openejb.util.UniqueDefaultLinkResolver;
0101:        import org.apache.openejb.config.AppModule;
0102:        import org.apache.openejb.config.ConfigurationFactory;
0103:        import org.apache.openejb.config.DeploymentLoader;
0104:        import org.apache.openejb.config.ReadDescriptors;
0105:        import org.apache.openejb.config.UnknownModuleTypeException;
0106:        import org.apache.openejb.config.UnsupportedModuleTypeException;
0107:        import org.apache.openejb.config.ValidationError;
0108:        import org.apache.openejb.config.ValidationFailedException;
0109:        import org.apache.openejb.config.ValidationFailure;
0110:        import org.apache.openejb.config.ConfigurationFactory.Chain;
0111:        import org.apache.openejb.jee.EjbJar;
0112:        import org.apache.openejb.jee.EjbRef;
0113:        import org.apache.openejb.jee.EnterpriseBean;
0114:        import org.apache.openejb.jee.MessageDestinationRef;
0115:        import org.apache.openejb.jee.PersistenceContextRef;
0116:        import org.apache.openejb.jee.PersistenceUnitRef;
0117:        import org.apache.openejb.jee.ResourceEnvRef;
0118:        import org.apache.openejb.jee.ResourceRef;
0119:        import org.apache.openejb.jee.ServiceRef;
0120:        import org.apache.openejb.jee.jpa.unit.Persistence;
0121:        import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
0122:        import org.apache.openejb.jee.jpa.unit.TransactionType;
0123:        import org.apache.openejb.jee.oejb2.EjbRefType;
0124:        import org.apache.openejb.jee.oejb2.GeronimoEjbJarType;
0125:        import org.apache.openejb.jee.oejb2.MessageDrivenBeanType;
0126:        import org.apache.openejb.jee.oejb2.OpenejbJarType;
0127:        import org.apache.openejb.jee.oejb2.PatternType;
0128:        import org.apache.openejb.jee.oejb2.ResourceLocatorType;
0129:        import org.apache.openejb.loader.SystemInstance;
0130:        import org.apache.xmlbeans.XmlCursor;
0131:        import org.apache.xmlbeans.XmlObject;
0132:
0133:        /**
0134:         * Master builder for processing EJB JAR deployments and creating the
0135:         * correspinding runtime objects (GBeans, etc.).
0136:         *
0137:         * @version $Revision: 479481 $ $Date: 2006-11-26 16:52:20 -0800 (Sun, 26 Nov 2006) $
0138:         */
0139:        public class EjbModuleBuilder implements  ModuleBuilder, GBeanLifecycle {
0140:            private static final Log log = LogFactory
0141:                    .getLog(EjbModuleBuilder.class);
0142:
0143:            private static final String OPENEJBJAR_NAMESPACE = XmlUtil.OPENEJBJAR_QNAME
0144:                    .getNamespaceURI();
0145:            private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String, String>();
0146:            static {
0147:                NAMESPACE_UPDATES.put(
0148:                        "http://www.openejb.org/xml/ns/openejb-jar",
0149:                        "http://openejb.apache.org/xml/ns/openejb-jar-2.3");
0150:                NAMESPACE_UPDATES.put(
0151:                        "http://www.openejb.org/xml/ns/openejb-jar-2.1",
0152:                        "http://openejb.apache.org/xml/ns/openejb-jar-2.3");
0153:                NAMESPACE_UPDATES.put(
0154:                        "http://www.openejb.org/xml/ns/openejb-jar-2.2",
0155:                        "http://openejb.apache.org/xml/ns/openejb-jar-2.3");
0156:                NAMESPACE_UPDATES.put(
0157:                        "http://www.openejb.org/xml/ns/openejb-jar-2.3",
0158:                        "http://openejb.apache.org/xml/ns/openejb-jar-2.3");
0159:                NAMESPACE_UPDATES.put("http://www.openejb.org/xml/ns/pkgen",
0160:                        "http://openejb.apache.org/xml/ns/pkgen-2.1");
0161:                NAMESPACE_UPDATES.put(
0162:                        "http://www.openejb.org/xml/ns/pkgen-2.0",
0163:                        "http://openejb.apache.org/xml/ns/pkgen-2.1");
0164:            }
0165:
0166:            private final Environment defaultEnvironment;
0167:            private final String defaultCmpJTADataSource;
0168:            private final String defaultCmpNonJTADataSource;
0169:            private final NamespaceDrivenBuilderCollection securityBuilders;
0170:            private final NamespaceDrivenBuilderCollection serviceBuilders;
0171:            private final NamingBuilder namingBuilder;
0172:            private final ResourceEnvironmentSetter resourceEnvironmentSetter;
0173:            private final Collection<ModuleBuilderExtension> moduleBuilderExtensions;
0174:
0175:            public EjbModuleBuilder(Environment defaultEnvironment,
0176:                    String defaultCmpJTADataSource,
0177:                    String defaultCmpNonJTADataSource,
0178:                    Collection<ModuleBuilderExtension> moduleBuilderExtensions,
0179:                    Collection securityBuilders, Collection serviceBuilders,
0180:                    NamingBuilder namingBuilders,
0181:                    ResourceEnvironmentSetter resourceEnvironmentSetter) {
0182:                this .defaultEnvironment = defaultEnvironment;
0183:                this .defaultCmpJTADataSource = defaultCmpJTADataSource;
0184:                this .defaultCmpNonJTADataSource = defaultCmpNonJTADataSource;
0185:                this .securityBuilders = new NamespaceDrivenBuilderCollection(
0186:                        securityBuilders, GerSecurityDocument.type
0187:                                .getDocumentElementName());
0188:                this .serviceBuilders = new NamespaceDrivenBuilderCollection(
0189:                        serviceBuilders, GBeanBuilder.SERVICE_QNAME);
0190:                this .namingBuilder = namingBuilders;
0191:                this .resourceEnvironmentSetter = resourceEnvironmentSetter;
0192:
0193:                if (moduleBuilderExtensions == null) {
0194:                    moduleBuilderExtensions = Collections.emptyList();
0195:                }
0196:                this .moduleBuilderExtensions = moduleBuilderExtensions;
0197:
0198:                //duplicate of stuff in OpenEjbSystemGBean, may not be essential
0199:                System.setProperty("duct tape", "");
0200:                System.setProperty("admin.disabled", "true");
0201:                System.setProperty("openejb.logger.external", "true");
0202:
0203:                setDefaultProperty("openejb.deploymentId.format",
0204:                        "{moduleId}/{ejbName}");
0205:                setDefaultProperty("openejb.jndiname.strategy.class",
0206:                        "org.apache.openejb.assembler.classic.JndiBuilder$TemplatedStrategy");
0207:                setDefaultProperty("openejb.jndiname.format",
0208:                        "{ejbName}{interfaceType.annotationName}");
0209:                setDefaultProperty("openejb.jndiname.failoncollision", "false");
0210:
0211:                System.setProperty("openejb.naming", "xbean");
0212:
0213:            }
0214:
0215:            public void doStart() throws Exception {
0216:                XmlBeansUtil.registerNamespaceUpdates(NAMESPACE_UPDATES);
0217:            }
0218:
0219:            public void doStop() {
0220:                XmlBeansUtil.unregisterNamespaceUpdates(NAMESPACE_UPDATES);
0221:            }
0222:
0223:            public void doFail() {
0224:                doStop();
0225:            }
0226:
0227:            private void setDefaultProperty(String key, String value) {
0228:                SystemInstance systemInstance = SystemInstance.get();
0229:                String format = systemInstance.getProperty(key);
0230:                if (format == null) {
0231:                    systemInstance.setProperty(key, value);
0232:                }
0233:            }
0234:
0235:            public String getSchemaNamespace() {
0236:                return EjbModuleBuilder.OPENEJBJAR_NAMESPACE;
0237:            }
0238:
0239:            public Module createModule(File plan, JarFile moduleFile,
0240:                    Naming naming, ModuleIDBuilder idBuilder)
0241:                    throws DeploymentException {
0242:                return createModule(plan, moduleFile, "ejb.jar", null, null,
0243:                        null, naming, idBuilder);
0244:            }
0245:
0246:            public Module createModule(Object plan, JarFile moduleFile,
0247:                    String targetPath, URL specDDUrl, Environment environment,
0248:                    Object moduleContextInfo, AbstractName earName,
0249:                    Naming naming, ModuleIDBuilder idBuilder)
0250:                    throws DeploymentException {
0251:                return createModule(plan, moduleFile, targetPath, specDDUrl,
0252:                        environment, earName, naming, idBuilder);
0253:            }
0254:
0255:            private Module createModule(Object plan, JarFile moduleFile,
0256:                    String targetPath, URL specDDUrl,
0257:                    Environment earEnvironment, AbstractName earName,
0258:                    Naming naming, ModuleIDBuilder idBuilder)
0259:                    throws DeploymentException {
0260:                if (moduleFile == null)
0261:                    throw new NullPointerException("moduleFile is null");
0262:                if (targetPath == null)
0263:                    throw new NullPointerException("targetPath is null");
0264:                if (targetPath.endsWith("/"))
0265:                    throw new IllegalArgumentException(
0266:                            "targetPath must not end with a '/'");
0267:
0268:                // Load the module file
0269:                DeploymentLoader loader = new DeploymentLoader();
0270:                AppModule appModule;
0271:                try {
0272:                    appModule = loader.load(new File(moduleFile.getName()));
0273:                } catch (UnknownModuleTypeException e) {
0274:                    return null;
0275:                } catch (UnsupportedModuleTypeException e) {
0276:                    return null;
0277:                } catch (OpenEJBException e) {
0278:                    Throwable t = e.getCause();
0279:                    if (t instanceof  UnknownModuleTypeException
0280:                            || t instanceof  UnsupportedModuleTypeException) {
0281:                        return null;
0282:                    }
0283:                    throw new DeploymentException(e);
0284:                }
0285:
0286:                // did we find a ejb jar?
0287:                if (appModule.getEjbModules().size() == 0) {
0288:                    return null;
0289:                }
0290:
0291:                // get the module
0292:                org.apache.openejb.config.EjbModule ejbModule = appModule
0293:                        .getEjbModules().get(0);
0294:
0295:                // add the ejb-jar.xml altDD plan
0296:                if (specDDUrl != null) {
0297:                    ejbModule.setEjbJar(null);
0298:                    ejbModule.getAltDDs().put("ejb-jar.xml", specDDUrl);
0299:                }
0300:
0301:                // convert the vendor plan object to the ejbModule altDD map
0302:                XmlObject unknownXmlObject = null;
0303:                if (plan instanceof  XmlObject) {
0304:                    unknownXmlObject = (XmlObject) plan;
0305:                } else if (plan != null) {
0306:                    try {
0307:                        unknownXmlObject = XmlBeansUtil.parse(((File) plan)
0308:                                .toURL(), XmlUtil.class.getClassLoader());
0309:                    } catch (Exception e) {
0310:                        throw new DeploymentException(e);
0311:                    }
0312:                }
0313:
0314:                if (unknownXmlObject != null) {
0315:                    XmlCursor xmlCursor = unknownXmlObject.newCursor();
0316:                    //
0317:                    QName qname = xmlCursor.getName();
0318:                    if (qname == null) {
0319:                        xmlCursor.toFirstChild();
0320:                        qname = xmlCursor.getName();
0321:                    }
0322:                    if (qname.getLocalPart().equals("openejb-jar")) {
0323:                        ejbModule.getAltDDs().put("openejb-jar.xml",
0324:                                xmlCursor.xmlText());
0325:                    } else if (qname.getLocalPart().equals("ejb-jar")
0326:                            && qname
0327:                                    .getNamespaceURI()
0328:                                    .equals(
0329:                                            "http://geronimo.apache.org/xml/ns/j2ee/ejb/openejb-2.0")) {
0330:                        ejbModule.getAltDDs().put("geronimo-openejb.xml",
0331:                                xmlCursor.xmlText());
0332:                    }
0333:                }
0334:
0335:                // Read in the deploument desiptor files
0336:                ReadDescriptors readDescriptors = new ReadDescriptors();
0337:                try {
0338:                    readDescriptors.deploy(appModule);
0339:                } catch (OpenEJBException e) {
0340:                    throw new DeploymentException(
0341:                            "Failed parsing descriptors for module: "
0342:                                    + moduleFile.getName(), e);
0343:                }
0344:
0345:                // Get the geronimo-openejb.xml tree
0346:                boolean standAlone = earEnvironment == null;
0347:                GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule
0348:                        .getAltDDs().get("geronimo-openejb.xml");
0349:                if (geronimoEjbJarType == null) {
0350:                    // create default plan
0351:                    String path = (standAlone) ? new File(moduleFile.getName())
0352:                            .getName() : targetPath;
0353:                    geronimoEjbJarType = XmlUtil.createDefaultPlan(path,
0354:                            ejbModule.getEjbJar());
0355:                    ejbModule.getAltDDs().put("geronimo-openejb.xml",
0356:                            geronimoEjbJarType);
0357:                }
0358:
0359:                // create the geronimo environment object
0360:                Environment environment = XmlUtil
0361:                        .buildEnvironment(geronimoEjbJarType.getEnvironment(),
0362:                                defaultEnvironment);
0363:                if (earEnvironment != null) {
0364:                    EnvironmentBuilder.mergeEnvironments(earEnvironment,
0365:                            environment);
0366:                    environment = earEnvironment;
0367:                    if (!environment.getConfigId().isResolved()) {
0368:                        throw new IllegalStateException(
0369:                                "EJB module ID should be fully resolved (not "
0370:                                        + environment.getConfigId() + ")");
0371:                    }
0372:                } else {
0373:                    idBuilder.resolve(environment, new File(moduleFile
0374:                            .getName()).getName(), "jar");
0375:                }
0376:
0377:                AbstractName moduleName;
0378:                if (earName == null) {
0379:                    earName = naming.createRootName(environment.getConfigId(),
0380:                            NameFactory.NULL, NameFactory.J2EE_APPLICATION);
0381:                    moduleName = naming.createChildName(earName, environment
0382:                            .getConfigId().toString(), NameFactory.EJB_MODULE);
0383:                    ejbModule.setModuleId(environment.getConfigId()
0384:                            .getArtifactId());
0385:                } else {
0386:                    moduleName = naming.createChildName(earName, targetPath,
0387:                            NameFactory.EJB_MODULE);
0388:                    ejbModule.setModuleId(targetPath);
0389:                }
0390:
0391:                // Create XMLBeans version of EjbJarType for the AnnotatedApp interface
0392:                EjbJar ejbJar = ejbModule.getEjbJar();
0393:                EjbJarType ejbJarType = XmlUtil.convertToXmlbeans(ejbJar);
0394:                AnnotatedEjbJar annotatedEjbJar = new AnnotatedEjbJar(
0395:                        ejbJarType);
0396:
0397:                EjbModule module = new EjbModule(ejbModule, standAlone,
0398:                        moduleName, environment, moduleFile, targetPath, "",
0399:                        annotatedEjbJar);
0400:
0401:                for (ModuleBuilderExtension builder : moduleBuilderExtensions) {
0402:                    try {
0403:                        builder.createModule(module, plan, moduleFile,
0404:                                targetPath, specDDUrl, environment, null,
0405:                                earName, naming, idBuilder);
0406:                    } catch (Throwable t) {
0407:                        String builderName = builder.getClass().getSimpleName();
0408:                        log.error(builderName + ".createModule() failed: "
0409:                                + t.getMessage(), t);
0410:
0411:                    }
0412:                }
0413:                return module;
0414:            }
0415:
0416:            protected static void unmapReferences(EjbJar ejbJar,
0417:                    GeronimoEjbJarType geronimoEjbJarType) {
0418:                Set<String> corbaEjbRefs = new TreeSet<String>();
0419:                for (EjbRefType ejbRef : geronimoEjbJarType.getEjbRef()) {
0420:                    if (ejbRef.getNsCorbaloc() != null) {
0421:                        corbaEjbRefs.add(ejbRef.getRefName());
0422:                    }
0423:                }
0424:
0425:                for (EnterpriseBean enterpriseBean : ejbJar
0426:                        .getEnterpriseBeans()) {
0427:                    enterpriseBean.getEnvEntry().clear();
0428:                    enterpriseBean.getEjbLocalRef().clear();
0429:
0430:                    for (Iterator<EjbRef> iterator = enterpriseBean.getEjbRef()
0431:                            .iterator(); iterator.hasNext();) {
0432:                        EjbRef ref = iterator.next();
0433:                        if (!corbaEjbRefs.contains(ref.getEjbRefName())) {
0434:                            // remove all non corba refs to avoid overwriting normal ejb refs
0435:                            iterator.remove();
0436:                        } else {
0437:                            // clear mapped named data from corba refs
0438:                            ref.setMappedName(null);
0439:                            ref.getInjectionTarget().clear();
0440:                        }
0441:                    }
0442:
0443:                    for (MessageDestinationRef ref : enterpriseBean
0444:                            .getMessageDestinationRef()) {
0445:                        ref.setMappedName(null);
0446:                        ref.getInjectionTarget().clear();
0447:                    }
0448:                    for (PersistenceContextRef ref : enterpriseBean
0449:                            .getPersistenceContextRef()) {
0450:                        ref.setMappedName(null);
0451:                        ref.getInjectionTarget().clear();
0452:                    }
0453:                    for (PersistenceUnitRef ref : enterpriseBean
0454:                            .getPersistenceUnitRef()) {
0455:                        ref.setMappedName(null);
0456:                        ref.getInjectionTarget().clear();
0457:                    }
0458:                    for (ResourceRef ref : enterpriseBean.getResourceRef()) {
0459:                        ref.setMappedName(null);
0460:                        ref.getInjectionTarget().clear();
0461:                    }
0462:                    for (Iterator<ResourceEnvRef> iterator = enterpriseBean
0463:                            .getResourceEnvRef().iterator(); iterator.hasNext();) {
0464:                        ResourceEnvRef ref = iterator.next();
0465:                        if (ref.getType()
0466:                                .equals(SessionContext.class.getName())) {
0467:                            iterator.remove();
0468:                        } else if (ref.getType().equals(
0469:                                EntityContext.class.getName())) {
0470:                            iterator.remove();
0471:                        } else if (ref.getType().equals(
0472:                                MessageDrivenContext.class.getName())) {
0473:                            iterator.remove();
0474:                        } else if (ref.getType().equals(
0475:                                TimerService.class.getName())) {
0476:                            iterator.remove();
0477:                        } else {
0478:                            ref.setMappedName(null);
0479:                        }
0480:                        ref.getInjectionTarget().clear();
0481:
0482:                    }
0483:                    for (ServiceRef ref : enterpriseBean.getServiceRef()) {
0484:                        ref.setMappedName(null);
0485:                        ref.getInjectionTarget().clear();
0486:                    }
0487:                }
0488:            }
0489:
0490:            public void installModule(JarFile earFile, EARContext earContext,
0491:                    Module module, Collection configurationStores,
0492:                    ConfigurationStore targetConfigurationStore,
0493:                    Collection repository) throws DeploymentException {
0494:                installModule(module, earContext);
0495:                EARContext moduleContext;
0496:                if (module.isStandAlone()) {
0497:                    moduleContext = earContext;
0498:                } else {
0499:                    Environment environment = earContext.getConfiguration()
0500:                            .getEnvironment();
0501:                    File configurationDir = new File(earContext.getBaseDir(),
0502:                            module.getTargetPath());
0503:                    //            configurationDir.mkdirs();
0504:
0505:                    // construct the ejb app deployment context... this is the same class used by the ear context
0506:                    try {
0507:                        File inPlaceConfigurationDir = null;
0508:                        if (null != earContext.getInPlaceConfigurationDir()) {
0509:                            inPlaceConfigurationDir = new File(earContext
0510:                                    .getInPlaceConfigurationDir(), module
0511:                                    .getTargetPath());
0512:                        }
0513:                        moduleContext = new EARContext(configurationDir,
0514:                                inPlaceConfigurationDir, environment,
0515:                                ConfigurationModuleType.EJB, module
0516:                                        .getModuleName(), earContext);
0517:                    } catch (DeploymentException e) {
0518:                        cleanupConfigurationDir(configurationDir);
0519:                        throw e;
0520:                    }
0521:                }
0522:                module.setEarContext(moduleContext);
0523:                module.setRootEarContext(earContext);
0524:                if (((EjbModule) module).getEjbJar().getAssemblyDescriptor() != null) {
0525:                    namingBuilder.buildEnvironment(null, null, module
0526:                            .getEnvironment());
0527:                }
0528:                for (ModuleBuilderExtension builder : moduleBuilderExtensions) {
0529:                    try {
0530:                        builder.installModule(earFile, earContext, module,
0531:                                configurationStores, targetConfigurationStore,
0532:                                repository);
0533:                    } catch (Throwable t) {
0534:                        String builderName = builder.getClass().getSimpleName();
0535:                        log.error(builderName + ".installModule() failed: "
0536:                                + t.getMessage(), t);
0537:                    }
0538:                }
0539:            }
0540:
0541:            private void installModule(Module module, EARContext earContext)
0542:                    throws DeploymentException {
0543:                EarData earData = (EarData) earContext.getGeneralData().get(
0544:                        EarData.class);
0545:                if (earData == null) {
0546:                    earData = new EarData();
0547:                    earContext.getGeneralData().put(EarData.class, earData);
0548:                }
0549:                earData.addEjbModule((EjbModule) module);
0550:
0551:                JarFile moduleFile = module.getModuleFile();
0552:                try {
0553:                    // extract the ejbJar file into a standalone packed jar file and add the contents to the output
0554:                    earContext.addIncludeAsPackedJar(URI.create(module
0555:                            .getTargetPath()), moduleFile);
0556:                } catch (IOException e) {
0557:                    throw new DeploymentException(
0558:                            "Unable to copy ejb module jar into configuration: "
0559:                                    + moduleFile.getName(), e);
0560:                }
0561:            }
0562:
0563:            private static final String LINE_SEP = System
0564:                    .getProperty("line.separator");
0565:
0566:            private boolean cleanupConfigurationDir(File configurationDir) {
0567:                LinkedList<String> cannotBeDeletedList = new LinkedList<String>();
0568:
0569:                if (!DeploymentUtil.recursiveDelete(configurationDir,
0570:                        cannotBeDeletedList)) {
0571:                    // Output a message to help user track down file problem
0572:                    log
0573:                            .warn("Unable to delete "
0574:                                    + cannotBeDeletedList.size()
0575:                                    + " files while recursively deleting directory "
0576:                                    + configurationDir.getAbsolutePath()
0577:                                    + LINE_SEP
0578:                                    + "The first file that could not be deleted was:"
0579:                                    + LINE_SEP
0580:                                    + "  "
0581:                                    + (!cannotBeDeletedList.isEmpty() ? cannotBeDeletedList
0582:                                            .getFirst()
0583:                                            : ""));
0584:                    return false;
0585:                }
0586:                return true;
0587:            }
0588:
0589:            public void initContext(EARContext earContext, Module module,
0590:                    ClassLoader classLoader) throws DeploymentException {
0591:                EjbModule ejbModule = (EjbModule) module;
0592:
0593:                EjbJarInfo ejbJarInfo = getEjbJarInfo(earContext, ejbModule,
0594:                        classLoader);
0595:
0596:                ejbModule.setEjbJarInfo(ejbJarInfo);
0597:
0598:                // update the original spec dd with the metadata complete dd
0599:                EjbJar ejbJar = ejbModule.getEjbJar();
0600:                ejbModule.setOriginalSpecDD(XmlUtil.marshal(ejbModule
0601:                        .getEjbJar()));
0602:
0603:                // Get the geronimo-openejb plan
0604:                GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule
0605:                        .getEjbModule().getAltDDs().get("geronimo-openejb.xml");
0606:
0607:                // We must set all mapped name references back to null or Geronimo will blow up
0608:                unmapReferences(ejbJar, geronimoEjbJarType);
0609:
0610:                // create a xmlbeans version of the ejb-jar.xml file, because the jndi code is coupled based on xmlbeans objects
0611:                EjbJarType ejbJarType = XmlUtil.convertToXmlbeans(ejbJar);
0612:                ejbModule.setSpecDD(ejbJarType);
0613:
0614:                // convert the plan to xmlbeans since geronimo naming is coupled on xmlbeans objects
0615:                OpenejbGeronimoEjbJarType geronimoOpenejb = XmlUtil
0616:                        .convertToXmlbeans(geronimoEjbJarType);
0617:                ejbModule.setVendorDD(geronimoOpenejb);
0618:
0619:                // todo move namingBuilders.buildEnvironment() here when geronimo naming supports it
0620:
0621:                // initialize the naming builders
0622:                if (ejbJarType.getAssemblyDescriptor() != null) {
0623:                    namingBuilder.initContext(ejbJarType
0624:                            .getAssemblyDescriptor(), geronimoOpenejb,
0625:                            ejbModule);
0626:                }
0627:
0628:                EjbDeploymentBuilder ejbDeploymentBuilder = new EjbDeploymentBuilder(
0629:                        earContext, ejbModule, namingBuilder,
0630:                        resourceEnvironmentSetter);
0631:                ejbModule.setEjbBuilder(ejbDeploymentBuilder);
0632:                ejbDeploymentBuilder.initContext();
0633:
0634:                // Build the security configuration.
0635:                securityBuilders.build(geronimoOpenejb, earContext, ejbModule
0636:                        .isStandAlone() ? ejbModule.getEarContext() : null);
0637:
0638:                // Add extra gbean declared in the geronimo-openejb.xml file
0639:                serviceBuilders.build(geronimoOpenejb, earContext, ejbModule
0640:                        .getEarContext());
0641:
0642:                ClassPathList manifestcp = new ClassPathList();
0643:                manifestcp.add(module.getTargetPath());
0644:                EARContext moduleContext = module.getEarContext();
0645:                ModuleList moduleLocations = (ModuleList) module
0646:                        .getRootEarContext().getGeneralData().get(
0647:                                ModuleList.class);
0648:                URI baseUri = URI.create(module.getTargetPath());
0649:                moduleContext.getCompleteManifestClassPath(module
0650:                        .getModuleFile(), baseUri, URI.create("."), manifestcp,
0651:                        moduleLocations);
0652:                moduleContext.getGeneralData().put(ClassPathList.class,
0653:                        manifestcp);
0654:
0655:                for (ModuleBuilderExtension builder : moduleBuilderExtensions) {
0656:                    try {
0657:                        builder.initContext(earContext, module, classLoader);
0658:                    } catch (Throwable t) {
0659:                        String builderName = builder.getClass().getSimpleName();
0660:                        log.error(builderName + ".initContext() failed: "
0661:                                + t.getMessage(), t);
0662:                    }
0663:                }
0664:            }
0665:
0666:            private EjbJarInfo getEjbJarInfo(EARContext earContext,
0667:                    EjbModule ejbModule, ClassLoader classLoader)
0668:                    throws DeploymentException {
0669:                EarData earData = (EarData) earContext.getGeneralData().get(
0670:                        EarData.class);
0671:                if (earData.getEjbJars().isEmpty()) {
0672:
0673:                    // temporary classloader is used for processing ejb annotations and byte code manipulation during ejb load
0674:                    TemporaryClassLoader temporaryClassLoader = new TemporaryClassLoader(
0675:                            new URL[0], classLoader);
0676:
0677:                    // create an openejb app module for the ear containing all ejb modules
0678:                    AppModule appModule = new AppModule(classLoader, earContext
0679:                            .getConfigID().toString());
0680:                    for (EjbModule module : earData.getEjbModuels()) {
0681:                        module.setClassLoader(temporaryClassLoader);
0682:                        appModule.getEjbModules().add(module.getEjbModule());
0683:                    }
0684:
0685:                    // build the config info tree
0686:                    // this method fills in the ejbJar jaxb tree based on the annotations
0687:                    // (metadata complete) and it run the openejb verifier
0688:                    AppInfo appInfo;
0689:                    try {
0690:                        appInfo = configureApplication(appModule, ejbModule,
0691:                                earContext.getConfiguration());
0692:                    } catch (ValidationFailedException set) {
0693:                        StringBuilder sb = new StringBuilder();
0694:                        sb.append("Jar failed validation: ").append(
0695:                                appModule.getModuleId());
0696:
0697:                        for (ValidationError e : set.getErrors()) {
0698:                            sb.append(e.getPrefix()).append(" ... ").append(
0699:                                    e.getComponentName()).append(":\t").append(
0700:                                    e.getMessage(2));
0701:                        }
0702:
0703:                        for (ValidationFailure e : set.getFailures()) {
0704:                            sb.append(e.getPrefix()).append(" ... ").append(
0705:                                    e.getComponentName()).append(":\t").append(
0706:                                    e.getMessage(2));
0707:                        }
0708:
0709:                        throw new DeploymentException(sb.toString());
0710:                    } catch (OpenEJBException e) {
0711:                        throw new DeploymentException(e);
0712:                    }
0713:
0714:                    // add all of the modules to the ear data
0715:                    for (EjbJarInfo ejbJar : appInfo.ejbJars) {
0716:                        earData.addEjbJar(ejbJar);
0717:                    }
0718:
0719:                    // add the cmp jar
0720:                    CmpJarBuilder cmp2Builder = new CmpJarBuilder(appInfo,
0721:                            classLoader);
0722:                    try {
0723:                        File generatedJar = cmp2Builder.getJarFile();
0724:                        if (generatedJar != null) {
0725:                            String generatedPath = ejbModule.getTargetPath();
0726:                            if (generatedPath.endsWith(".jar")) {
0727:                                generatedPath = generatedPath.substring(0,
0728:                                        generatedPath.length() - 4);
0729:                            }
0730:                            generatedPath += "-cmp2.jar";
0731:                            earContext.addInclude(URI.create(generatedPath),
0732:                                    generatedJar);
0733:                        }
0734:                    } catch (IOException e) {
0735:                        throw new DeploymentException(e);
0736:                    }
0737:
0738:                    // add the cmp persistence unit if needed
0739:                    if (appInfo.cmpMappingsXml != null) {
0740:                        addGeronimmoOpenEJBPersistenceUnit(ejbModule);
0741:                    }
0742:                }
0743:
0744:                // find our module
0745:                EjbJarInfo ejbJarInfo = earData.getEjbJar(ejbModule
0746:                        .getEjbModule().getModuleId());
0747:                return ejbJarInfo;
0748:            }
0749:
0750:            private AppInfo configureApplication(AppModule appModule,
0751:                    EjbModule ejbModule, Configuration configuration)
0752:                    throws OpenEJBException {
0753:                OpenEjbConfiguration openEjbConfiguration = new OpenEjbConfiguration();
0754:                openEjbConfiguration.containerSystem = new ContainerSystemInfo();
0755:                openEjbConfiguration.facilities = new FacilitiesInfo();
0756:                boolean offline = true;
0757:
0758:                ConfigurationFactory configurationFactory = new ConfigurationFactory(
0759:                        offline, ejbModule.getPreAutoConfigDeployer(),
0760:                        openEjbConfiguration);
0761:                ClassLoader oldClassLoader = Thread.currentThread()
0762:                        .getContextClassLoader();
0763:                Thread.currentThread().setContextClassLoader(
0764:                        appModule.getClassLoader());
0765:                try {
0766:                    addContainerInfos(configuration,
0767:                            openEjbConfiguration.containerSystem,
0768:                            configurationFactory);
0769:                    addResourceAdapterMDBInfos(configuration,
0770:                            openEjbConfiguration.containerSystem,
0771:                            configurationFactory);
0772:                    //process resource adapters
0773:
0774:                    return configurationFactory.configureApplication(appModule);
0775:                } finally {
0776:                    Thread.currentThread()
0777:                            .setContextClassLoader(oldClassLoader);
0778:                }
0779:            }
0780:
0781:            private void addContainerInfos(Configuration configuration,
0782:                    ContainerSystemInfo containerSystem,
0783:                    ConfigurationFactory configurationFactory)
0784:                    throws OpenEJBException {
0785:                LinkedHashSet<GBeanData> containerDatas = configuration
0786:                        .findGBeanDatas(Collections
0787:                                .singleton(new AbstractNameQuery(
0788:                                        EjbContainer.class.getName())));
0789:                for (GBeanData containerData : containerDatas) {
0790:                    Class<? extends ContainerInfo> infoClass = (Class<? extends ContainerInfo>) containerData
0791:                            .getAttribute("infoType");
0792:                    if (infoClass == null) {
0793:                        String type = (String) containerData
0794:                                .getAttribute("type");
0795:                        infoClass = EjbContainer.getInfoType(type);
0796:                    }
0797:                    String serviceId = (String) containerData
0798:                            .getAttribute("id");
0799:                    Properties declaredProperties = (Properties) containerData
0800:                            .getAttribute("properties");
0801:                    String providerId = (String) containerData
0802:                            .getAttribute("provider");
0803:                    ContainerInfo containerInfo = configurationFactory
0804:                            .configureService(infoClass, serviceId,
0805:                                    declaredProperties, providerId, "Container");
0806:                    containerSystem.containers.add(containerInfo);
0807:                }
0808:            }
0809:
0810:            private void addResourceAdapterMDBInfos(
0811:                    Configuration configuration,
0812:                    ContainerSystemInfo containerSystem,
0813:                    ConfigurationFactory configurationFactory)
0814:                    throws OpenEJBException {
0815:                LinkedHashSet<GBeanData> resourceAdapterWrappers = configuration
0816:                        .findGBeanDatas(Collections
0817:                                .singleton(new AbstractNameQuery(
0818:                                        ResourceAdapterWrapperGBean.class
0819:                                                .getName())));
0820:                for (GBeanData resourceAdapterWrapperData : resourceAdapterWrappers) {
0821:                    String resourceAdapterId = getResourceAdapterId(resourceAdapterWrapperData
0822:                            .getAbstractName());
0823:                    Map<String, String> messageListenerToActivationSpecMap = (Map<String, String>) resourceAdapterWrapperData
0824:                            .getAttribute("messageListenerToActivationSpecMap");
0825:                    if (messageListenerToActivationSpecMap == null) {
0826:                        continue;
0827:                    }
0828:                    for (Map.Entry<String, String> entry : messageListenerToActivationSpecMap
0829:                            .entrySet()) {
0830:                        String messageListenerInterface = entry.getKey();
0831:                        String activationSpecClass = entry.getValue();
0832:
0833:                        // only process RA if not previously processed
0834:                        String containerName = resourceAdapterId + "-"
0835:                                + messageListenerInterface;
0836:                        // get default mdb config
0837:                        ContainerInfo containerInfo = configurationFactory
0838:                                .configureService(MdbContainerInfo.class);
0839:                        containerInfo.id = containerName;
0840:                        containerInfo.displayName = containerName;
0841:
0842:                        // set ra specific properties
0843:
0844:                        try {
0845:                            containerInfo.properties
0846:                                    .put(
0847:                                            "MessageListenerInterface",
0848:                                            configuration
0849:                                                    .getConfigurationClassLoader()
0850:                                                    .loadClass(
0851:                                                            messageListenerInterface));
0852:                        } catch (ClassNotFoundException e) {
0853:                            throw new OpenEJBException(
0854:                                    "Could not load MessageListenerInterface "
0855:                                            + messageListenerInterface
0856:                                            + " in classloader: "
0857:                                            + configuration
0858:                                                    .getConfigurationClassLoader(),
0859:                                    e);
0860:                        }
0861:                        try {
0862:                            containerInfo.properties.put("ActivationSpecClass",
0863:                                    configuration.getConfigurationClassLoader()
0864:                                            .loadClass(activationSpecClass));
0865:                        } catch (ClassNotFoundException e) {
0866:                            throw new OpenEJBException(
0867:                                    "Could not load ActivationSpecClass "
0868:                                            + activationSpecClass
0869:                                            + " in classloader: "
0870:                                            + configuration
0871:                                                    .getConfigurationClassLoader(),
0872:                                    e);
0873:                        }
0874:                        //TODO is this necessary????
0875:                        //                containerInfo.properties.put("ResourceAdapter", resourceAdapter);
0876:
0877:                        containerSystem.containers.add(containerInfo);
0878:                    }
0879:                }
0880:            }
0881:
0882:            private void addGeronimmoOpenEJBPersistenceUnit(EjbModule ejbModule) {
0883:                GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule
0884:                        .getEjbModule().getAltDDs().get("geronimo-openejb.xml");
0885:
0886:                // search for the cmp persistence unit
0887:                PersistenceUnit persistenceUnit = null;
0888:                for (Persistence persistence : geronimoEjbJarType
0889:                        .getPersistence()) {
0890:                    for (PersistenceUnit unit : persistence
0891:                            .getPersistenceUnit()) {
0892:                        if ("cmp".equals(unit.getName())) {
0893:                            persistenceUnit = unit;
0894:                            break;
0895:                        }
0896:                    }
0897:                }
0898:
0899:                // if not found create one
0900:                if (persistenceUnit == null) {
0901:                    String jtaDataSource = null;
0902:                    // todo Persistence Unit Data Sources need to be global JNDI names
0903:                    Object altDD = ejbModule.getEjbModule().getAltDDs().get(
0904:                            "openejb-jar.xml");
0905:                    if (altDD instanceof  OpenejbJarType) {
0906:                        ResourceLocatorType cmpConnectionFactory = ((OpenejbJarType) altDD)
0907:                                .getCmpConnectionFactory();
0908:                        if (cmpConnectionFactory != null) {
0909:                            String datasourceName = cmpConnectionFactory
0910:                                    .getResourceLink();
0911:                            if (datasourceName != null) {
0912:                                jtaDataSource = datasourceName.trim();
0913:                            }
0914:                        }
0915:                    }
0916:
0917:                    persistenceUnit = new PersistenceUnit();
0918:                    persistenceUnit.setName("cmp");
0919:                    persistenceUnit.setTransactionType(TransactionType.JTA);
0920:                    if (jtaDataSource != null) {
0921:                        persistenceUnit.setJtaDataSource(jtaDataSource);
0922:                    } else {
0923:                        persistenceUnit
0924:                                .setJtaDataSource(defaultCmpJTADataSource);
0925:                    }
0926:                    persistenceUnit
0927:                            .setNonJtaDataSource(defaultCmpNonJTADataSource);
0928:                    persistenceUnit.setExcludeUnlistedClasses(true);
0929:
0930:                    Persistence persistence = new Persistence();
0931:                    persistence.setVersion("1.0");
0932:                    persistence.getPersistenceUnit().add(persistenceUnit);
0933:
0934:                    geronimoEjbJarType.getPersistence().add(persistence);
0935:                }
0936:                persistenceUnit.getMappingFile().add(
0937:                        "META-INF/openejb-cmp-generated-orm.xml");
0938:            }
0939:
0940:            /**
0941:             * Does the meaty work of processing the deployment information and
0942:             * creating GBeans for all the EJBs in the JAR, etc.
0943:             */
0944:            public void addGBeans(EARContext earContext, Module module,
0945:                    ClassLoader cl, Collection repositories)
0946:                    throws DeploymentException {
0947:                EjbModule ejbModule = (EjbModule) module;
0948:                EjbDeploymentBuilder ejbDeploymentBuilder = ejbModule
0949:                        .getEjbBuilder();
0950:
0951:                // add enc
0952:                ejbDeploymentBuilder.buildEnc();
0953:
0954:                Set<GBeanData> gBeanDatas = earContext.getConfiguration()
0955:                        .findGBeanDatas(
0956:                                Collections.singleton(new AbstractNameQuery(
0957:                                        PersistenceUnitGBean.class.getName())));
0958:                LinkResolver<String> linkResolver = new UniqueDefaultLinkResolver<String>();
0959:                for (GBeanData gBeanData : gBeanDatas) {
0960:                    String name = (String) gBeanData
0961:                            .getAttribute("persistenceUnitName");
0962:                    String rootUrl = (String) gBeanData
0963:                            .getAttribute("persistenceUnitRoot");
0964:                    if (name.equals("cmp"))
0965:                        continue;
0966:                    String id = name + " " + rootUrl.hashCode();
0967:                    linkResolver.add(rootUrl, name, id);
0968:                }
0969:
0970:                EjbJarInfo ejbJarInfo = ejbModule.getEjbJarInfo();
0971:                for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
0972:                    if (beanInfo instanceof  StatefulBeanInfo) {
0973:                        StatefulBeanInfo statefulBeanInfo = (StatefulBeanInfo) beanInfo;
0974:                        for (PersistenceContextReferenceInfo refInfo : statefulBeanInfo.jndiEnc.persistenceContextRefs) {
0975:                            if (refInfo.extended) {
0976:                                String id = linkResolver.resolveLink(
0977:                                        refInfo.persistenceUnitName,
0978:                                        ejbJarInfo.moduleId);
0979:                                refInfo.unitId = id;
0980:                            }
0981:                        }
0982:                    }
0983:                }
0984:                // Add JSR77 EJBModule GBean
0985:                GBeanData ejbModuleGBeanData = new GBeanData(ejbModule
0986:                        .getModuleName(), EjbModuleImplGBean.GBEAN_INFO);
0987:                try {
0988:                    ejbModuleGBeanData.setReferencePattern("J2EEServer",
0989:                            earContext.getServerName());
0990:                    if (!ejbModule.isStandAlone()) {
0991:                        ejbModuleGBeanData.setReferencePattern(
0992:                                "J2EEApplication", earContext.getModuleName());
0993:                    }
0994:
0995:                    ejbModuleGBeanData.setAttribute("deploymentDescriptor",
0996:                            ejbModule.getOriginalSpecDD());
0997:
0998:                    ejbModuleGBeanData
0999:                            .setReferencePatterns(
1000:                                    "EJBCollection",
1001:                                    new ReferencePatterns(
1002:                                            new AbstractNameQuery(
1003:                                                    null,
1004:                                                    Collections
1005:                                                            .singletonMap(
1006:                                                                    NameFactory.EJB_MODULE,
1007:                                                                    ejbModule
1008:                                                                            .getModuleName()
1009:                                                                            .getNameProperty(
1010:                                                                                    NameFactory.J2EE_NAME)),
1011:                                                    EjbDeployment.class
1012:                                                            .getName())));
1013:
1014:                    ejbModuleGBeanData.setReferencePattern("OpenEjbSystem",
1015:                            new AbstractNameQuery(null, Collections.EMPTY_MAP,
1016:                                    OpenEjbSystem.class.getName()));
1017:                    ejbModuleGBeanData.setAttribute("ejbJarInfo", ejbModule
1018:                            .getEjbJarInfo());
1019:
1020:                    earContext.addGBean(ejbModuleGBeanData);
1021:                } catch (Exception e) {
1022:                    throw new DeploymentException(
1023:                            "Unable to initialize EJBModule GBean "
1024:                                    + ejbModuleGBeanData.getAbstractName(), e);
1025:                }
1026:
1027:                // add a depdendency on the ejb module object
1028:                ejbDeploymentBuilder.addEjbModuleDependency(ejbModuleGBeanData
1029:                        .getAbstractName());
1030:
1031:                // add the Jacc permissions to the ear
1032:                ComponentPermissions componentPermissions = ejbDeploymentBuilder
1033:                        .buildComponentPermissions();
1034:                earContext.addSecurityContext(
1035:                        ejbModule.getEjbJarInfo().moduleId,
1036:                        componentPermissions);
1037:
1038:                setMdbContainerIds(earContext, ejbModule, ejbModuleGBeanData);
1039:
1040:                for (ModuleBuilderExtension builder : moduleBuilderExtensions) {
1041:                    try {
1042:                        builder.addGBeans(earContext, module, cl, repositories);
1043:                    } catch (Throwable t) {
1044:                        String builderName = builder.getClass().getSimpleName();
1045:                        log.error(builderName + ".addGBeans() failed: "
1046:                                + t.getMessage(), t);
1047:                    }
1048:                }
1049:            }
1050:
1051:            private void setMdbContainerIds(EARContext earContext,
1052:                    EjbModule ejbModule, GBeanData ejbModuleGBeanData)
1053:                    throws DeploymentException {
1054:                Object altDD = ejbModule.getEjbModule().getAltDDs().get(
1055:                        "openejb-jar.xml");
1056:                if (!(altDD instanceof  OpenejbJarType)) {
1057:                    return;
1058:                }
1059:                OpenejbJarType openejbJarType = (OpenejbJarType) altDD;
1060:                EjbJarInfo ejbJarInfo = ejbModule.getEjbJarInfo();
1061:
1062:                Map<String, MessageDrivenBeanInfo> mdbs = new TreeMap<String, MessageDrivenBeanInfo>();
1063:                for (EnterpriseBeanInfo enterpriseBean : ejbJarInfo.enterpriseBeans) {
1064:                    if (enterpriseBean instanceof  MessageDrivenBeanInfo) {
1065:                        mdbs.put(enterpriseBean.ejbName,
1066:                                (MessageDrivenBeanInfo) enterpriseBean);
1067:                    }
1068:                }
1069:                for (org.apache.openejb.jee.oejb2.EnterpriseBean enterpriseBean : openejbJarType
1070:                        .getEnterpriseBeans()) {
1071:                    if (!(enterpriseBean instanceof  MessageDrivenBeanType)) {
1072:                        continue;
1073:                    }
1074:                    MessageDrivenBeanType bean = (MessageDrivenBeanType) enterpriseBean;
1075:                    MessageDrivenBeanInfo messageDrivenBeanInfo = mdbs.get(bean
1076:                            .getEjbName());
1077:                    if (messageDrivenBeanInfo == null) {
1078:                        continue;
1079:                    }
1080:                    if (messageDrivenBeanInfo.containerId != null) {
1081:                        // containerId already set
1082:                        continue;
1083:                    }
1084:
1085:                    if (bean.getResourceAdapter() == null) {
1086:                        throw new DeploymentException(
1087:                                "No Resource Adapter defined for MDB '"
1088:                                        + bean.getEjbName() + "'");
1089:                    }
1090:
1091:                    AbstractNameQuery resourceAdapterNameQuery = getResourceAdapterNameQuery(bean
1092:                            .getResourceAdapter());
1093:                    AbstractName resourceAdapterAbstractName;
1094:                    try {
1095:                        resourceAdapterAbstractName = earContext
1096:                                .findGBean(resourceAdapterNameQuery);
1097:                    } catch (GBeanNotFoundException e) {
1098:                        throw new DeploymentException(
1099:                                "Resource Adapter for MDB '"
1100:                                        + bean.getEjbName() + "'not found: "
1101:                                        + resourceAdapterNameQuery, e);
1102:                    }
1103:
1104:                    String resourceAdapterId = getResourceAdapterId(resourceAdapterAbstractName);
1105:                    messageDrivenBeanInfo.containerId = resourceAdapterId + "-"
1106:                            + messageDrivenBeanInfo.mdbInterface;
1107:
1108:                    // add a dependency from the module to the ra so we can be assured the mdb
1109:                    // container exists when this app is started
1110:                    ejbModuleGBeanData
1111:                            .addDependency(resourceAdapterAbstractName);
1112:                }
1113:            }
1114:
1115:            private String getResourceAdapterId(
1116:                    AbstractName resourceAdapterAbstractName) {
1117:                Map properties = resourceAdapterAbstractName.getName();
1118:                String shortName = (String) properties.get("name");
1119:                String moduleName = (String) properties
1120:                        .get("ResourceAdapterModule");
1121:                if (shortName != null && moduleName != null) {
1122:                    return moduleName + "." + shortName;
1123:                } else {
1124:                    return resourceAdapterAbstractName.getObjectName()
1125:                            .toString();
1126:                }
1127:            }
1128:
1129:            private static AbstractNameQuery getResourceAdapterNameQuery(
1130:                    ResourceLocatorType resourceLocator) {
1131:                if (resourceLocator.getResourceLink() != null) {
1132:                    Map<String, String> nameMap = new HashMap<String, String>();
1133:                    nameMap.put("name", resourceLocator.getResourceLink());
1134:                    nameMap.put("j2eeType", NameFactory.JCA_RESOURCE_ADAPTER);
1135:                    return new AbstractNameQuery(null, nameMap);
1136:                }
1137:
1138:                //construct name from components
1139:                PatternType pattern = resourceLocator.getPattern();
1140:                Artifact artifact = null;
1141:                if (pattern.getArtifactId() != null) {
1142:                    artifact = new Artifact(pattern.getGroupId(), pattern
1143:                            .getArtifactId(), pattern.getVersion(), "car");
1144:                }
1145:
1146:                Map<String, String> nameMap = new HashMap<String, String>();
1147:                nameMap.put("name", pattern.getName());
1148:                nameMap.put("j2eeType", NameFactory.JCA_RESOURCE_ADAPTER);
1149:                if (pattern.getModule() != null) {
1150:                    nameMap.put(NameFactory.RESOURCE_ADAPTER_MODULE, pattern
1151:                            .getModule());
1152:                }
1153:                return new AbstractNameQuery(artifact, nameMap, (Set) null);
1154:            }
1155:
1156:            public static class EarData {
1157:                private final Map<String, EjbModule> ejbModules = new TreeMap<String, EjbModule>();
1158:                private final Map<String, EjbJarInfo> ejbJars = new TreeMap<String, EjbJarInfo>();
1159:
1160:                public void addEjbModule(EjbModule ejbModule) {
1161:                    ejbModules.put(ejbModule.getEjbModule().getModuleId(),
1162:                            ejbModule);
1163:                }
1164:
1165:                public EjbModule getEjbModule(String moduleId)
1166:                        throws DeploymentException {
1167:                    EjbModule ejbModule = ejbModules.get(moduleId);
1168:                    if (ejbModule == null) {
1169:                        throw new DeploymentException("Ejb  module " + moduleId
1170:                                + " was not found in configured module list "
1171:                                + ejbModules.keySet());
1172:                    }
1173:                    return ejbModule;
1174:                }
1175:
1176:                public Collection<EjbModule> getEjbModuels() {
1177:                    return ejbModules.values();
1178:                }
1179:
1180:                public void addEjbJar(EjbJarInfo ejbJarInfo) {
1181:                    ejbJars.put(ejbJarInfo.moduleId, ejbJarInfo);
1182:                }
1183:
1184:                public EjbJarInfo getEjbJar(String moduleId)
1185:                        throws DeploymentException {
1186:                    EjbJarInfo ejbJarInfo = ejbJars.get(moduleId);
1187:                    if (ejbJarInfo == null) {
1188:                        throw new DeploymentException(
1189:                                "Ejb jar configuration passed but expected module "
1190:                                        + moduleId
1191:                                        + " was not found in configured module list "
1192:                                        + ejbJars.keySet());
1193:                    }
1194:                    return ejbJarInfo;
1195:                }
1196:
1197:                public Collection<EjbJarInfo> getEjbJars() {
1198:                    return ejbJars.values();
1199:                }
1200:            }
1201:
1202:            public static final GBeanInfo GBEAN_INFO;
1203:
1204:            static {
1205:                GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
1206:                        EjbModuleBuilder.class, NameFactory.MODULE_BUILDER);
1207:                infoBuilder.addAttribute("defaultEnvironment",
1208:                        Environment.class, true);
1209:                infoBuilder.addAttribute("defaultCmpJTADataSource",
1210:                        String.class, true);
1211:                infoBuilder.addAttribute("defaultCmpNonJTADataSource",
1212:                        String.class, true);
1213:                infoBuilder.addReference("ModuleBuilderExtensions",
1214:                        ModuleBuilderExtension.class,
1215:                        NameFactory.MODULE_BUILDER);
1216:                infoBuilder.addReference("SecurityBuilders",
1217:                        NamespaceDrivenBuilder.class,
1218:                        NameFactory.MODULE_BUILDER);
1219:                infoBuilder.addReference("ServiceBuilders",
1220:                        NamespaceDrivenBuilder.class,
1221:                        NameFactory.MODULE_BUILDER);
1222:                infoBuilder.addReference("NamingBuilders", NamingBuilder.class,
1223:                        NameFactory.MODULE_BUILDER);
1224:                infoBuilder.addReference("ResourceEnvironmentSetter",
1225:                        ResourceEnvironmentSetter.class,
1226:                        NameFactory.MODULE_BUILDER);
1227:
1228:                infoBuilder.setConstructor(new String[] { "defaultEnvironment",
1229:                        "defaultCmpJTADataSource",
1230:                        "defaultCmpNonJTADataSource",
1231:                        "ModuleBuilderExtensions", "SecurityBuilders",
1232:                        "ServiceBuilders", "NamingBuilders",
1233:                        "ResourceEnvironmentSetter" });
1234:                GBEAN_INFO = infoBuilder.getBeanInfo();
1235:            }
1236:
1237:            public static GBeanInfo getGBeanInfo() {
1238:                return GBEAN_INFO;
1239:            }
1240:
1241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.