Source Code Cross Referenced for JSR88_Util.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » configcreator » 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.console.configcreator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.console.configcreator;
017:
018:        import java.io.ByteArrayOutputStream;
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.net.URL;
022:        import java.util.ArrayList;
023:        import java.util.List;
024:        import java.util.jar.JarFile;
025:
026:        import javax.enterprise.deploy.model.DDBean;
027:        import javax.enterprise.deploy.model.DDBeanRoot;
028:        import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
029:        import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
030:        import javax.enterprise.deploy.spi.DeploymentConfiguration;
031:        import javax.enterprise.deploy.spi.DeploymentManager;
032:        import javax.enterprise.deploy.spi.Target;
033:        import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
034:        import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
035:        import javax.enterprise.deploy.spi.exceptions.InvalidModuleException;
036:        import javax.enterprise.deploy.spi.factories.DeploymentFactory;
037:        import javax.enterprise.deploy.spi.status.ProgressObject;
038:        import javax.management.ObjectName;
039:        import javax.portlet.PortletException;
040:        import javax.portlet.PortletRequest;
041:
042:        import org.apache.geronimo.common.DeploymentException;
043:        import org.apache.geronimo.connector.deployment.AdminObjectRefBuilder.AdminObjectRefProcessor;
044:        import org.apache.geronimo.connector.deployment.ResourceRefBuilder.ResourceRefProcessor;
045:        import org.apache.geronimo.console.configcreator.AbstractHandler.ReferenceData;
046:        import org.apache.geronimo.console.configcreator.AbstractHandler.WARConfigData;
047:        import org.apache.geronimo.console.configcreator.JSR77_Util.ReferredData;
048:        import org.apache.geronimo.console.util.PortletManager;
049:        import org.apache.geronimo.deployment.ConfigurationBuilder;
050:        import org.apache.geronimo.deployment.ModuleIDBuilder;
051:        import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryWithKernel;
052:        import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
053:        import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
054:        import org.apache.geronimo.deployment.tools.loader.WebDeployable;
055:        import org.apache.geronimo.j2ee.ApplicationInfo;
056:        import org.apache.geronimo.j2ee.deployment.Module;
057:        import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp;
058:        import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedWebApp;
059:        import org.apache.geronimo.j2ee.deployment.annotation.EJBAnnotationHelper;
060:        import org.apache.geronimo.j2ee.deployment.annotation.HandlerChainAnnotationHelper;
061:        import org.apache.geronimo.j2ee.deployment.annotation.PersistenceContextAnnotationHelper;
062:        import org.apache.geronimo.j2ee.deployment.annotation.PersistenceUnitAnnotationHelper;
063:        import org.apache.geronimo.j2ee.deployment.annotation.ResourceAnnotationHelper;
064:        import org.apache.geronimo.j2ee.deployment.annotation.SecurityAnnotationHelper;
065:        import org.apache.geronimo.j2ee.deployment.annotation.WebServiceRefAnnotationHelper;
066:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
067:        import org.apache.geronimo.kernel.Kernel;
068:        import org.apache.geronimo.kernel.config.ConfigurationManager;
069:        import org.apache.geronimo.kernel.repository.Artifact;
070:        import org.apache.geronimo.naming.deployment.EnvironmentEntryBuilder.EnvEntryRefProcessor;
071:        import org.apache.geronimo.naming.deployment.SwitchingServiceRefBuilder.ServiceRefProcessor;
072:        import org.apache.geronimo.naming.deployment.jsr88.EjbLocalRef;
073:        import org.apache.geronimo.naming.deployment.jsr88.EjbRef;
074:        import org.apache.geronimo.naming.deployment.jsr88.MessageDestination;
075:        import org.apache.geronimo.naming.deployment.jsr88.Pattern;
076:        import org.apache.geronimo.naming.deployment.jsr88.ResourceEnvRef;
077:        import org.apache.geronimo.naming.deployment.jsr88.ResourceRef;
078:        import org.apache.geronimo.web.deployment.WebAppDConfigBean;
079:        import org.apache.geronimo.web.deployment.WebAppDConfigRoot;
080:        import org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder;
081:        import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
082:        import org.apache.geronimo.xbeans.geronimo.security.GerRoleType;
083:        import org.apache.geronimo.xbeans.geronimo.security.GerSecurityType;
084:        import org.apache.geronimo.xbeans.javaee.EjbLocalRefType;
085:        import org.apache.geronimo.xbeans.javaee.EjbRefType;
086:        import org.apache.geronimo.xbeans.javaee.MessageDestinationType;
087:        import org.apache.geronimo.xbeans.javaee.ResourceEnvRefType;
088:        import org.apache.geronimo.xbeans.javaee.ResourceRefType;
089:        import org.apache.geronimo.xbeans.javaee.SecurityRoleType;
090:        import org.apache.geronimo.xbeans.javaee.ServiceRefType;
091:        import org.apache.geronimo.xbeans.javaee.WebAppType;
092:        import org.apache.xbean.finder.ClassFinder;
093:
094:        /**
095:         * Util class for JSR-88 related functions
096:         * 
097:         * @version $Rev: 611338 $ $Date: 2008-01-11 16:42:22 -0800 (Fri, 11 Jan 2008) $
098:         */
099:        public class JSR88_Util {
100:
101:            private static void parseAnnotations(AnnotatedApp annotatedApp,
102:                    ClassFinder classFinder) throws Exception {
103:                ResourceAnnotationHelper.processAnnotations(annotatedApp,
104:                        classFinder, EnvEntryRefProcessor.INSTANCE);
105:                WebServiceRefAnnotationHelper.processAnnotations(annotatedApp,
106:                        classFinder);
107:                HandlerChainAnnotationHelper.processAnnotations(annotatedApp,
108:                        classFinder);
109:                ResourceAnnotationHelper.processAnnotations(annotatedApp,
110:                        classFinder, ServiceRefProcessor.INSTANCE);
111:                ResourceAnnotationHelper.processAnnotations(annotatedApp,
112:                        classFinder, AdminObjectRefProcessor.INSTANCE);
113:                ResourceAnnotationHelper.processAnnotations(annotatedApp,
114:                        classFinder, ResourceRefProcessor.INSTANCE);
115:                PersistenceContextAnnotationHelper.processAnnotations(
116:                        annotatedApp, classFinder);
117:                PersistenceUnitAnnotationHelper.processAnnotations(
118:                        annotatedApp, classFinder);
119:                EJBAnnotationHelper.processAnnotations(annotatedApp,
120:                        classFinder);
121:                if (annotatedApp instanceof  AnnotatedWebApp) {
122:                    SecurityAnnotationHelper.processAnnotations(
123:                            ((AnnotatedWebApp) annotatedApp).getWebApp(),
124:                            classFinder);
125:                }
126:            }
127:
128:            private static ConfigurationBuilder getConfigurationBuilder(
129:                    PortletRequest request) {
130:                Object[] builders = PortletManager.getGBeansImplementing(
131:                        request, ConfigurationBuilder.class);
132:                ConfigurationBuilder configurationBuilder = null;
133:                for (int i = 0; i < builders.length; i++) {
134:                    ObjectName objectName = PortletManager.getNameFor(request,
135:                            builders[i]).getObjectName();
136:                    if ("EARBuilder".equalsIgnoreCase(objectName
137:                            .getKeyProperty(NameFactory.J2EE_NAME))) {
138:                        configurationBuilder = (ConfigurationBuilder) builders[i];
139:                        break;
140:                    }
141:                }
142:                return configurationBuilder;
143:            }
144:
145:            private static ApplicationInfo createApplicationInfo(
146:                    PortletRequest request, URL moduleUrl) throws Exception {
147:                ConfigurationBuilder configurationBuilderBuilder = getConfigurationBuilder(request);
148:                File moduleFile = new File(moduleUrl.toURI());
149:                JarFile moduleJar = new JarFile(moduleFile);
150:                ApplicationInfo applicationInfo = (ApplicationInfo) configurationBuilderBuilder
151:                        .getDeploymentPlan(null, moduleJar,
152:                                new ModuleIDBuilder());
153:                return applicationInfo;
154:            }
155:
156:            public static void parseWarReferences(PortletRequest request,
157:                    WARConfigData data, URL warUrl) throws Exception {
158:                WebDeployable webDeployable = new WebDeployable(warUrl);
159:                ClassLoader classLoader = webDeployable.getModuleLoader();
160:
161:                ApplicationInfo applicationInfo = createApplicationInfo(
162:                        request, warUrl);
163:                Module module = (Module) (applicationInfo.getModules()
164:                        .toArray()[0]);
165:                WebAppType webApp = (WebAppType) module.getSpecDD();
166:
167:                ClassFinder classFinder = null;
168:                try {
169:                    classFinder = AbstractWebModuleBuilder
170:                            .createWebAppClassFinder(webApp, classLoader);
171:                    // classFinder = new ClassFinder(classLoader);
172:                } catch (DeploymentException e1) {
173:                    // Some of the class types referred in the WAR cannot be resolved.
174:                    // A typical case would be references to EJBs already deployed into the system, and
175:                    // hence not packaged inside WEB-INF/lib directory of WAR.
176:                    // try adding all EJBs deployed in the system as parents of this WAR, and
177:                    // see if referred classes can now be successfully resolved
178:
179:                    classLoader = new WebDeployable(warUrl,
180:                            getEjbClassLoaders(request)).getModuleLoader();
181:                    try {
182:                        classFinder = AbstractWebModuleBuilder
183:                                .createWebAppClassFinder(webApp, classLoader);
184:                    } catch (DeploymentException e2) {
185:                        return;
186:                    }
187:                }
188:                AnnotatedApp annotatedApp = module.getAnnotatedApp();
189:                parseAnnotations(annotatedApp, classFinder);
190:
191:                //DDBeanRoot ddBeanRoot = webDeployable.getDDBeanRoot();
192:                //DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];
193:
194:                EjbRefType[] ejbRefs = annotatedApp.getEjbRefArray();
195:                for (int i = 0; i < ejbRefs.length; i++) {
196:                    String refName = ejbRefs[i].getEjbRefName()
197:                            .getStringValue();
198:                    data.getEjbRefs().add(new ReferenceData(refName));
199:                }
200:                /*DDBean[] ddBeans = ddBean.getChildBean("ejb-ref");
201:                for (int i = 0; ddBeans != null && i < ddBeans.length; i++) {
202:                    String refName = ddBeans[i].getChildBean("ejb-ref-name")[0].getText();
203:                    data.getEjbRefs().add(new ReferenceData(refName));
204:                }*/
205:
206:                EjbLocalRefType[] ejbLocalRefs = annotatedApp
207:                        .getEjbLocalRefArray();
208:                for (int i = 0; i < ejbLocalRefs.length; i++) {
209:                    String refName = ejbLocalRefs[i].getEjbRefName()
210:                            .getStringValue();
211:                    data.getEjbLocalRefs().add(new ReferenceData(refName));
212:                }
213:                /*ddBeans = ddBean.getChildBean("ejb-local-ref");
214:                for (int i = 0; ddBeans != null && i < ddBeans.length; i++) {
215:                    String refName = ddBeans[i].getChildBean("ejb-ref-name")[0].getText();
216:                    data.getEjbLocalRefs().add(new ReferenceData(refName));
217:                }*/
218:
219:                ResourceRefType[] resourceRefs = annotatedApp
220:                        .getResourceRefArray();
221:                for (int i = 0; i < resourceRefs.length; i++) {
222:                    String refName = resourceRefs[i].getResRefName()
223:                            .getStringValue();
224:                    String refType = resourceRefs[i].getResType()
225:                            .getStringValue();
226:                    if ("javax.sql.DataSource".equalsIgnoreCase(refType)) {
227:                        data.getJdbcPoolRefs().add(new ReferenceData(refName));
228:                    } else if ("javax.jms.ConnectionFactory"
229:                            .equalsIgnoreCase(refType)
230:                            || "javax.jms.QueueConnectionFactory"
231:                                    .equalsIgnoreCase(refType)
232:                            || "javax.jms.TopicConnectionFactory"
233:                                    .equalsIgnoreCase(refType)) {
234:                        data.getJmsConnectionFactoryRefs().add(
235:                                new ReferenceData(refName));
236:                    } else if ("javax.mail.Session".equalsIgnoreCase(refType)) {
237:                        data.getJavaMailSessionRefs().add(
238:                                new ReferenceData(refName));
239:                    }
240:                }
241:                /*ddBeans = ddBean.getChildBean("resource-ref");
242:                for (int i = 0; ddBeans != null && i < ddBeans.length; i++) {
243:                    String refName = ddBeans[i].getChildBean("res-ref-name")[0].getText();
244:                    String refType = ddBeans[i].getChildBean("res-type")[0].getText();
245:                    if ("javax.sql.DataSource".equalsIgnoreCase(refType)) {
246:                        data.getJdbcPoolRefs().add(new ReferenceData(refName));
247:                    } else if ("javax.jms.ConnectionFactory".equalsIgnoreCase(refType)
248:                            || "javax.jms.QueueConnectionFactory".equalsIgnoreCase(refType)
249:                            || "javax.jms.TopicConnectionFactory".equalsIgnoreCase(refType)) {
250:                        data.getJmsConnectionFactoryRefs().add(new ReferenceData(refName));
251:                    }
252:                }*/
253:
254:                ServiceRefType[] serviceRefs = annotatedApp
255:                        .getServiceRefArray();
256:                for (int i = 0; i < serviceRefs.length; i++) {
257:                    String refName = serviceRefs[i].getServiceRefName()
258:                            .getStringValue();
259:                    GerServiceRefType serviceRef = GerServiceRefType.Factory
260:                            .newInstance();
261:                    serviceRef.setServiceRefName(refName);
262:                    data.getWebServiceRefs().add(serviceRef);
263:                }
264:
265:                ResourceEnvRefType[] resourceEnvRefs = annotatedApp
266:                        .getResourceEnvRefArray();
267:                for (int i = 0; i < resourceEnvRefs.length; i++) {
268:                    String refName = resourceEnvRefs[i].getResourceEnvRefName()
269:                            .getStringValue();
270:                    ReferenceData refData = new ReferenceData(refName);
271:                    refData.setRefLink(refName);
272:                    data.getJmsDestinationRefs().add(refData);
273:                }
274:                if (annotatedApp instanceof  AnnotatedWebApp) {
275:                    WebAppType webApp2 = ((AnnotatedWebApp) annotatedApp)
276:                            .getWebApp();
277:                    MessageDestinationType[] messageDestinations = webApp2
278:                            .getMessageDestinationArray();
279:                    for (int i = 0; i < messageDestinations.length; i++) {
280:                        String refName = messageDestinations[i]
281:                                .getMessageDestinationName().getStringValue();
282:                        ReferenceData refData = new ReferenceData(refName);
283:                        refData.setRefLink(refName);
284:                        data.getMessageDestinations().add(refData);
285:                    }
286:
287:                    SecurityRoleType[] securityRoles = webApp2
288:                            .getSecurityRoleArray();
289:                    if (securityRoles.length > 0) {
290:                        data.setSecurity(GerSecurityType.Factory.newInstance());
291:                        data.getSecurity().addNewRoleMappings();
292:                    }
293:                    for (int i = 0; i < securityRoles.length; i++) {
294:                        String roleName = securityRoles[i].getRoleName()
295:                                .getStringValue();
296:                        GerRoleType role = data.getSecurity().getRoleMappings()
297:                                .addNewRole();
298:                        role.setRoleName(roleName);
299:                    }
300:                }
301:                /*ddBeans = ddBean.getChildBean("message-destination");
302:                for (int i = 0; ddBeans != null && i < ddBeans.length; i++) {
303:                    String refName = ddBeans[i].getChildBean("message-destination-name")[0].getText();
304:                    ReferenceData refData = new ReferenceData(refName);
305:                    refData.setRefLink(refName);
306:                    data.getJmsDestinationRefs().add(refData);
307:                }*/
308:            }
309:
310:            private static List getEjbClassLoaders(PortletRequest request) {
311:                List deployedEjbs = JSR77_Util.getDeployedEJBs(request);
312:                List configurations = new ArrayList();
313:                for (int i = 0; i < deployedEjbs.size(); i++) {
314:                    String ejbPatternName = ((ReferredData) deployedEjbs.get(i))
315:                            .getPatternName();
316:                    configurations.add(getDependencyString(ejbPatternName));
317:                }
318:                return getConfigClassLoaders(configurations);
319:            }
320:
321:            private static List getConfigClassLoaders(List configurationNames) {
322:                List classLoaders = new ArrayList();
323:                ConfigurationManager configurationManager = PortletManager
324:                        .getConfigurationManager();
325:                for (int i = 0; i < configurationNames.size(); i++) {
326:                    Artifact configurationId = Artifact
327:                            .create((String) configurationNames.get(i));
328:                    classLoaders.add(configurationManager.getConfiguration(
329:                            configurationId).getConfigurationClassLoader());
330:                }
331:                return classLoaders;
332:            }
333:
334:            public static String getDependencyString(String patternString) {
335:                String[] elements = patternString.split("/", 6);
336:                return elements[0] + "/" + elements[1] + "/" + elements[2]
337:                        + "/" + elements[3];
338:            }
339:
340:            public static String createDeploymentPlan(PortletRequest request,
341:                    WARConfigData data, URL WarUrl) throws IOException,
342:                    DDBeanCreateException, InvalidModuleException,
343:                    ConfigurationException, DeploymentManagerCreationException {
344:                WebDeployable webDeployable = new WebDeployable(WarUrl);
345:                DDBeanRoot ddBeanRoot = webDeployable.getDDBeanRoot();
346:                DDBean ddBean = ddBeanRoot.getChildBean("web-app")[0];
347:
348:                Kernel kernel = PortletManager.getKernel();
349:                DeploymentFactory factory = new DeploymentFactoryWithKernel(
350:                        kernel);
351:                DeploymentManager deploymentManager = factory
352:                        .getDeploymentManager("deployer:geronimo:inVM", null,
353:                                null);
354:                DeploymentConfiguration deploymentConfiguration = deploymentManager
355:                        .createConfiguration(webDeployable);
356:                WebAppDConfigRoot configRoot = (WebAppDConfigRoot) deploymentConfiguration
357:                        .getDConfigBeanRoot(ddBeanRoot);
358:                WebAppDConfigBean webApp = (WebAppDConfigBean) configRoot
359:                        .getDConfigBean(ddBean);
360:
361:                webApp.setContextRoot(data.getContextRoot());
362:
363:                EnvironmentData environment = new EnvironmentData();
364:                webApp.setEnvironment(environment);
365:                org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
366:                environment.setConfigId(configId);
367:                configId.setGroupId(data.getGroupId());
368:                configId.setArtifactId(data.getArtifactId());
369:                configId.setVersion(data.getVersion());
370:                configId.setType(data.getType());
371:                int numDependencies = data.getDependencies().size();
372:                if (numDependencies > 0) {
373:                    org.apache.geronimo.deployment.service.jsr88.Artifact[] dependencies = new org.apache.geronimo.deployment.service.jsr88.Artifact[numDependencies];
374:                    for (int i = 0; i < numDependencies; i++) {
375:                        dependencies[i] = new org.apache.geronimo.deployment.service.jsr88.Artifact();
376:                    }
377:                    environment.setDependencies(dependencies);
378:                    for (int i = 0; i < numDependencies; i++) {
379:                        Artifact artifact = Artifact.create(((String) data
380:                                .getDependencies().get(i)).trim());
381:                        org.apache.geronimo.deployment.service.jsr88.Artifact dep = dependencies[i];
382:                        dep.setArtifactId(artifact.getArtifactId());
383:                        if (artifact.getGroupId() != null) {
384:                            dep.setGroupId(artifact.getGroupId());
385:                        }
386:                        if (artifact.getType() != null) {
387:                            dep.setType(artifact.getType());
388:                        }
389:                        if (artifact.getVersion() != null) {
390:                            dep.setVersion(artifact.getVersion().toString());
391:                        }
392:                    }
393:                }
394:                String hiddenClassesString = data.getHiddenClasses();
395:                if (hiddenClassesString != null
396:                        && hiddenClassesString.length() > 0) {
397:                    String[] hiddenClasses = getNonEmptyStrings(hiddenClassesString
398:                            .split(";"));
399:                    if (hiddenClasses.length > 0) {
400:                        environment.setHiddenClasses(hiddenClasses);
401:                    }
402:                }
403:                String nonOverridableClassesString = data
404:                        .getNonOverridableClasses();
405:                if (nonOverridableClassesString != null
406:                        && nonOverridableClassesString.length() > 0) {
407:                    String[] nonOverridableClasses = getNonEmptyStrings(nonOverridableClassesString
408:                            .split(";"));
409:                    if (nonOverridableClasses.length > 0) {
410:                        environment
411:                                .setNonOverridableClasses(nonOverridableClasses);
412:                    }
413:                }
414:                if (data.isInverseClassLoading()) {
415:                    environment.setInverseClassLoading(true);
416:                }
417:
418:                int numEjbRefs = data.getEjbRefs().size();
419:                if (numEjbRefs > 0) {
420:                    EjbRef[] ejbRefs = new EjbRef[numEjbRefs];
421:                    for (int i = 0; i < numEjbRefs; i++) {
422:                        ejbRefs[i] = new EjbRef();
423:                    }
424:                    webApp.setEjbRefs(ejbRefs);
425:                    for (int i = 0; i < numEjbRefs; i++) {
426:                        EjbRef ejbRef = ejbRefs[i];
427:                        ReferenceData referenceData = (ReferenceData) data
428:                                .getEjbRefs().get(i);
429:                        ejbRef.setRefName(referenceData.getRefName());
430:                        ejbRef.setPattern(createPattern(referenceData
431:                                .getRefLink()));
432:                    }
433:                }
434:
435:                int numEjbLocalRefs = data.getEjbLocalRefs().size();
436:                if (numEjbLocalRefs > 0) {
437:                    EjbLocalRef[] ejbLocalRefs = new EjbLocalRef[numEjbLocalRefs];
438:                    for (int i = 0; i < numEjbLocalRefs; i++) {
439:                        ejbLocalRefs[i] = new EjbLocalRef();
440:                    }
441:                    webApp.setEjbLocalRefs(ejbLocalRefs);
442:                    for (int i = 0; i < numEjbLocalRefs; i++) {
443:                        EjbLocalRef ejbLocalRef = ejbLocalRefs[i];
444:                        ReferenceData referenceData = (ReferenceData) data
445:                                .getEjbLocalRefs().get(i);
446:                        ejbLocalRef.setRefName(referenceData.getRefName());
447:                        ejbLocalRef.setPattern(createPattern(referenceData
448:                                .getRefLink()));
449:                    }
450:                }
451:
452:                int numResourceRefs = data.getJdbcPoolRefs().size()
453:                        + data.getJmsConnectionFactoryRefs().size()
454:                        + data.getJavaMailSessionRefs().size();
455:                if (numResourceRefs > 0) {
456:                    ResourceRef[] resourceRefs = new ResourceRef[numResourceRefs];
457:                    for (int i = 0; i < numResourceRefs; i++) {
458:                        resourceRefs[i] = new ResourceRef();
459:                    }
460:                    webApp.setResourceRefs(resourceRefs);
461:                    int i = 0;
462:                    for (int l = 0; l < data.getJdbcPoolRefs().size(); l++, i++) {
463:                        ResourceRef resourceRef = resourceRefs[i];
464:                        ReferenceData referenceData = (ReferenceData) data
465:                                .getJdbcPoolRefs().get(l);
466:                        resourceRef.setRefName(referenceData.getRefName());
467:                        resourceRef.setPattern(createPattern(referenceData
468:                                .getRefLink()));
469:                    }
470:                    for (int m = 0; m < data.getJmsConnectionFactoryRefs()
471:                            .size(); m++, i++) {
472:                        ResourceRef resourceRef = resourceRefs[i];
473:                        ReferenceData referenceData = (ReferenceData) data
474:                                .getJmsConnectionFactoryRefs().get(m);
475:                        resourceRef.setRefName(referenceData.getRefName());
476:                        resourceRef.setPattern(createPattern(referenceData
477:                                .getRefLink()));
478:                    }
479:                    for (int n = 0; n < data.getJavaMailSessionRefs().size(); n++, i++) {
480:                        ResourceRef resourceRef = resourceRefs[i];
481:                        ReferenceData referenceData = (ReferenceData) data
482:                                .getJavaMailSessionRefs().get(n);
483:                        resourceRef.setRefName(referenceData.getRefName());
484:                        resourceRef.setPattern(createPattern(referenceData
485:                                .getRefLink()));
486:                    }
487:                }
488:
489:                int numMessageDestinations = data.getMessageDestinations()
490:                        .size();
491:                if (numMessageDestinations > 0) {
492:                    MessageDestination[] messageDestinations = new MessageDestination[numMessageDestinations];
493:                    for (int i = 0; i < numMessageDestinations; i++) {
494:                        messageDestinations[i] = new MessageDestination();
495:                    }
496:                    webApp.setMessageDestinations(messageDestinations);
497:                    for (int i = 0; i < numMessageDestinations; i++) {
498:                        MessageDestination messageDestination = messageDestinations[i];
499:                        ReferenceData referenceData = (ReferenceData) data
500:                                .getMessageDestinations().get(i);
501:                        messageDestination
502:                                .setMessageDestinationName(referenceData
503:                                        .getRefName());
504:                        // messageDestination.setPattern(createPattern(referenceData.getRefLink()));
505:                        messageDestination.setAdminObjectLink(createPattern(
506:                                referenceData.getRefLink()).getName());
507:                    }
508:                }
509:
510:                int numResourceEnvRefs = data.getJmsDestinationRefs().size();
511:                if (numResourceEnvRefs > 0) {
512:                    ResourceEnvRef[] resourceEnvRefs = new ResourceEnvRef[numResourceEnvRefs];
513:                    for (int i = 0; i < numResourceEnvRefs; i++) {
514:                        resourceEnvRefs[i] = new ResourceEnvRef();
515:                    }
516:                    webApp.setResourceEnvRefs(resourceEnvRefs);
517:                    for (int i = 0; i < numResourceEnvRefs; i++) {
518:                        ResourceEnvRef resourceEnvRef = resourceEnvRefs[i];
519:                        ReferenceData referenceData = (ReferenceData) data
520:                                .getJmsDestinationRefs().get(i);
521:                        resourceEnvRef.setRefName(referenceData.getRefName());
522:                        resourceEnvRef.setPattern(createPattern(referenceData
523:                                .getRefLink()));
524:                        // resourceEnvRef.setAdminObjectLink(createPattern(referenceData.getRefLink()).getName());
525:                    }
526:                }
527:
528:                int numWebServiceRefs = data.getWebServiceRefs().size();
529:                if (numWebServiceRefs > 0) {
530:                    webApp.setServiceRefs(data.getWebServiceRefs().toArray(
531:                            new GerServiceRefType[numWebServiceRefs]));
532:                }
533:
534:                if (data.getSecurity() != null) {
535:                    webApp.setSecurityRealmName(data.getSecurityRealmName());
536:                    webApp.setSecurity(data.getSecurity());
537:                }
538:
539:                ByteArrayOutputStream out = new ByteArrayOutputStream();
540:                deploymentConfiguration.save(out);
541:                out.close();
542:                return new String(out.toByteArray(), "US-ASCII");
543:            }
544:
545:            private static Pattern createPattern(String patternString) {
546:                Pattern pattern = new Pattern();
547:                String[] elements = patternString.split("/", 6);
548:                pattern.setGroupId(elements[0]);
549:                pattern.setArtifactId(elements[1]);
550:                pattern.setVersion(elements[2]);
551:                pattern.setType(elements[3]);
552:                pattern.setModule(elements[4]);
553:                pattern.setName(elements[5]);
554:                return pattern;
555:            }
556:
557:            private static String[] getNonEmptyStrings(String[] strings) {
558:                ArrayList list = new ArrayList();
559:                for (int i = 0; i < strings.length; i++) {
560:                    if (strings[i].trim().length() > 0)
561:                        list.add(strings[i].trim());
562:                }
563:                return (String[]) list.toArray(new String[list.size()]);
564:            }
565:
566:            public static String[] deploy(PortletRequest actionRequest,
567:                    File moduleFile, File planFile) throws PortletException {
568:                // TODO this is a duplicate of the code from
569:                // org.apache.geronimo.console.configmanager.DeploymentPortlet.processAction()
570:                // TODO need to eliminate this duplicate code
571:                DeploymentFactoryManager dfm = DeploymentFactoryManager
572:                        .getInstance();
573:                String[] statusMsgs = new String[2];
574:                try {
575:                    DeploymentManager mgr = dfm.getDeploymentManager(
576:                            "deployer:geronimo:inVM", null, null);
577:                    try {
578:                        if (mgr instanceof  JMXDeploymentManager) {
579:                            ((JMXDeploymentManager) mgr).setLogConfiguration(
580:                                    false, true);
581:                        }
582:
583:                        Target[] targets = mgr.getTargets();
584:                        if (null == targets) {
585:                            throw new IllegalStateException(
586:                                    "No target to distribute to");
587:                        }
588:                        targets = new Target[] { targets[0] };
589:
590:                        ProgressObject progress = mgr.distribute(targets,
591:                                moduleFile, planFile);
592:                        while (progress.getDeploymentStatus().isRunning()) {
593:                            Thread.sleep(100);
594:                        }
595:
596:                        String abbrStatusMessage;
597:                        String fullStatusMessage = null;
598:                        if (progress.getDeploymentStatus().isCompleted()) {
599:                            abbrStatusMessage = "The application was successfully deployed.<br/>";
600:                            // start installed app/s
601:                            progress = mgr.start(progress
602:                                    .getResultTargetModuleIDs());
603:                            while (progress.getDeploymentStatus().isRunning()) {
604:                                Thread.sleep(100);
605:                            }
606:                            abbrStatusMessage += "The application was successfully started";
607:                        } else {
608:                            fullStatusMessage = progress.getDeploymentStatus()
609:                                    .getMessage();
610:                            // for the abbreviated status message clip off everything
611:                            // after the first line, which in most cases means the gnarly stacktrace
612:                            abbrStatusMessage = "Deployment failed:<br/>"
613:                                    + fullStatusMessage.substring(0,
614:                                            fullStatusMessage.indexOf('\n'));
615:                        }
616:                        statusMsgs[0] = abbrStatusMessage;
617:                        statusMsgs[1] = fullStatusMessage;
618:                    } finally {
619:                        mgr.release();
620:                    }
621:                } catch (Exception e) {
622:                    throw new PortletException(e);
623:                }
624:                return statusMsgs;
625:            }
626:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.