Source Code Cross Referenced for EjbLoader.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » ejb » load » 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 » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.ejb.load 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        /*
042:         * EjbLoader.java
043:         *
044:         * Created on April 28, 2004, 5:39 PM
045:         */
046:
047:        package org.netbeans.modules.visualweb.ejb.load;
048:
049:        import java.io.File;
050:        import java.lang.reflect.Method;
051:        import java.net.URLClassLoader;
052:        import java.util.ArrayList;
053:        import java.util.Collection;
054:        import java.util.HashMap;
055:        import java.util.HashSet;
056:        import java.util.Iterator;
057:        import java.util.List;
058:        import java.util.Map;
059:        import java.util.Set;
060:
061:        import org.netbeans.modules.visualweb.ejb.datamodel.EjbContainerVendor;
062:        import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
063:        import org.netbeans.modules.visualweb.ejb.datamodel.EjbInfo;
064:        import org.netbeans.modules.visualweb.ejb.datamodel.MethodInfo;
065:        import org.netbeans.modules.visualweb.ejb.datamodel.MethodParam;
066:        import org.netbeans.modules.visualweb.ejb.datamodel.MethodReturn;
067:        import org.netbeans.modules.visualweb.ejb.ui.ConfigureMethodsDialog;
068:        import org.netbeans.modules.visualweb.ejb.util.Util;
069:        import org.openide.ErrorManager;
070:        import org.openide.modules.InstalledFileLocator;
071:        import org.openide.util.NbBundle;
072:
073:        /**
074:         * This class is used to load the jar file into rave and extract
075:         * the necessary information regarding the Ejbs from the jar.
076:         */
077:        public class EjbLoader {
078:
079:            // The package where all the client wrapper will be
080:            // FIXME The icon code needs to be fixed. Right now it's either broken or working by accident.
081:            public static final String CLIENT_WRAPPER_PACKAGE_NAME = "org.netbeans.modules.visualweb.ejb";
082:
083:            // Two jar files needed for compiling the generated data provider and wrapper classes
084:            public static final String dataproviderJar = InstalledFileLocator
085:                    .getDefault().locate("modules/ext/dataprovider.jar", null,
086:                            false).getAbsolutePath(); // NOI18N
087:            public static final String designTimeJar = InstalledFileLocator
088:                    .getDefault().locate("modules/ext/designtime.jar", null,
089:                            false).getAbsolutePath(); // NOI18N
090:            public static final String designTimeBaseJar = InstalledFileLocator
091:                    .getDefault().locate("modules/ext/designtime-base.jar",
092:                            null, false).getAbsolutePath(); // NOI18N
093:            public static final String propEditorsJar = InstalledFileLocator
094:                    .getDefault()
095:                    .locate("modules/ext/editors.jar", null, false)
096:                    .getAbsolutePath(); // NOI18N
097:
098:            private EjbGroup ejbGroup;
099:            private URLClassLoader classloader;
100:            private String warningMsg;
101:
102:            public EjbLoader(EjbGroup ejbGroup) {
103:                this .ejbGroup = ejbGroup;
104:            }
105:
106:            public void load() throws EjbLoadException {
107:                // Extract the deployment descriptors from the jar files (client jar file + dd location file if there is one )
108:
109:                ArrayList jarFiles = new ArrayList();
110:                jarFiles.addAll(ejbGroup.getClientJarFiles());
111:                if (ejbGroup.getDDLocationFile() != null)
112:                    jarFiles.add(ejbGroup.getDDLocationFile());
113:
114:                DeploymentDescriptorExtractor extractor = new DeploymentDescriptorExtractor(
115:                        jarFiles);
116:                Map descriptors = extractor.getDeploymentDescriptors();
117:
118:                // Log a warning if there is no deployment descriptor found
119:                if (descriptors.isEmpty()) {
120:                    ErrorManager
121:                            .getDefault()
122:                            .getInstance(
123:                                    "org.netbeans.modules.visualweb.ejb.load.EjbLoader")
124:                            .log(ErrorManager.WARNING,
125:                                    "NO EJB deployment descriptors found");
126:
127:                    // No EJB deployment descriptors found in client jar files and/or deployment descriptors.
128:                    // Looking for a reference to {0}. Add a Jar or Ear file containing deployment descriptors.
129:                    String ddFileName = EjbContainerVendor
130:                            .getVendorDDFileName(ejbGroup.getAppServerVendor());
131:                    String msg = NbBundle.getMessage(EjbLoader.class,
132:                            "NO_DEPLOYMENT_DESCRIPTOR", ddFileName);
133:
134:                    throw new EjbLoadException(EjbLoadException.USER_ERROR, msg);
135:                } else {
136:                    // Make sure that the user has selected the correct container for the jar file
137:                    validateAppServerSelection(descriptors);
138:
139:                    // Load classes from the client jars
140:                    classloader = EjbLoaderHelper
141:                            .getEjbGroupClassLoader(ejbGroup);
142:
143:                    // Cleanup the classes list extracted from the client jars and set them to the ejbgroup
144:                    setAllClazz(extractor.getAllClazz());
145:
146:                    // Populate the session beans with business methods
147:                    // Note: entity beans and mdbs later
148:                    populateBeanInfo(descriptors);
149:
150:                    // Check to see whether there are any session EJBs in the provided
151:                    // client jars. If not, warning here
152:                    if (ejbGroup.getSessionBeans() == null
153:                            || ejbGroup.getSessionBeans().isEmpty()) {
154:                        ErrorManager
155:                                .getDefault()
156:                                .getInstance(
157:                                        "org.netbeans.modules.visualweb.ejb.load.EjbLoader")
158:                                .log(ErrorManager.ERROR,
159:                                        "NO session EJBs found");
160:
161:                        // No session EJBs found in given client jar files.
162:                        // The given client jar files do not contain any session EJBs
163:                        String msg = NbBundle.getMessage(EjbLoader.class,
164:                                "NO_SESSION_EJBS_FOUND");
165:
166:                        // If we have skipped some EJBs, then add the information to the message.
167:                        if (warningMsg != null)
168:                            msg = msg + " " + warningMsg;
169:
170:                        throw new EjbLoadException(EjbLoadException.USER_ERROR,
171:                                msg);
172:                    }
173:
174:                    // Lastly (has be be last), check whether there is any warning we should give.
175:                    // For now, the only warning is if there are any EJBs skipped
176:                    if (warningMsg != null)
177:                        throw new EjbLoadException(EjbLoadException.WARNING,
178:                                warningMsg);
179:
180:                    // Got all the information. Delete the tmp files
181:                    //cleanTempFiles( descriptors, extractor.getTmpJarFiles() );
182:                }
183:            }
184:
185:            public boolean reload() throws EjbLoadException {
186:
187:                // Before anything, lets check the existence of all the jar files
188:                checkFileExistence();
189:
190:                // Lets remember the original ejbs so that we can copy over the method parameter names 
191:                // and return collection element classes
192:                Collection origEjbs = ejbGroup.getSessionBeans();
193:
194:                // Clean up the old data
195:                ejbGroup.setSessionBeans(null);
196:                ejbGroup.setEntityBeans(null);
197:                ejbGroup.setMDBs(null);
198:                ejbGroup.setAllClazz(new HashSet());
199:
200:                // Do the load all over again
201:                load();
202:
203:                if (ejbGroup.hasAnyConfigurableMethod()) {
204:                    // Need to copy over the information (parameter names and return collection element classes) from the origial group
205:                    // if possible
206:                    Collection newEjbs = ejbGroup.getSessionBeans();
207:                    copyOverUserInputs(origEjbs, newEjbs);
208:
209:                    // Popup the dialog to allow configuring the method if there are anything to configure
210:                    // When "OK" in the dialog is clicked, the wrapper classes will be regenerated
211:                    ConfigureMethodsDialog dialog = new ConfigureMethodsDialog(
212:                            ejbGroup, true);
213:                    dialog.showDialog();
214:
215:                    if (dialog.isCancelled())
216:                        return false;
217:                    else {
218:                        ejbGroup = dialog.getEjbGroup();
219:                        return true;
220:                    }
221:                } else {
222:                    // Regenerate the classes             
223:                    createWrapperClientBeans();
224:                    return true;
225:                }
226:            }
227:
228:            private void copyOverUserInputs(Collection origEjbs,
229:                    Collection newEjbs) {
230:                // Convert the collection to map
231:                Map origMap = new HashMap();
232:                for (Iterator iter = origEjbs.iterator(); iter.hasNext();) {
233:                    EjbInfo ejb = (EjbInfo) iter.next();
234:                    origMap.put(ejb.getJNDIName(), ejb);
235:                }
236:
237:                for (Iterator iter = newEjbs.iterator(); iter.hasNext();) {
238:                    EjbInfo ejb = (EjbInfo) iter.next();
239:                    EjbInfo origEjb = (EjbInfo) origMap.get(ejb.getJNDIName());
240:
241:                    // Must be a new ejb just added. Move on
242:                    if (origEjb == null)
243:                        continue;
244:
245:                    copyOverMethodConfiguration(origEjb.getMethods(), ejb
246:                            .getMethods());
247:                }
248:            }
249:
250:            private void copyOverMethodConfiguration(ArrayList origMethods,
251:                    ArrayList newMethods) {
252:                Map origMap = new HashMap();
253:                for (Iterator iter = origMethods.iterator(); iter.hasNext();) {
254:                    MethodInfo method = (MethodInfo) iter.next();
255:                    origMap.put(method.getSignature(), method);
256:                }
257:
258:                for (Iterator iter = newMethods.iterator(); iter.hasNext();) {
259:                    MethodInfo method = (MethodInfo) iter.next();
260:
261:                    // Time to get the information
262:                    if (method.isMethodConfigurable()) {
263:                        MethodInfo origMethod = (MethodInfo) origMap.get(method
264:                                .getSignature());
265:
266:                        if (origMethod == null)
267:                            continue;
268:
269:                        // Parameter names first
270:                        ArrayList params = method.getParameters();
271:                        ArrayList origParams = origMethod.getParameters();
272:
273:                        for (int i = 0; i < params.size(); i++) {
274:                            MethodParam param = (MethodParam) params.get(i);
275:                            MethodParam origParam = (MethodParam) origParams
276:                                    .get(i);
277:
278:                            param.setName(origParam.getName());
279:                        }
280:
281:                        // Now reutrn collection element class
282:                        if (method.getReturnType().isCollection()) {
283:                            MethodReturn ret = method.getReturnType();
284:                            ret.setElemClassName(origMethod.getReturnType()
285:                                    .getElemClassName());
286:                        }
287:                    }
288:                }
289:            }
290:
291:            public EjbGroup getEjbGroup() {
292:                return this .ejbGroup;
293:            }
294:
295:            private void setAllClazz(Set allClasses) {
296:                for (Iterator iter = allClasses.iterator(); iter.hasNext();) {
297:                    String className = (String) iter.next();
298:
299:                    // No internal classes for now
300:                    if (className.indexOf('$') != -1) {
301:                        iter.remove();
302:                        continue;
303:                    }
304:
305:                    /*try {
306:                        Class.forName( className, true, classloader );
307:                    } catch( Throwable t ) {
308:                        // bad one
309:                        iter.remove();
310:                    } */
311:                }
312:                ejbGroup.setAllClazz(allClasses);
313:            }
314:
315:            private void populateBeanInfo(Map deploymentDescriptors)
316:                    throws EjbLoadException {
317:                // Populate the ejb information from the deployment descriptors extracted
318:                // from the client jar file. The ejb names, home interfaces, component interfaces
319:                // are extracted from the standard deployment descriptor - ejb-jar.xml. The
320:                // JNDI names are from the vendor specific xml file, for example, sun-ejb-jar.xml
321:                // Using Java reflection to get the business methods
322:
323:                // Parse the standard deployment descriptors first to get
324:                // the session EJBs
325:                parseStdXmls(deploymentDescriptors.keySet());
326:
327:                // Then the vendor specific ones to get the jndi names
328:                Map ejbName2JndiNameMapping = parseVendorXmls(deploymentDescriptors
329:                        .values());
330:
331:                // Now set the jndi name to the proper ejbs
332:                for (Iterator iter = ejbGroup.getSessionBeans().iterator(); iter
333:                        .hasNext();) {
334:                    EjbInfo info = (EjbInfo) iter.next();
335:
336:                    // Note: the map from sun appserver and weblogic deployment descriptor,
337:                    // the map contains (ejbName, jndiName) pairs. But the map from the
338:                    // websphere deployment descriptor cotains (bean id, jndi name )
339:
340:                    String jndiName = null;
341:                    if (ejbGroup.isWebsphereAppServer())
342:                        jndiName = (String) ejbName2JndiNameMapping.get(info
343:                                .getBeanId());
344:                    else
345:                        jndiName = (String) ejbName2JndiNameMapping.get(info
346:                                .getEjbName());
347:
348:                    info.setJNDIName(jndiName);
349:
350:                    // Make the ejb ref name, which will be written into web.xml, the
351:                    // same as the jndi name
352:                    info.setWebEjbRef(jndiName);
353:                }
354:
355:                // Buz methods
356:                populateBusinessMethods();
357:            }
358:
359:            private void parseStdXmls(Collection stdXmls)
360:                    throws EjbLoadException {
361:                Collection allSkippedEjbs = new ArrayList();
362:
363:                for (Iterator iter = stdXmls.iterator(); iter.hasNext();) {
364:                    String stdXml = (String) iter.next();
365:                    StdDeploymentDescriptorParser parser = new StdDeploymentDescriptorParser(
366:                            stdXml);
367:                    ejbGroup.addSessionBeans(parser.parse());
368:
369:                    if (parser.getSkippedEjbs() != null)
370:                        allSkippedEjbs.addAll(parser.getSkippedEjbs());
371:                }
372:
373:                if (!allSkippedEjbs.isEmpty()) {
374:                    StringBuffer skippedEjbsStr = new StringBuffer();
375:                    boolean first = true;
376:                    for (Iterator skippedEjbsIter = allSkippedEjbs.iterator(); skippedEjbsIter
377:                            .hasNext();) {
378:                        if (first)
379:                            first = false;
380:                        else
381:                            skippedEjbsStr.append(", ");
382:
383:                        skippedEjbsStr.append((String) skippedEjbsIter.next());
384:                    }
385:
386:                    if (allSkippedEjbs.size() == 1)
387:                        // EJB {0} has been skipped because there are no packages defined for the home or/and remote interfaces.
388:                        warningMsg = NbBundle.getMessage(
389:                                StdDeploymentDescriptorParser.class,
390:                                "SKIP_NO_PACKAGE_EJB_SINGLE", skippedEjbsStr
391:                                        .toString());
392:                    else
393:                        // EJBs {0} have been skipped because there are no packages defined for the home or/and remote interfaces.
394:                        warningMsg = NbBundle.getMessage(
395:                                StdDeploymentDescriptorParser.class,
396:                                "SKIP_NO_PACKAGE_EJBS", skippedEjbsStr
397:                                        .toString());
398:                }
399:            }
400:
401:            private Map parseVendorXmls(Collection vendorXmls)
402:                    throws EjbLoadException {
403:                Map ejbName2JndiNameMapping = new HashMap();
404:                for (Iterator iter = vendorXmls.iterator(); iter.hasNext();) {
405:                    String vendorXml = (String) iter.next();
406:
407:                    if (ejbGroup.isSunAppServer()) {
408:                        SunDeploymentDescriptorParser parser = new SunDeploymentDescriptorParser(
409:                                vendorXml);
410:                        ejbName2JndiNameMapping.putAll(parser.parse());
411:                    } else if (ejbGroup.isWebLogicAppServer()) {
412:                        WeblogicDeploymentDescriptorParser parser = new WeblogicDeploymentDescriptorParser(
413:                                vendorXml);
414:                        ejbName2JndiNameMapping.putAll(parser.parse());
415:                    } else if (ejbGroup.isWebsphereAppServer()) {
416:                        WebsphereDeploymentDescriptorParser parser = new WebsphereDeploymentDescriptorParser(
417:                                vendorXml);
418:                        ejbName2JndiNameMapping.putAll(parser.parse());
419:                    }
420:                }
421:
422:                return ejbName2JndiNameMapping;
423:            }
424:
425:            private void populateBusinessMethods() throws EjbLoadException {
426:                // Now get the business methods of each session bean
427:                Collection sessionBeans = ejbGroup.getSessionBeans();
428:
429:                for (Iterator iter = sessionBeans.iterator(); iter.hasNext();) {
430:                    EjbInfo ejbInfo = (EjbInfo) iter.next();
431:                    ArrayList allMethods = new ArrayList();
432:
433:                    // Get the business methods
434:                    String remoteInterface = ejbInfo.getCompInterfaceName();
435:
436:                    try {
437:                        allMethods.addAll(getBuzMethodInfos(remoteInterface));
438:                    } catch (java.lang.ClassNotFoundException ex) {
439:                        // Looks like this session ejb is not in the specified client jars.
440:                        // Remove it from the session bean list and go on
441:                        iter.remove();
442:                        continue;
443:                    }
444:
445:                    // Get the create() methods in home interface
446:                    String homeInterface = ejbInfo.getHomeInterfaceName();
447:                    allMethods.addAll(getCreateMethodInfos(homeInterface));
448:
449:                    ejbInfo.setMethods(allMethods);
450:                }
451:
452:                // The session beans collection might be changed.
453:                ejbGroup.setSessionBeans(sessionBeans);
454:            }
455:
456:            private ArrayList getBuzMethodInfos(String interfaceName)
457:                    throws java.lang.ClassNotFoundException {
458:                try {
459:                    Class c = Class.forName(interfaceName, true, classloader);
460:                    Method[] methods = c.getMethods();
461:
462:                    ArrayList methodInfos = new ArrayList();
463:                    for (int i = 0; i < methods.length; i++) {
464:                        if (EjbMethodFilter.isEjbSpecMethod(methods[i]))
465:                            continue;
466:
467:                        String methodName = methods[i].getName();
468:
469:                        // Return type
470:                        MethodReturn returnType = createMethodReturn(methods[i]
471:                                .getReturnType());
472:
473:                        // Parameters
474:                        Class[] pcs = methods[i].getParameterTypes();
475:                        ArrayList parameters = new ArrayList();
476:                        for (int pci = 0; pci < pcs.length; pci++) {
477:                            parameters.add(new MethodParam("arg" + pci, Util
478:                                    .getTypeName(pcs[pci])));
479:                        }
480:
481:                        // Exceptions
482:                        Class[] exceptionCls = methods[i].getExceptionTypes();
483:                        ArrayList exceptions = new ArrayList();
484:                        for (int exi = 0; exi < exceptionCls.length; exi++)
485:                            exceptions.add(exceptionCls[exi].getName());
486:
487:                        // Ready to make a MethodInfo object
488:                        methodInfos.add(new MethodInfo(methodName, methodName,
489:                                parameters, returnType, exceptions));
490:                    }
491:
492:                    return methodInfos;
493:                } catch (java.lang.ClassNotFoundException ex) {
494:                    // Log a warning and go one
495:                    ErrorManager
496:                            .getDefault()
497:                            .getInstance(
498:                                    "org.netbeans.modules.visualweb.ejb.load.EjbLoader")
499:                            .log(
500:                                    ErrorManager.INFORMATIONAL,
501:                                    "Remote interface ("
502:                                            + interfaceName
503:                                            + ") is not found in the client jars. Skipped.");
504:
505:                    throw ex;
506:                }
507:            }
508:
509:            private ArrayList getCreateMethodInfos(String interfaceName)
510:                    throws EjbLoadException {
511:                try {
512:                    Class c = Class.forName(interfaceName, true, classloader);
513:                    Method[] methods = c.getMethods();
514:
515:                    ArrayList methodInfos = new ArrayList();
516:                    for (int i = 0; i < methods.length; i++) {
517:                        // Only look for create() metohds
518:                        if (!methods[i].getName().equals("create"))
519:                            continue;
520:
521:                        String methodName = methods[i].getName();
522:                        MethodReturn returnType = createMethodReturn(methods[i]
523:                                .getReturnType());
524:
525:                        // Parameters
526:                        Class[] pcs = methods[i].getParameterTypes();
527:                        ArrayList parameters = new ArrayList();
528:                        for (int pci = 0; pci < pcs.length; pci++) {
529:                            parameters.add(new MethodParam("arg" + pci,
530:                                    pcs[pci].getName()));
531:                        }
532:
533:                        // Exceptions
534:                        Class[] exceptionCls = methods[i].getExceptionTypes();
535:                        ArrayList exceptions = new ArrayList();
536:                        for (int exi = 0; exi < exceptionCls.length; exi++)
537:                            exceptions.add(exceptionCls[exi].getName());
538:
539:                        // Ready to make a MethodInfo object
540:                        methodInfos
541:                                .add(new MethodInfo(false, methodName,
542:                                        methodName, parameters, returnType,
543:                                        exceptions));
544:                    }
545:
546:                    return methodInfos;
547:                } catch (java.lang.ClassNotFoundException ex) {
548:                    // Log error
549:                    String logMsg = "Error occurred when trying to get the method information. Cannot find class "
550:                            + interfaceName;
551:                    ErrorManager
552:                            .getDefault()
553:                            .getInstance(
554:                                    "org.netbeans.modules.visualweb.ejb.load.EjbLoader")
555:                            .log(ErrorManager.ERROR, logMsg);
556:                    ex.printStackTrace();
557:
558:                    // throw exception
559:                    throw new EjbLoadException(ex.getMessage());
560:                }
561:            }
562:
563:            private MethodReturn createMethodReturn(Class returnClass) {
564:                MethodReturn returnType = new MethodReturn();
565:
566:                if (Collection.class.isAssignableFrom(returnClass))
567:                    returnType.setIsCollection(true);
568:                else
569:                    returnType.setIsCollection(false);
570:
571:                returnType.setClassName(Util.getTypeName(returnClass));
572:
573:                return returnType;
574:            }
575:
576:            public void createWrapperClientBeans() throws EjbLoadException {
577:
578:                // Where the class will be generated
579:                String srcDir = getWrapperBeanSrcDir();
580:
581:                // Load classes from the client jars if not yet
582:                if (classloader == null)
583:                    classloader = EjbLoaderHelper
584:                            .getEjbGroupClassLoader(ejbGroup);
585:
586:                ArrayList allClassDescriptors = new ArrayList();
587:
588:                // Generate source code for wrapper classes (bean, beanInfo), 
589:                // data provider bean classes (bean, beanInfo, designInfo),
590:                // then compile them and jar all the files into one jar file
591:
592:                // One wrapper class per session ejb
593:                for (Iterator iter = ejbGroup.getSessionBeans().iterator(); iter
594:                        .hasNext();) {
595:                    EjbInfo ejb = (EjbInfo) iter.next();
596:                    ClientBeanGenerator generator = new ClientBeanGenerator(
597:                            ejb, classloader);
598:                    allClassDescriptors.addAll(generator
599:                            .generateClasses(srcDir));
600:                }
601:
602:                // Data provider classes. One per non-void buz method
603:                generateDPClasses(allClassDescriptors);
604:
605:                // Compile the wrapper bean and beanInfo classes
606:                ClientBeanWrapperCompiler compiler = new ClientBeanWrapperCompiler();
607:                ArrayList jarFiles = new ArrayList(ejbGroup.getClientJarFiles());
608:                //      jarFiles.add( ejb20Jar );  // For EJB base classes
609:                List<File> javaEEJars = EjbLoaderHelper
610:                        .getJavaEEClasspathEntries();
611:                for (File file : javaEEJars) {
612:                    String path = file.getAbsolutePath();
613:                    jarFiles.add(path);
614:                }
615:                jarFiles.add(dataproviderJar); // For the data provider classes
616:                jarFiles.add(designTimeJar); // For the DesignInfo classes
617:                jarFiles.add(designTimeBaseJar);
618:                jarFiles.add(propEditorsJar);
619:
620:                compiler.compile(srcDir, allClassDescriptors, jarFiles);
621:
622:                // Time to jar ....
623:                // The name of the jar file will be the concatenation of the ejb group name (spaces will be replaced with "_"s)
624:                // with "ClientWrapper". For example, if the ejb group name is "Travel Center EJBs", then the wrapper
625:                // jar name will be Travel_Center_EJBsClientWrapper.jar
626:
627:                if (ejbGroup.getClientWrapperBeanJar() == null) {
628:                    // Must be the first time generating the jar file
629:                    // It is for the add new ejb group case
630:
631:                    String jarName = ejbGroup.getName().replaceAll(" ", "_")
632:                            + "ClientWrapper.jar"; // NOI18N
633:                    String wrapperJarPath = srcDir + File.separator + jarName;
634:                    ejbGroup.setClientWrapperBeanJar(wrapperJarPath);
635:                }
636:
637:                if (ejbGroup.getDesignInfoJar() == null) {
638:                    // Must be the first time generating the jar file
639:                    // It is for the add new ejb group case
640:
641:                    String jarName = ejbGroup.getName().replaceAll(" ", "_")
642:                            + "DesignTime.jar"; // NOI18N
643:                    String jarPath = srcDir + File.separator + jarName;
644:                    ejbGroup.setDesignInfoJar(jarPath);
645:                }
646:
647:                ClientBeanWrapperJarGenerator.jarThemUp(ejbGroup.getName(),
648:                        ejbGroup, allClassDescriptors);
649:            }
650:
651:            private void generateDPClasses(ArrayList allClassDescriptors)
652:                    throws EjbLoadException {
653:                // Business methods from session ejbs
654:                for (Iterator iter = ejbGroup.getSessionBeans().iterator(); iter
655:                        .hasNext();) {
656:                    EjbInfo ejbInfo = (EjbInfo) iter.next();
657:
658:                    Map methodNameOccurrence = new HashMap();
659:                    for (Iterator mIter = ejbInfo.getMethods().iterator(); mIter
660:                            .hasNext();) {
661:                        MethodInfo mInfo = (MethodInfo) mIter.next();
662:
663:                        if (mInfo.isBusinessMethod()
664:                                && !mInfo.getReturnType().isVoid()) {
665:                            // For overloadded method, an index will be append after the method name for the second method on
666:
667:                            String dpClassName = mInfo.getName();
668:
669:                            Integer occurrence = (Integer) methodNameOccurrence
670:                                    .get(mInfo.getName());
671:                            if (occurrence == null)
672:                                occurrence = new Integer(1);
673:                            else {
674:                                occurrence = new Integer(
675:                                        occurrence.intValue() + 1);
676:                                dpClassName += occurrence;
677:                            }
678:
679:                            methodNameOccurrence.put(mInfo.getName(),
680:                                    occurrence);
681:
682:                            // The data provider class name is the ejb remote interface name + method name + (possible index number if method name is overloadded)
683:                            mInfo.setDataProvider(Util.getClassName(ejbInfo
684:                                    .getCompInterfaceName())
685:                                    + Util.capitalize(dpClassName)); // NOI18N
686:
687:                            DataProviderGenerator dpGen = new DataProviderGenerator(
688:                                    ejbInfo.getBeanWrapperName(), mInfo,
689:                                    classloader);
690:                            allClassDescriptors.addAll(dpGen
691:                                    .generateClasses(getWrapperBeanSrcDir()));
692:                        }
693:                    }
694:                }
695:            }
696:
697:            private String getWrapperBeanSrcDir() {
698:                File srcDirF = new File(Util.getEjbStateDir(), "ejb-datasource"); // NOI18N
699:                if (!srcDirF.exists())
700:                    srcDirF.mkdirs();
701:
702:                return srcDirF.getAbsolutePath();
703:            }
704:
705:            private void validateAppServerSelection(Map descriptors)
706:                    throws EjbLoadException {
707:                // I think it is safe to just pick one of the vendor deployment descriptor
708:                // to validate
709:
710:                String vendorDD = (String) descriptors.values().iterator()
711:                        .next();
712:                boolean invalid = false;
713:                if ((ejbGroup.isSunAppServer() && vendorDD
714:                        .indexOf("sun-ejb-jar") == -1)
715:                        || (ejbGroup.isWebLogicAppServer() && vendorDD
716:                                .indexOf("weblogic-ejb-jar") == -1)
717:                        || (ejbGroup.isWebsphereAppServer() && vendorDD
718:                                .indexOf("ibm-ejb-jar-bnd") == -1)) {
719:                    // Wrong vendor DD
720:                    // The deployment descriptors contained in the client jar files and/or deployment descriptor file do not match those expected for application server {0}. Maybe the wrong application server is selected.
721:                    ErrorManager
722:                            .getDefault()
723:                            .getInstance(
724:                                    "org.netbeans.modules.visualweb.ejb.load.EjbLoader")
725:                            .log(
726:                                    ErrorManager.ERROR,
727:                                    "Incorrect application server selected for EJB set: "
728:                                            + ejbGroup.getName());
729:                    throw new EjbLoadException(EjbLoadException.USER_ERROR,
730:                            NbBundle.getMessage(EjbLoader.class,
731:                                    "WRONG_APP_SERVER_TYPE", ejbGroup
732:                                            .getAppServerVendor()));
733:                }
734:            }
735:
736:            private void checkFileExistence() throws EjbLoadException {
737:                if (ejbGroup.getClientJarFiles() != null) {
738:                    for (Iterator iter = ejbGroup.getClientJarFiles()
739:                            .iterator(); iter.hasNext();) {
740:                        String file = (String) iter.next();
741:                        if (!(new File(file)).exists()) {
742:                            String msg = NbBundle.getMessage(EjbLoader.class,
743:                                    "RELOAD_ERROR_FILE_NOT_FOUND", ejbGroup
744:                                            .getName(), file);
745:                            throw new EjbLoadException(
746:                                    EjbLoadException.USER_ERROR, msg);
747:                        }
748:                    }
749:                }
750:
751:                if (ejbGroup.getDDLocationFile() != null
752:                        && !(new File(ejbGroup.getDDLocationFile()).exists())) {
753:                    String msg = NbBundle.getMessage(EjbLoader.class,
754:                            "RELOAD_ERROR_FILE_NOT_FOUND", ejbGroup.getName(),
755:                            ejbGroup.getDDLocationFile());
756:                    throw new EjbLoadException(EjbLoadException.USER_ERROR, msg);
757:                }
758:            }
759:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.