Source Code Cross Referenced for AppClientModuleBuilder.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » client » builder » 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.client.builder 
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.client.builder;
0017:
0018:        import java.io.File;
0019:        import java.io.IOException;
0020:        import java.net.URI;
0021:        import java.net.URISyntaxException;
0022:        import java.net.URL;
0023:        import java.util.ArrayList;
0024:        import java.util.Collection;
0025:        import java.util.Collections;
0026:        import java.util.HashMap;
0027:        import java.util.LinkedList;
0028:        import java.util.List;
0029:        import java.util.Map;
0030:        import java.util.StringTokenizer;
0031:        import java.util.LinkedHashSet;
0032:        import java.util.jar.Attributes;
0033:        import java.util.jar.JarFile;
0034:        import java.util.jar.Manifest;
0035:        import java.util.zip.ZipEntry;
0036:
0037:        import org.apache.commons.logging.Log;
0038:        import org.apache.commons.logging.LogFactory;
0039:        import org.apache.geronimo.client.AppClientContainer;
0040:        import org.apache.geronimo.client.StaticJndiContextPlugin;
0041:        import org.apache.geronimo.common.DeploymentException;
0042:        import org.apache.geronimo.deployment.ClassPathList;
0043:        import org.apache.geronimo.deployment.DeploymentContext;
0044:        import org.apache.geronimo.deployment.ModuleIDBuilder;
0045:        import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
0046:        import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection;
0047:        import org.apache.geronimo.deployment.ModuleList;
0048:        import org.apache.geronimo.deployment.service.EnvironmentBuilder;
0049:        import org.apache.geronimo.deployment.service.GBeanBuilder;
0050:        import org.apache.geronimo.deployment.util.DeploymentUtil;
0051:        import org.apache.geronimo.deployment.util.NestedJarFile;
0052:        import org.apache.geronimo.deployment.xbeans.EnvironmentType;
0053:        import org.apache.geronimo.deployment.xbeans.PatternType;
0054:        import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
0055:        import org.apache.geronimo.gbean.AbstractName;
0056:        import org.apache.geronimo.gbean.AbstractNameQuery;
0057:        import org.apache.geronimo.gbean.GBeanData;
0058:        import org.apache.geronimo.gbean.GBeanInfo;
0059:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
0060:        import org.apache.geronimo.gbean.SingleElementCollection;
0061:        import org.apache.geronimo.gbean.GBeanLifecycle;
0062:        import org.apache.geronimo.j2ee.deployment.AppClientModule;
0063:        import org.apache.geronimo.j2ee.deployment.ConnectorModule;
0064:        import org.apache.geronimo.j2ee.deployment.CorbaGBeanNameSource;
0065:        import org.apache.geronimo.j2ee.deployment.EARContext;
0066:        import org.apache.geronimo.j2ee.deployment.Module;
0067:        import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
0068:        import org.apache.geronimo.j2ee.deployment.ModuleBuilderExtension;
0069:        import org.apache.geronimo.j2ee.deployment.NamingBuilder;
0070:        import org.apache.geronimo.j2ee.deployment.NamingBuilderCollection;
0071:        import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApplicationClient;
0072:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
0073:        import org.apache.geronimo.j2ee.management.impl.J2EEAppClientModuleImpl;
0074:        import org.apache.geronimo.j2ee.ApplicationInfo;
0075:        import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
0076:        import org.apache.geronimo.kernel.Naming;
0077:        import org.apache.geronimo.kernel.config.Configuration;
0078:        import org.apache.geronimo.kernel.config.ConfigurationAlreadyExistsException;
0079:        import org.apache.geronimo.kernel.config.ConfigurationModuleType;
0080:        import org.apache.geronimo.kernel.config.ConfigurationStore;
0081:        import org.apache.geronimo.kernel.repository.Artifact;
0082:        import org.apache.geronimo.kernel.repository.Environment;
0083:        import org.apache.geronimo.kernel.repository.Repository;
0084:        import org.apache.geronimo.kernel.repository.ArtifactResolver;
0085:        import org.apache.geronimo.kernel.repository.MissingDependencyException;
0086:        import org.apache.geronimo.schema.SchemaConversionUtils;
0087:        import org.apache.geronimo.security.deploy.SubjectInfo;
0088:        import org.apache.geronimo.security.deployment.SecurityConfiguration;
0089:        import org.apache.geronimo.xbeans.geronimo.client.GerApplicationClientDocument;
0090:        import org.apache.geronimo.xbeans.geronimo.client.GerApplicationClientType;
0091:        import org.apache.geronimo.xbeans.geronimo.client.GerResourceType;
0092:        import org.apache.geronimo.xbeans.geronimo.naming.GerAbstractNamingEntryDocument;
0093:        import org.apache.geronimo.xbeans.geronimo.security.GerSubjectInfoType;
0094:        import org.apache.geronimo.xbeans.javaee.ApplicationClientDocument;
0095:        import org.apache.geronimo.xbeans.javaee.ApplicationClientType;
0096:        import org.apache.geronimo.xbeans.javaee.FullyQualifiedClassType;
0097:        import org.apache.xbean.finder.ClassFinder;
0098:        import org.apache.xmlbeans.XmlCursor;
0099:        import org.apache.xmlbeans.XmlException;
0100:        import org.apache.xmlbeans.XmlObject;
0101:
0102:        /**
0103:         * @version $Rev:385232 $ $Date: 2008-02-01 22:01:19 -0800 (Fri, 01 Feb 2008) $
0104:         */
0105:        public class AppClientModuleBuilder implements  ModuleBuilder,
0106:                CorbaGBeanNameSource, GBeanLifecycle {
0107:            private static final Log log = LogFactory
0108:                    .getLog(AppClientModuleBuilder.class);
0109:            private static final String LINE_SEP = System
0110:                    .getProperty("line.separator");
0111:            private static final String GERAPPCLIENT_NAMESPACE = GerApplicationClientDocument.type
0112:                    .getDocumentElementName().getNamespaceURI();
0113:            private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String, String>();
0114:            static {
0115:                NAMESPACE_UPDATES
0116:                        .put(
0117:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client",
0118:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
0119:                NAMESPACE_UPDATES
0120:                        .put(
0121:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client-1.1",
0122:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
0123:                NAMESPACE_UPDATES
0124:                        .put(
0125:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client-1.2",
0126:                                "http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0");
0127:            }
0128:
0129:            private final Environment defaultClientEnvironment;
0130:            private final Environment defaultServerEnvironment;
0131:            private final AbstractNameQuery corbaGBeanObjectName;
0132:
0133:            private final AbstractNameQuery transactionManagerObjectName;
0134:            private final AbstractNameQuery connectionTrackerObjectName;
0135:            private final AbstractNameQuery credentialStoreName;
0136:            private final SingleElementCollection connectorModuleBuilder;
0137:            private final NamespaceDrivenBuilderCollection serviceBuilder;
0138:            private final NamingBuilderCollection namingBuilders;
0139:            private final Collection<ModuleBuilderExtension> moduleBuilderExtensions;
0140:
0141:            private final Collection<Repository> repositories;
0142:
0143:            private final ArtifactResolver clientArtifactResolver;
0144:
0145:            public AppClientModuleBuilder(Environment defaultClientEnvironment,
0146:                    Environment defaultServerEnvironment,
0147:                    AbstractNameQuery transactionManagerObjectName,
0148:                    AbstractNameQuery connectionTrackerObjectName,
0149:                    AbstractNameQuery corbaGBeanObjectName,
0150:                    AbstractNameQuery credentialStoreName,
0151:                    Collection<Repository> repositories,
0152:                    ModuleBuilder connectorModuleBuilder,
0153:                    NamespaceDrivenBuilder serviceBuilder,
0154:                    Collection<NamingBuilder> namingBuilders,
0155:                    Collection<ModuleBuilderExtension> moduleBuilderExtensions,
0156:                    ArtifactResolver clientArtifactResolver) {
0157:                this (defaultClientEnvironment, defaultServerEnvironment,
0158:                        transactionManagerObjectName,
0159:                        connectionTrackerObjectName, corbaGBeanObjectName,
0160:                        credentialStoreName, repositories,
0161:                        new SingleElementCollection<ModuleBuilder>(
0162:                                connectorModuleBuilder),
0163:                        serviceBuilder == null ? Collections.EMPTY_SET
0164:                                : Collections.singleton(serviceBuilder),
0165:                        namingBuilders == null ? Collections.EMPTY_SET
0166:                                : namingBuilders, moduleBuilderExtensions,
0167:                        clientArtifactResolver);
0168:            }
0169:
0170:            public AppClientModuleBuilder(
0171:                    AbstractNameQuery transactionManagerObjectName,
0172:                    AbstractNameQuery connectionTrackerObjectName,
0173:                    AbstractNameQuery corbaGBeanObjectName,
0174:                    AbstractNameQuery credentialStoreName,
0175:                    Collection<Repository> repositories,
0176:                    Collection<ModuleBuilder> connectorModuleBuilder,
0177:                    Collection<NamespaceDrivenBuilder> serviceBuilder,
0178:                    Collection<NamingBuilder> namingBuilders,
0179:                    Collection<ModuleBuilderExtension> moduleBuilderExtensions,
0180:                    ArtifactResolver clientArtifactResolver,
0181:                    Environment defaultClientEnvironment,
0182:                    Environment defaultServerEnvironment) {
0183:                this (defaultClientEnvironment, defaultServerEnvironment,
0184:                        transactionManagerObjectName,
0185:                        connectionTrackerObjectName, corbaGBeanObjectName,
0186:                        credentialStoreName, repositories,
0187:                        new SingleElementCollection<ModuleBuilder>(
0188:                                connectorModuleBuilder), serviceBuilder,
0189:                        namingBuilders, moduleBuilderExtensions,
0190:                        clientArtifactResolver);
0191:            }
0192:
0193:            private AppClientModuleBuilder(
0194:                    Environment defaultClientEnvironment,
0195:                    Environment defaultServerEnvironment,
0196:                    AbstractNameQuery transactionManagerObjectName,
0197:                    AbstractNameQuery connectionTrackerObjectName,
0198:                    AbstractNameQuery corbaGBeanObjectName,
0199:                    AbstractNameQuery credentialStoreName,
0200:                    Collection<Repository> repositories,
0201:                    SingleElementCollection<ModuleBuilder> connectorModuleBuilder,
0202:                    Collection<NamespaceDrivenBuilder> serviceBuilder,
0203:                    Collection<NamingBuilder> namingBuilders,
0204:                    Collection<ModuleBuilderExtension> moduleBuilderExtensions,
0205:                    ArtifactResolver clientArtifactResolver) {
0206:                this .defaultClientEnvironment = defaultClientEnvironment;
0207:                this .defaultServerEnvironment = defaultServerEnvironment;
0208:                this .corbaGBeanObjectName = corbaGBeanObjectName;
0209:                this .transactionManagerObjectName = transactionManagerObjectName;
0210:                this .connectionTrackerObjectName = connectionTrackerObjectName;
0211:                this .credentialStoreName = credentialStoreName;
0212:                this .repositories = repositories;
0213:                this .connectorModuleBuilder = connectorModuleBuilder;
0214:                this .serviceBuilder = new NamespaceDrivenBuilderCollection(
0215:                        serviceBuilder, GBeanBuilder.SERVICE_QNAME);
0216:                this .namingBuilders = new NamingBuilderCollection(
0217:                        namingBuilders, GerAbstractNamingEntryDocument.type
0218:                                .getDocumentElementName());
0219:                this .moduleBuilderExtensions = moduleBuilderExtensions;
0220:                this .clientArtifactResolver = clientArtifactResolver;
0221:            }
0222:
0223:            public void doStart() throws Exception {
0224:                XmlBeansUtil.registerNamespaceUpdates(NAMESPACE_UPDATES);
0225:            }
0226:
0227:            public void doStop() {
0228:                XmlBeansUtil.unregisterNamespaceUpdates(NAMESPACE_UPDATES);
0229:            }
0230:
0231:            public void doFail() {
0232:                doStop();
0233:            }
0234:
0235:            public AbstractNameQuery getCorbaGBeanName() {
0236:                return corbaGBeanObjectName;
0237:            }
0238:
0239:            private ModuleBuilder getConnectorModuleBuilder() {
0240:                return (ModuleBuilder) connectorModuleBuilder.getElement();
0241:            }
0242:
0243:            public Module createModule(File plan, JarFile moduleFile,
0244:                    Naming naming, ModuleIDBuilder idBuilder)
0245:                    throws DeploymentException {
0246:                return createModule(plan, moduleFile, "app-client", null, null,
0247:                        null, naming, idBuilder);
0248:            }
0249:
0250:            public Module createModule(Object plan, JarFile moduleFile,
0251:                    String targetPath, URL specDDUrl, Environment environment,
0252:                    Object moduleContextInfo, AbstractName earName,
0253:                    Naming naming, ModuleIDBuilder idBuilder)
0254:                    throws DeploymentException {
0255:                return createModule(plan, moduleFile, targetPath, specDDUrl,
0256:                        environment, earName, naming, idBuilder);
0257:            }
0258:
0259:            private Module createModule(Object plan, JarFile moduleFile,
0260:                    String targetPath, URL specDDUrl,
0261:                    Environment earEnvironment, AbstractName earName,
0262:                    Naming naming, ModuleIDBuilder idBuilder)
0263:                    throws DeploymentException {
0264:                assert moduleFile != null : "moduleFile is null";
0265:                assert targetPath != null : "targetPath is null";
0266:                assert !targetPath.endsWith("/") : "targetPath must not end with a '/'";
0267:                assert (earName == null) == (earEnvironment == null) : "if earName is not null you must supply earEnvironment as well";
0268:
0269:                boolean standAlone = earEnvironment == null;
0270:
0271:                // get the app client main class
0272:                String mainClass;
0273:                try {
0274:                    Manifest manifest = moduleFile.getManifest();
0275:                    if (manifest == null) {
0276:                        throw new DeploymentException(
0277:                                "App client module jar does not contain a manifest: "
0278:                                        + moduleFile.getName());
0279:                    }
0280:                    mainClass = manifest.getMainAttributes().getValue(
0281:                            Attributes.Name.MAIN_CLASS);
0282:                    if (mainClass == null) {
0283:                        //not an app client
0284:                        return null;
0285:                    }
0286:                    String classPath = manifest.getMainAttributes().getValue(
0287:                            Attributes.Name.CLASS_PATH);
0288:                    if (standAlone && classPath != null) {
0289:                        throw new DeploymentException(
0290:                                "Manifest class path entry is not allowed in a standalone jar (JAVAEE 5 Section 8.2)");
0291:                    }
0292:                } catch (IOException e) {
0293:                    throw new DeploymentException(
0294:                            "Could not get manifest from app client module: "
0295:                                    + moduleFile.getName(), e);
0296:                }
0297:
0298:                String specDD;
0299:                ApplicationClientType appClient = null;
0300:                try {
0301:                    if (specDDUrl == null) {
0302:                        specDDUrl = DeploymentUtil.createJarURL(moduleFile,
0303:                                "META-INF/application-client.xml");
0304:                    }
0305:
0306:                    // read in the entire specDD as a string, we need this for getDeploymentDescriptor
0307:                    // on the J2ee management object
0308:                    specDD = DeploymentUtil.readAll(specDDUrl);
0309:                } catch (Exception e) {
0310:                    //construct a default spec dd
0311:                    ApplicationClientDocument appClientDoc = ApplicationClientDocument.Factory
0312:                            .newInstance();
0313:                    appClientDoc.addNewApplicationClient();
0314:                    appClient = appClientDoc.getApplicationClient();
0315:                    specDD = appClientDoc.xmlText();
0316:                }
0317:
0318:                if (appClient == null) {
0319:                    //we found application-client.xml, if it won't parse it's an error.
0320:                    try {
0321:                        // parse it
0322:                        XmlObject xmlObject = XmlBeansUtil.parse(specDD);
0323:                        ApplicationClientDocument appClientDoc = convertToApplicationClientSchema(xmlObject);
0324:                        appClient = appClientDoc.getApplicationClient();
0325:                    } catch (XmlException e) {
0326:                        throw new DeploymentException(
0327:                                "Unable to parse application-client.xml", e);
0328:                    }
0329:                }
0330:
0331:                // parse vendor dd
0332:                GerApplicationClientType gerAppClient = getGeronimoAppClient(
0333:                        plan, moduleFile, standAlone, targetPath, appClient,
0334:                        earEnvironment);
0335:
0336:                EnvironmentType clientEnvironmentType = gerAppClient
0337:                        .getClientEnvironment();
0338:                Environment clientEnvironment = EnvironmentBuilder
0339:                        .buildEnvironment(clientEnvironmentType,
0340:                                defaultClientEnvironment);
0341:                if (standAlone) {
0342:                    String name = new File(moduleFile.getName()).getName();
0343:                    idBuilder.resolve(clientEnvironment, name + "_" + name,
0344:                            "jar");
0345:                } else {
0346:                    Artifact earConfigId = earEnvironment.getConfigId();
0347:                    idBuilder.resolve(clientEnvironment, earConfigId
0348:                            .getArtifactId()
0349:                            + "_" + targetPath, "jar");
0350:                }
0351:                EnvironmentType serverEnvironmentType = gerAppClient
0352:                        .getServerEnvironment();
0353:                Environment serverEnvironment = EnvironmentBuilder
0354:                        .buildEnvironment(serverEnvironmentType,
0355:                                defaultServerEnvironment);
0356:                if (!standAlone) {
0357:                    EnvironmentBuilder.mergeEnvironments(earEnvironment,
0358:                            serverEnvironment);
0359:                    serverEnvironment = earEnvironment;
0360:                    if (!serverEnvironment.getConfigId().isResolved()) {
0361:                        throw new IllegalStateException(
0362:                                "Server environment module ID should be fully resolved (not "
0363:                                        + serverEnvironment.getConfigId() + ")");
0364:                    }
0365:                } else {
0366:                    idBuilder.resolve(serverEnvironment, new File(moduleFile
0367:                            .getName()).getName(), "jar");
0368:                }
0369:
0370:                if (earName == null) {
0371:                    earName = naming.createRootName(serverEnvironment
0372:                            .getConfigId(), NameFactory.NULL,
0373:                            NameFactory.J2EE_APPLICATION);
0374:                }
0375:
0376:                //always use the artifactId of the app client as the name component of the module name (on the server).
0377:                AbstractName moduleName = naming.createChildName(earName,
0378:                        clientEnvironment.getConfigId().toString(),
0379:                        NameFactory.APP_CLIENT_MODULE);
0380:                AbstractName clientBaseName = naming.createRootName(
0381:                        clientEnvironment.getConfigId(), clientEnvironment
0382:                                .getConfigId().toString(),
0383:                        NameFactory.J2EE_APPLICATION);
0384:
0385:                //start installing the resource adapters in the client.
0386:                Collection<ConnectorModule> resourceModules = new ArrayList<ConnectorModule>();
0387:                GerResourceType[] resources = gerAppClient.getResourceArray();
0388:                for (GerResourceType resource : resources) {
0389:                    String path;
0390:                    JarFile connectorFile;
0391:                    if (resource.isSetExternalRar()) {
0392:                        PatternType externalRar = resource.getExternalRar();
0393:                        String groupId = trim(externalRar.getGroupId());
0394:                        String artifactId = trim(externalRar.getArtifactId());
0395:                        String version = trim(externalRar.getVersion());
0396:                        String type = trim(externalRar.getType());
0397:                        Artifact artifact = new Artifact(groupId, artifactId,
0398:                                version, type);
0399:                        try {
0400:                            artifact = clientArtifactResolver
0401:                                    .resolveInClassLoader(artifact);
0402:                        } catch (MissingDependencyException e) {
0403:                            throw new DeploymentException(
0404:                                    "Could not resolve external rar location in repository: "
0405:                                            + artifact, e);
0406:                        }
0407:                        File file = null;
0408:                        for (Repository repository : repositories) {
0409:                            if (repository.contains(artifact)) {
0410:                                file = repository.getLocation(artifact);
0411:                                break;
0412:                            }
0413:                        }
0414:                        if (file == null) {
0415:                            throw new DeploymentException(
0416:                                    "Missing external rar in repositories: "
0417:                                            + artifact);
0418:                        }
0419:                        try {
0420:                            connectorFile = new JarFile(file);
0421:                        } catch (IOException e) {
0422:                            throw new DeploymentException(
0423:                                    "Could not access external rar contents for artifact: "
0424:                                            + artifact, e);
0425:                        }
0426:                        path = artifact.toString();
0427:                    } else {
0428:                        path = resource.getInternalRar();
0429:                        try {
0430:                            connectorFile = new NestedJarFile(moduleFile, path);
0431:                        } catch (IOException e) {
0432:                            throw new DeploymentException(
0433:                                    "Could not locate connector inside ear", e);
0434:                        }
0435:                    }
0436:                    XmlObject connectorPlan = resource.getConnector();
0437:                    ConnectorModule connectorModule = (ConnectorModule) getConnectorModuleBuilder()
0438:                            .createModule(connectorPlan, connectorFile, path,
0439:                                    null, clientEnvironment, null,
0440:                                    clientBaseName, naming, idBuilder);
0441:                    resourceModules.add(connectorModule);
0442:                }
0443:
0444:                // Create the AnnotatedApp interface for the AppClientModule
0445:                AnnotatedApplicationClient annotatedApplicationClient = new AnnotatedApplicationClient(
0446:                        appClient, mainClass);
0447:
0448:                AppClientModule module = new AppClientModule(standAlone,
0449:                        moduleName, clientBaseName, serverEnvironment,
0450:                        clientEnvironment, moduleFile, targetPath, appClient,
0451:                        mainClass, gerAppClient, specDD, resourceModules,
0452:                        annotatedApplicationClient);
0453:                for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
0454:                    mbe.createModule(module, plan, moduleFile, targetPath,
0455:                            specDDUrl, clientEnvironment, null, earName,
0456:                            naming, idBuilder);
0457:                }
0458:                if (standAlone) {
0459:                    ApplicationInfo appInfo = new ApplicationInfo(
0460:                            ConfigurationModuleType.CAR, serverEnvironment,
0461:                            earName, null, null, null,
0462:                            new LinkedHashSet<Module>(Collections
0463:                                    .singleton(module)), new ModuleList(), null);
0464:                    return appInfo;
0465:                } else {
0466:                    return module;
0467:                }
0468:            }
0469:
0470:            private String trim(String s) {
0471:                if (s == null) {
0472:                    return null;
0473:                }
0474:                return s.trim();
0475:            }
0476:
0477:            GerApplicationClientType getGeronimoAppClient(Object plan,
0478:                    JarFile moduleFile, boolean standAlone, String targetPath,
0479:                    ApplicationClientType appClient, Environment environment)
0480:                    throws DeploymentException {
0481:                GerApplicationClientType gerAppClient;
0482:                XmlObject rawPlan = null;
0483:                try {
0484:                    // load the geronimo-application-client.xml from either the supplied plan or from the earFile
0485:                    try {
0486:                        if (plan instanceof  XmlObject) {
0487:                            rawPlan = (XmlObject) plan;
0488:                        } else {
0489:                            if (plan != null) {
0490:                                rawPlan = XmlBeansUtil.parse((File) plan);
0491:                            } else {
0492:                                URL path = DeploymentUtil
0493:                                        .createJarURL(moduleFile,
0494:                                                "META-INF/geronimo-application-client.xml");
0495:                                rawPlan = XmlBeansUtil.parse(path, getClass()
0496:                                        .getClassLoader());
0497:                            }
0498:                        }
0499:                    } catch (IOException e) {
0500:                        //exception means we create default
0501:                    }
0502:
0503:                    // if we got one extract the validate it otherwise create a default one
0504:                    if (rawPlan != null) {
0505:                        gerAppClient = (GerApplicationClientType) SchemaConversionUtils
0506:                                .fixGeronimoSchema(rawPlan,
0507:                                        GerApplicationClientDocument.type
0508:                                                .getDocumentElementName(),
0509:                                        GerApplicationClientType.type);
0510:                    } else {
0511:                        String path;
0512:                        if (standAlone) {
0513:                            // default configId is based on the moduleFile name
0514:                            path = new File(moduleFile.getName()).getName();
0515:                        } else {
0516:                            // default configId is based on the module uri from the application.xml
0517:                            path = targetPath;
0518:                        }
0519:                        gerAppClient = createDefaultPlan(path, appClient,
0520:                                standAlone, environment);
0521:                    }
0522:                } catch (XmlException e) {
0523:                    throw new DeploymentException(
0524:                            "Unable to parse application plan", e);
0525:                }
0526:                return gerAppClient;
0527:            }
0528:
0529:            private GerApplicationClientType createDefaultPlan(String name,
0530:                    ApplicationClientType appClient, boolean standAlone,
0531:                    Environment environment) {
0532:                String id = appClient == null ? null : appClient.getId();
0533:                if (id == null) {
0534:                    id = name;
0535:                    if (id.endsWith(".jar")) {
0536:                        id = id.substring(0, id.length() - 4);
0537:                    }
0538:                    if (id.endsWith("/")) {
0539:                        id = id.substring(0, id.length() - 1);
0540:                    }
0541:                }
0542:
0543:                GerApplicationClientType geronimoAppClient = GerApplicationClientType.Factory
0544:                        .newInstance();
0545:                EnvironmentType clientEnvironmentType = geronimoAppClient
0546:                        .addNewClientEnvironment();
0547:                EnvironmentType serverEnvironmentType = geronimoAppClient
0548:                        .addNewServerEnvironment();
0549:                //TODO configid fill in environment with configids
0550:                // set the parentId and configId
0551:                //        if (standAlone) {
0552:                //            geronimoAppClient.setClientConfigId(id);
0553:                //            geronimoAppClient.setConfigId(id + "/server");
0554:                //        } else {
0555:                //            geronimoAppClient.setClientConfigId(earConfigId.getPath() + "/" + id);
0556:                //             not used but we need to have a value
0557:                //            geronimoAppClient.setConfigId(id);
0558:                //        }
0559:                return geronimoAppClient;
0560:            }
0561:
0562:            static ApplicationClientDocument convertToApplicationClientSchema(
0563:                    XmlObject xmlObject) throws XmlException {
0564:                if (ApplicationClientDocument.type.equals(xmlObject
0565:                        .schemaType())) {
0566:                    XmlBeansUtil.validateDD(xmlObject);
0567:                    return (ApplicationClientDocument) xmlObject;
0568:                }
0569:                XmlCursor cursor = xmlObject.newCursor();
0570:                XmlCursor moveable = xmlObject.newCursor();
0571:                String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application-client_5.xsd";
0572:                String version = "5";
0573:                try {
0574:                    cursor.toStartDoc();
0575:                    cursor.toFirstChild();
0576:                    if ("http://java.sun.com/xml/ns/j2ee".equals(cursor
0577:                            .getName().getNamespaceURI())) {
0578:                        SchemaConversionUtils.convertSchemaVersion(cursor,
0579:                                SchemaConversionUtils.JAVAEE_NAMESPACE,
0580:                                schemaLocationURL, version);
0581:                        XmlObject result = xmlObject
0582:                                .changeType(ApplicationClientDocument.type);
0583:                        XmlBeansUtil.validateDD(result);
0584:                        return (ApplicationClientDocument) result;
0585:                    }
0586:
0587:                    // otherwise assume DTD
0588:                    SchemaConversionUtils.convertToSchema(cursor,
0589:                            SchemaConversionUtils.JAVAEE_NAMESPACE,
0590:                            schemaLocationURL, version);
0591:                    cursor.toStartDoc();
0592:                    cursor.toChild(SchemaConversionUtils.JAVAEE_NAMESPACE,
0593:                            "application-client");
0594:                    cursor.toFirstChild();
0595:                    SchemaConversionUtils.convertToDescriptionGroup(
0596:                            SchemaConversionUtils.JAVAEE_NAMESPACE, cursor,
0597:                            moveable);
0598:                } finally {
0599:                    cursor.dispose();
0600:                    moveable.dispose();
0601:                }
0602:                XmlObject result = xmlObject
0603:                        .changeType(ApplicationClientDocument.type);
0604:                if (result != null) {
0605:                    XmlBeansUtil.validateDD(result);
0606:                    return (ApplicationClientDocument) result;
0607:                }
0608:                XmlBeansUtil.validateDD(xmlObject);
0609:                return (ApplicationClientDocument) xmlObject;
0610:
0611:            }
0612:
0613:            public void installModule(JarFile earFile, EARContext earContext,
0614:                    Module module, Collection configurationStores,
0615:                    ConfigurationStore targetConfigurationStore,
0616:                    Collection repositories) throws DeploymentException {
0617:                // extract the app client jar file into a standalone packed jar file and add the contents to the output
0618:                //This duplicates the copy in the app client's own configuration, made below.
0619:                //this should really only be done if there's a manifest classpath reference to the app client jar by another
0620:                //javaee module.
0621:                JarFile moduleFile = module.getModuleFile();
0622:                try {
0623:                    earContext.addIncludeAsPackedJar(URI.create(module
0624:                            .getTargetPath()), moduleFile);
0625:                } catch (IOException e) {
0626:                    throw new DeploymentException(
0627:                            "Unable to copy app client module jar into configuration: "
0628:                                    + moduleFile.getName(), e);
0629:                }
0630:                AppClientModule appClientModule = (AppClientModule) module;
0631:                appClientModule.setEarFile(earFile);
0632:                //create the ear context for the app client.
0633:                Environment clientEnvironment = appClientModule
0634:                        .getEnvironment();
0635:                //        if (!appClientModule.isStandAlone() || clientEnvironment.getConfigId() == null) {
0636:                //            Artifact earConfigId = earContext.getConfigID();
0637:                //            Artifact configId = new Artifact(earConfigId.getGroupId(), earConfigId.getArtifactId() + "_" + module.getTargetPath(), earConfigId.getVersion(), "car");
0638:                //            clientEnvironment.setConfigId(configId);
0639:                //        }
0640:
0641:                File appClientDir;
0642:                try {
0643:                    appClientDir = targetConfigurationStore
0644:                            .createNewConfigurationDir(clientEnvironment
0645:                                    .getConfigId());
0646:                } catch (ConfigurationAlreadyExistsException e) {
0647:                    throw new DeploymentException(
0648:                            "Unable to create configuration directory for "
0649:                                    + clientEnvironment.getConfigId(), e);
0650:                }
0651:
0652:                // construct the app client deployment context... this is the same class used by the ear context
0653:                EARContext appClientDeploymentContext;
0654:                try {
0655:
0656:                    appClientDeploymentContext = new EARContext(appClientDir,
0657:                            null,
0658:                            clientEnvironment,
0659:                            ConfigurationModuleType.CAR,
0660:                            earContext.getNaming(),
0661:                            earContext.getConfigurationManager(),
0662:                            null, //no server name needed on client
0663:                            appClientModule.getAppClientName(),
0664:                            transactionManagerObjectName,
0665:                            connectionTrackerObjectName, null, null,
0666:                            corbaGBeanObjectName, earContext
0667:                                    .getMessageDestinations());
0668:                    appClientModule.setEarContext(appClientDeploymentContext);
0669:                    appClientModule
0670:                            .setRootEarContext(appClientDeploymentContext);
0671:
0672:                    try {
0673:                        appClientDeploymentContext.addIncludeAsPackedJar(URI
0674:                                .create(module.getTargetPath()), moduleFile);
0675:                    } catch (IOException e) {
0676:                        throw new DeploymentException(
0677:                                "Unable to copy app client module jar into configuration: "
0678:                                        + moduleFile.getName(), e);
0679:                    }
0680:                    ClassPathList libClasspath = (ClassPathList) earContext
0681:                            .getGeneralData().get(ClassPathList.class);
0682:                    if (libClasspath != null) {
0683:                        for (String libEntryPath : libClasspath) {
0684:                            try {
0685:                                NestedJarFile library = new NestedJarFile(
0686:                                        earFile, libEntryPath);
0687:                                appClientDeploymentContext
0688:                                        .addIncludeAsPackedJar(URI
0689:                                                .create(libEntryPath), library);
0690:                            } catch (IOException e) {
0691:                                throw new DeploymentException(
0692:                                        "Could not add to app client library classpath: "
0693:                                                + libEntryPath, e);
0694:                            }
0695:                        }
0696:                    }
0697:                } catch (DeploymentException e) {
0698:                    cleanupAppClientDir(appClientDir);
0699:                    throw e;
0700:                }
0701:                for (ConnectorModule connectorModule : appClientModule
0702:                        .getResourceModules()) {
0703:                    getConnectorModuleBuilder().installModule(
0704:                            connectorModule.getModuleFile(),
0705:                            appClientDeploymentContext, connectorModule,
0706:                            configurationStores, targetConfigurationStore,
0707:                            repositories);
0708:                }
0709:
0710:                for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
0711:                    mbe.installModule(module.getModuleFile(),
0712:                            appClientDeploymentContext, module,
0713:                            configurationStores, targetConfigurationStore,
0714:                            repositories);
0715:                }
0716:            }
0717:
0718:            public void initContext(EARContext earContext, Module clientModule,
0719:                    ClassLoader cl) throws DeploymentException {
0720:                namingBuilders.buildEnvironment(clientModule.getSpecDD(),
0721:                        clientModule.getVendorDD(),
0722:                        ((AppClientModule) clientModule).getEnvironment());
0723:
0724:                AppClientModule appClientModule = ((AppClientModule) clientModule);
0725:                for (ConnectorModule connectorModule : appClientModule
0726:                        .getResourceModules()) {
0727:                    getConnectorModuleBuilder().initContext(
0728:                            appClientModule.getEarContext(), connectorModule,
0729:                            cl);
0730:                }
0731:                for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
0732:                    mbe.initContext(earContext, clientModule, cl);
0733:                }
0734:            }
0735:
0736:            public void addGBeans(EARContext earContext, Module module,
0737:                    ClassLoader earClassLoader, Collection repositories)
0738:                    throws DeploymentException {
0739:
0740:                AppClientModule appClientModule = (AppClientModule) module;
0741:                JarFile moduleFile = module.getModuleFile();
0742:
0743:                ApplicationClientType appClient = (ApplicationClientType) appClientModule
0744:                        .getSpecDD();
0745:                GerApplicationClientType geronimoAppClient = (GerApplicationClientType) appClientModule
0746:                        .getVendorDD();
0747:
0748:                // generate the object name for the app client
0749:                AbstractName appClientModuleName = appClientModule
0750:                        .getModuleName();
0751:
0752:                // create a gbean for the app client module and add it to the ear
0753:                GBeanData appClientModuleGBeanData = new GBeanData(
0754:                        appClientModuleName, J2EEAppClientModuleImpl.GBEAN_INFO);
0755:                try {
0756:                    appClientModuleGBeanData.setReferencePattern("J2EEServer",
0757:                            earContext.getServerName());
0758:                    if (!module.isStandAlone()) {
0759:                        appClientModuleGBeanData.setReferencePattern(
0760:                                "J2EEApplication", earContext.getModuleName());
0761:                    }
0762:
0763:                } catch (Exception e) {
0764:                    throw new DeploymentException(
0765:                            "Unable to initialize AppClientModule GBean", e);
0766:                }
0767:                try {
0768:                    earContext.addGBean(appClientModuleGBeanData);
0769:                } catch (GBeanAlreadyExistsException e) {
0770:                    throw new DeploymentException(
0771:                            "Could not add application client module gbean to configuration",
0772:                            e);
0773:                }
0774:
0775:                EARContext appClientDeploymentContext = appClientModule
0776:                        .getEarContext();
0777:                //Share the ejb info with the ear.
0778:                //TODO this might be too much, but I don't want to impose a dependency on geronimo-openejb to get
0779:                //EjbModuleBuilder.EarData.class
0780:                Map<Object, Object> generalData = earContext.getGeneralData();
0781:                for (Map.Entry<Object, Object> entry : generalData.entrySet()) {
0782:                    Object key = entry.getKey();
0783:                    if (key instanceof  Class
0784:                            && ((Class) key)
0785:                                    .getName()
0786:                                    .equals(
0787:                                            "org.apache.geronimo.openejb.deployment.EjbModuleBuilder$EarData")) {
0788:                        appClientDeploymentContext.getGeneralData().put(key,
0789:                                entry.getValue());
0790:                        break;
0791:                    }
0792:                }
0793:
0794:                // Create a Module ID Builder defaulting to similar settings to use for any children we create
0795:                ModuleIDBuilder idBuilder = new ModuleIDBuilder();
0796:                idBuilder.setDefaultGroup(appClientModule.getEnvironment()
0797:                        .getConfigId().getGroupId());
0798:                idBuilder.setDefaultVersion(appClientModule.getEnvironment()
0799:                        .getConfigId().getVersion());
0800:                try {
0801:                    try {
0802:
0803:                        //register the message destinations in the app client ear context.
0804:                        namingBuilders.initContext(appClient,
0805:                                geronimoAppClient, appClientModule);
0806:                        // extract the client Jar file into a standalone packed jar file and add the contents to the output
0807:                        URI moduleBase = new URI(appClientModule
0808:                                .getTargetPath());
0809:                        try {
0810:                            appClientDeploymentContext.addIncludeAsPackedJar(
0811:                                    moduleBase, moduleFile);
0812:                        } catch (IOException e) {
0813:                            throw new DeploymentException(
0814:                                    "Unable to copy app client module jar into configuration: "
0815:                                            + moduleFile.getName(), e);
0816:                        }
0817:
0818:                        // add manifest class path entries to the app client context
0819:                        addManifestClassPath(appClientDeploymentContext,
0820:                                appClientModule.getEarFile(), moduleFile,
0821:                                moduleBase);
0822:
0823:                        // get the classloader
0824:                        ClassLoader appClientClassLoader = appClientDeploymentContext
0825:                                .getClassLoader();
0826:
0827:                        // pop in all the gbeans declared in the geronimo app client file
0828:                        if (geronimoAppClient != null) {
0829:                            serviceBuilder.build(geronimoAppClient,
0830:                                    appClientDeploymentContext,
0831:                                    appClientDeploymentContext);
0832:                            //deploy the resource adapters specified in the geronimo-application.xml
0833:
0834:                            for (ConnectorModule connectorModule : appClientModule
0835:                                    .getResourceModules()) {
0836:                                getConnectorModuleBuilder().addGBeans(
0837:                                        appClientDeploymentContext,
0838:                                        connectorModule, appClientClassLoader,
0839:                                        repositories);
0840:                            }
0841:                        }
0842:
0843:                        //Holder may be loaded in the "client" module classloader here, whereas
0844:                        //NamingBuilder.INJECTION_KEY.get(buildingContext) returns a Holder loaded in the j2ee-server classloader.
0845:                        Object holder;
0846:                        // add the app client static jndi provider
0847:                        //TODO track resource ref shared and app managed security
0848:                        AbstractName jndiContextName = earContext.getNaming()
0849:                                .createChildName(
0850:                                        appClientDeploymentContext
0851:                                                .getModuleName(),
0852:                                        "StaticJndiContext",
0853:                                        "StaticJndiContext");
0854:                        GBeanData jndiContextGBeanData = new GBeanData(
0855:                                jndiContextName,
0856:                                StaticJndiContextPlugin.GBEAN_INFO);
0857:                        try {
0858:                            Map<NamingBuilder.Key, Object> buildingContext = new HashMap<NamingBuilder.Key, Object>();
0859:                            buildingContext.put(NamingBuilder.GBEAN_NAME_KEY,
0860:                                    jndiContextName);
0861:                            Configuration localConfiguration = appClientDeploymentContext
0862:                                    .getConfiguration();
0863:                            Configuration remoteConfiguration = earContext
0864:                                    .getConfiguration();
0865:
0866:                            if (!appClient.getMetadataComplete()) {
0867:                                // Create a classfinder and populate it for the naming builder(s). The absence of a
0868:                                // classFinder in the module will convey whether metadata-complete is set
0869:                                // (or not)
0870:                                appClientModule
0871:                                        .setClassFinder(createAppClientClassFinder(
0872:                                                appClient, appClientModule));
0873:                            }
0874:
0875:                            namingBuilders.buildNaming(appClient,
0876:                                    geronimoAppClient, appClientModule,
0877:                                    buildingContext);
0878:
0879:                            if (!appClient.getMetadataComplete()) {
0880:                                appClient.setMetadataComplete(true);
0881:                                module.setOriginalSpecDD(module.getSpecDD()
0882:                                        .toString());
0883:                            }
0884:
0885:                            appClientModuleGBeanData.setAttribute(
0886:                                    "deploymentDescriptor", appClientModule
0887:                                            .getOriginalSpecDD());
0888:                            holder = NamingBuilder.INJECTION_KEY
0889:                                    .get(buildingContext);
0890:                            jndiContextGBeanData
0891:                                    .setAttribute("context",
0892:                                            NamingBuilder.JNDI_KEY
0893:                                                    .get(buildingContext));
0894:                        } catch (DeploymentException e) {
0895:                            throw e;
0896:                        } catch (Exception e) {
0897:                            throw new DeploymentException(
0898:                                    "Unable to construct jndi context for AppClientModule GBean "
0899:                                            + appClientModule.getName(), e);
0900:                        }
0901:                        appClientDeploymentContext
0902:                                .addGBean(jndiContextGBeanData);
0903:
0904:                        // finally add the app client container
0905:                        AbstractName appClientContainerName = appClientDeploymentContext
0906:                                .getModuleName();
0907:                        GBeanData appClientContainerGBeanData = new GBeanData(
0908:                                appClientContainerName,
0909:                                AppClientContainer.GBEAN_INFO);
0910:                        try {
0911:                            appClientContainerGBeanData.setAttribute(
0912:                                    "mainClassName", appClientModule
0913:                                            .getMainClassName());
0914:                            appClientContainerGBeanData.setAttribute(
0915:                                    "appClientModuleName", appClientModuleName);
0916:                            String callbackHandlerClassName = null;
0917:                            if (appClient.isSetCallbackHandler()) {
0918:                                callbackHandlerClassName = appClient
0919:                                        .getCallbackHandler().getStringValue()
0920:                                        .trim();
0921:                            }
0922:                            if (geronimoAppClient.isSetCallbackHandler()) {
0923:                                callbackHandlerClassName = geronimoAppClient
0924:                                        .getCallbackHandler().trim();
0925:                            }
0926:                            String realmName = null;
0927:                            if (geronimoAppClient.isSetRealmName()) {
0928:                                realmName = geronimoAppClient.getRealmName()
0929:                                        .trim();
0930:                            }
0931:                            if (callbackHandlerClassName != null
0932:                                    && realmName == null) {
0933:                                throw new DeploymentException(
0934:                                        "You must specify a realm name with the callback handler");
0935:                            }
0936:                            if (realmName != null) {
0937:                                appClientContainerGBeanData.setAttribute(
0938:                                        "realmName", realmName);
0939:                                appClientContainerGBeanData.setAttribute(
0940:                                        "callbackHandlerClassName",
0941:                                        callbackHandlerClassName);
0942:                            } else if (geronimoAppClient.isSetDefaultSubject()) {
0943:                                GerSubjectInfoType subjectInfoType = geronimoAppClient
0944:                                        .getDefaultSubject();
0945:                                SubjectInfo subjectInfo = buildSubjectInfo(subjectInfoType);
0946:                                appClientContainerGBeanData.setAttribute(
0947:                                        "defaultSubject", subjectInfo);
0948:                                appClientContainerGBeanData
0949:                                        .setReferencePattern("CredentialStore",
0950:                                                credentialStoreName);
0951:                            } else if (earContext.getSecurityConfiguration() != null) {
0952:                                //beware a linkage error if we cast this to SubjectInfo
0953:                                String realm = ((SecurityConfiguration) earContext
0954:                                        .getSecurityConfiguration())
0955:                                        .getDefaultSubjectRealm();
0956:                                String id = ((SecurityConfiguration) earContext
0957:                                        .getSecurityConfiguration())
0958:                                        .getDefaultSubjectId();
0959:                                if (realm != null) {
0960:                                    SubjectInfo subjectInfo = new SubjectInfo(
0961:                                            realm, id);
0962:                                    appClientContainerGBeanData.setAttribute(
0963:                                            "defaultSubject", subjectInfo);
0964:                                    appClientContainerGBeanData
0965:                                            .setReferencePattern(
0966:                                                    "CredentialStore",
0967:                                                    credentialStoreName);
0968:                                }
0969:                            }
0970:                            appClientContainerGBeanData.setReferencePattern(
0971:                                    "JNDIContext", jndiContextName);
0972:                            appClientContainerGBeanData.setAttribute("holder",
0973:                                    holder);
0974:
0975:                        } catch (Exception e) {
0976:                            throw new DeploymentException(
0977:                                    "Unable to initialize AppClientModule GBean",
0978:                                    e);
0979:                        }
0980:                        appClientDeploymentContext
0981:                                .addGBean(appClientContainerGBeanData);
0982:
0983:                        //TODO this may definitely not be the best place for this!
0984:                        for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
0985:                            mbe.addGBeans(appClientDeploymentContext,
0986:                                    appClientModule, appClientClassLoader,
0987:                                    repositories);
0988:                        }
0989:
0990:                        // get the configuration data
0991:                        earContext
0992:                                .addAdditionalDeployment(appClientDeploymentContext
0993:                                        .getConfigurationData());
0994:                    } finally {
0995:                        if (appClientDeploymentContext != null) {
0996:                            try {
0997:                                appClientDeploymentContext.close();
0998:                            } catch (IOException e) {
0999:                                //nothing we can do
1000:                            }
1001:                        }
1002:                    }
1003:
1004:                } catch (Throwable e) {
1005:                    File appClientDir = appClientDeploymentContext.getBaseDir();
1006:                    cleanupAppClientDir(appClientDir);
1007:                    if (e instanceof  Error) {
1008:                        throw (Error) e;
1009:                    } else if (e instanceof  DeploymentException) {
1010:                        throw (DeploymentException) e;
1011:                    } else if (e instanceof  Exception) {
1012:                        throw new DeploymentException(e);
1013:                    }
1014:                    throw new Error(e);
1015:                }
1016:            }
1017:
1018:            private ClassFinder createAppClientClassFinder(
1019:                    ApplicationClientType appClient,
1020:                    AppClientModule appClientModule) throws DeploymentException {
1021:
1022:                //------------------------------------------------------------------------------------
1023:                // Find the list of classes from the application-client.xml we want to search for
1024:                // annotations in
1025:                //------------------------------------------------------------------------------------
1026:                List<Class> classes = new ArrayList<Class>();
1027:
1028:                // Get the classloader from the module's EARContext
1029:                ClassLoader classLoader = appClientModule.getEarContext()
1030:                        .getClassLoader();
1031:
1032:                // Get the main class from the module
1033:                String mainClass = appClientModule.getMainClassName();
1034:                Class<?> mainClas;
1035:                try {
1036:                    mainClas = classLoader.loadClass(mainClass);
1037:                } catch (ClassNotFoundException e) {
1038:                    throw new DeploymentException(
1039:                            "AppClientModuleBuilder: Could not load main class: "
1040:                                    + mainClass, e);
1041:                }
1042:                while (mainClas != null && mainClas != Object.class) {
1043:                    classes.add(mainClas);
1044:                    mainClas = mainClas.getSuperclass();
1045:                }
1046:
1047:                // Get the callback-handler from the deployment descriptor
1048:                if (appClient.isSetCallbackHandler()) {
1049:                    FullyQualifiedClassType cls = appClient
1050:                            .getCallbackHandler();
1051:                    Class<?> clas;
1052:                    try {
1053:                        clas = classLoader.loadClass(cls.getStringValue()
1054:                                .trim());
1055:                    } catch (ClassNotFoundException e) {
1056:                        throw new DeploymentException(
1057:                                "AppClientModuleBuilder: Could not load callback-handler class: "
1058:                                        + cls.getStringValue(), e);
1059:                    }
1060:                    classes.add(clas);
1061:                }
1062:
1063:                return new ClassFinder(classes);
1064:            }
1065:
1066:            private SubjectInfo buildSubjectInfo(
1067:                    GerSubjectInfoType defaultSubject) {
1068:                String realmName = defaultSubject.getRealm().trim();
1069:                String id = defaultSubject.getId().trim();
1070:                return new SubjectInfo(realmName, id);
1071:            }
1072:
1073:            public String getSchemaNamespace() {
1074:                return GERAPPCLIENT_NAMESPACE;
1075:            }
1076:
1077:            public void addManifestClassPath(
1078:                    DeploymentContext deploymentContext, JarFile earFile,
1079:                    JarFile jarFile, URI jarFileLocation)
1080:                    throws DeploymentException {
1081:                Manifest manifest;
1082:                try {
1083:                    manifest = jarFile.getManifest();
1084:                } catch (IOException e) {
1085:                    throw new DeploymentException("Could not read manifest: "
1086:                            + jarFileLocation, e);
1087:                }
1088:
1089:                if (manifest == null) {
1090:                    return;
1091:                }
1092:                String manifestClassPath = manifest.getMainAttributes()
1093:                        .getValue(Attributes.Name.CLASS_PATH);
1094:                if (manifestClassPath == null) {
1095:                    return;
1096:                }
1097:
1098:                for (StringTokenizer tokenizer = new StringTokenizer(
1099:                        manifestClassPath, " "); tokenizer.hasMoreTokens();) {
1100:                    String path = tokenizer.nextToken();
1101:
1102:                    URI pathUri;
1103:                    try {
1104:                        pathUri = new URI(path);
1105:                    } catch (URISyntaxException e) {
1106:                        throw new DeploymentException(
1107:                                "Invalid manifest classpath entry: jarFile="
1108:                                        + jarFileLocation + ", path=" + path, e);
1109:                    }
1110:
1111:                    if (!pathUri.getPath().endsWith(".jar")) {
1112:                        throw new DeploymentException(
1113:                                "Manifest class path entries must end with the .jar extension (JAVAEE 5 Section 8.2): jarFile="
1114:                                        + jarFileLocation + ", path=" + path);
1115:                    }
1116:                    if (pathUri.isAbsolute()) {
1117:                        throw new DeploymentException(
1118:                                "Manifest class path entries must be relative (JAVAEE 5 Section 8.2): jarFile="
1119:                                        + jarFileLocation + ", path=" + path);
1120:                    }
1121:
1122:                    // determine the target file
1123:                    URI classPathJarLocation = jarFileLocation.resolve(pathUri);
1124:                    File classPathFile = deploymentContext
1125:                            .getTargetFile(classPathJarLocation);
1126:
1127:                    // we only recuse if the path entry is not already in the output context
1128:                    // this will work for all current cases, but may not work in the future
1129:                    if (!classPathFile.exists()) {
1130:                        // check if the path exists in the earFile
1131:                        ZipEntry entry = earFile.getEntry(classPathJarLocation
1132:                                .getPath());
1133:                        if (entry == null) {
1134:                            throw new DeploymentException(
1135:                                    "Cound not find manifest class path entry: jarFile="
1136:                                            + jarFileLocation + ", path="
1137:                                            + path);
1138:                        }
1139:
1140:                        try {
1141:                            // copy the file into the output context
1142:                            deploymentContext.addFile(classPathJarLocation,
1143:                                    earFile, entry);
1144:                        } catch (IOException e) {
1145:                            throw new DeploymentException(
1146:                                    "Cound not copy manifest class path entry into configuration: jarFile="
1147:                                            + jarFileLocation + ", path="
1148:                                            + path, e);
1149:                        }
1150:
1151:                        JarFile classPathJarFile;
1152:                        try {
1153:                            classPathJarFile = new JarFile(classPathFile);
1154:                        } catch (IOException e) {
1155:                            throw new DeploymentException(
1156:                                    "Manifest class path entries must be a valid jar file (JAVAEE 5 Section 8.2): jarFile="
1157:                                            + jarFileLocation
1158:                                            + ", path="
1159:                                            + path, e);
1160:                        }
1161:
1162:                        // add the client jars of this class path jar
1163:                        addManifestClassPath(deploymentContext, earFile,
1164:                                classPathJarFile, classPathJarLocation);
1165:                    }
1166:                }
1167:            }
1168:
1169:            private boolean cleanupAppClientDir(File configurationDir) {
1170:                LinkedList<String> cannotBeDeletedList = new LinkedList<String>();
1171:
1172:                if (!DeploymentUtil.recursiveDelete(configurationDir,
1173:                        cannotBeDeletedList)) {
1174:                    // Output a message to help user track down file problem
1175:                    log
1176:                            .warn("Unable to delete "
1177:                                    + cannotBeDeletedList.size()
1178:                                    + " files while recursively deleting directory "
1179:                                    + configurationDir.getAbsolutePath()
1180:                                    + LINE_SEP
1181:                                    + "The first file that could not be deleted was:"
1182:                                    + LINE_SEP
1183:                                    + "  "
1184:                                    + (!cannotBeDeletedList.isEmpty() ? cannotBeDeletedList
1185:                                            .getFirst()
1186:                                            : ""));
1187:                    return false;
1188:                }
1189:                return true;
1190:            }
1191:
1192:            public static final GBeanInfo GBEAN_INFO;
1193:
1194:            static {
1195:                GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
1196:                        AppClientModuleBuilder.class,
1197:                        NameFactory.MODULE_BUILDER);
1198:                infoBuilder.addAttribute("defaultClientEnvironment",
1199:                        Environment.class, true, true);
1200:                infoBuilder.addAttribute("defaultServerEnvironment",
1201:                        Environment.class, true, true);
1202:                infoBuilder.addAttribute("transactionManagerObjectName",
1203:                        AbstractNameQuery.class, true);
1204:                infoBuilder.addAttribute("connectionTrackerObjectName",
1205:                        AbstractNameQuery.class, true);
1206:                infoBuilder.addAttribute("corbaGBeanObjectName",
1207:                        AbstractNameQuery.class, true);
1208:                infoBuilder.addAttribute("credentialStoreName",
1209:                        AbstractNameQuery.class, true);
1210:                infoBuilder.addReference("Repositories", Repository.class,
1211:                        "Repository");
1212:                infoBuilder.addReference("ConnectorModuleBuilder",
1213:                        ModuleBuilder.class, NameFactory.MODULE_BUILDER);
1214:                infoBuilder.addReference("ServiceBuilders",
1215:                        NamespaceDrivenBuilder.class,
1216:                        NameFactory.MODULE_BUILDER);
1217:                infoBuilder.addReference("NamingBuilders", NamingBuilder.class,
1218:                        NameFactory.MODULE_BUILDER);
1219:                infoBuilder.addReference("ModuleBuilderExtensions",
1220:                        ModuleBuilderExtension.class,
1221:                        NameFactory.MODULE_BUILDER);
1222:                infoBuilder.addReference("ClientArtifactResolver",
1223:                        ArtifactResolver.class, "ArtifactResolver");
1224:
1225:                infoBuilder.addInterface(ModuleBuilder.class);
1226:
1227:                infoBuilder.setConstructor(new String[] {
1228:                        "transactionManagerObjectName",
1229:                        "connectionTrackerObjectName", "corbaGBeanObjectName",
1230:                        "credentialStoreName", "Repositories",
1231:                        "ConnectorModuleBuilder", "ServiceBuilders",
1232:                        "NamingBuilders", "ModuleBuilderExtensions",
1233:                        "ClientArtifactResolver", "defaultClientEnvironment",
1234:                        "defaultServerEnvironment", });
1235:
1236:                GBEAN_INFO = infoBuilder.getBeanInfo();
1237:            }
1238:
1239:            public static GBeanInfo getGBeanInfo() {
1240:                return GBEAN_INFO;
1241:            }
1242:
1243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.