Source Code Cross Referenced for WebServiceGenerator.java in  » IDE-Netbeans » web.core » org » netbeans » modules » websvc » jaxrpc » dev » wizard » 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 » web.core » org.netbeans.modules.websvc.jaxrpc.dev.wizard 
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-2006 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:        package org.netbeans.modules.websvc.jaxrpc.dev.wizard;
043:
044:        import org.netbeans.modules.websvc.api.support.java.GenerationUtils;
045:        import org.openide.filesystems.FileObject;
046:        import org.netbeans.api.project.Project;
047:        import java.io.IOException;
048:        import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
049:        import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
050:        import org.netbeans.modules.j2ee.dd.api.webservices.ServiceImplBean;
051:        import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
052:        import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
053:        import java.net.URI;
054:        import org.openide.filesystems.FileLock;
055:        import java.io.OutputStream;
056:        import org.openide.filesystems.FileSystem;
057:        import org.openide.filesystems.FileUtil;
058:        import org.openide.filesystems.Repository;
059:        import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation;
060:        import org.openide.nodes.Node;
061:        import org.netbeans.api.project.ant.AntArtifact;
062:        import org.netbeans.spi.project.ant.AntArtifactProvider;
063:        import java.util.Iterator;
064:        import javax.xml.parsers.ParserConfigurationException;
065:        import javax.xml.parsers.SAXParser;
066:        import javax.xml.parsers.SAXParserFactory;
067:        import javax.xml.transform.stream.StreamSource;
068:        import org.xml.sax.SAXException;
069:        import java.io.InputStream;
070:        import java.util.HashMap;
071:        import java.util.List;
072:        import java.util.Map;
073:        import java.util.Set;
074:        import org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.Configuration;
075:        import org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.InterfaceType;
076:        import org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.WsdlType;
077:        import org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.wscreation.Bean;
078:        import org.netbeans.modules.websvc.wsdl.config.PortInformationHandler;
079:        import org.openide.ErrorManager;
080:        import org.openide.NotifyDescriptor;
081:        import org.openide.DialogDisplayer;
082:        import org.openide.util.NbBundle;
083:
084:        public class WebServiceGenerator {
085:            private WSGenerationUtil wsgenUtil = new WSGenerationUtil();
086:            private static final String WEBSERVICE_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE
087:                    + "WSImplBean.xml"; //NOI18N
088:            private static final String WEBSERVICEJAVAEE5_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE
089:                    + "WSImplBeanJavaEE5.xml"; //NOI18N
090:            private static final String INTERFACE_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE
091:                    + "WSInterface.xml"; //NOI18N
092:            private static final String HANDLER_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE
093:                    + "MessageHandler.xml"; //NOI18N
094:            public static final String WSDL_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE
095:                    + "WSDL.xml"; //NOI18N
096:
097:            public static final String EJB21_EJBCLASS = "Templates/J2EE/EJB21/SessionEjbClass.java"; // NOI18N
098:
099:            private String implBeanClass = "";
100:            private String intfClass = "";
101:            private String targetNS = null;
102:            private String soapBinding = "";
103:            private String portTypeName = null;
104:            public static final String WEBSERVICES_DD = "webservices";//NOI18N
105:            private WebServicesSupport wsSupport;
106:            private String wsName;
107:            private FileObject pkg;
108:            private Project project;
109:            private List importedSchemaList;
110:            // flag indicating if service name need to be changed (happens when portName=service name)
111:            // Issue 58509
112:            private boolean changeWsName;
113:            private String[] wscompileFeatures;
114:
115:            public WebServiceGenerator(WebServicesSupport wsSupport,
116:                    String wsName, FileObject pkg, Project project) {
117:                this .wsSupport = wsSupport;
118:                this .wsName = wsName;
119:                this .pkg = pkg;
120:                this .project = project;
121:            }
122:
123:            public WebServiceGenerator(FileObject pkg, Project project) {
124:                this .pkg = pkg;
125:                this .project = project;
126:            }
127:
128:            public void generateWebService() throws IOException {
129:                generateWebService(null);
130:            }
131:
132:            public FileObject generateWSDL(String template, String wsName,
133:                    String soapBinding, String portTypeName, FileObject folder,
134:                    FileObject originalFolder, String wsdlName,
135:                    StreamSource source) throws IOException {
136:                return wsgenUtil.generateWSDL(template, wsName, soapBinding,
137:                        portTypeName, folder, originalFolder, wsdlName, source);
138:            }
139:
140:            public FileObject generateWSDL(String template, String wsName,
141:                    String soapBinding, String portTypeName, FileObject folder,
142:                    String wsdlName, StreamSource source) throws IOException {
143:                return wsgenUtil.generateWSDL(template, wsName, soapBinding,
144:                        portTypeName, folder, wsdlName, source);
145:            }
146:
147:            /**
148:             * Parse the original wsdl to obtain the portType name, targetNamespace and SOAP
149:             * binding. Note that if no SOAP binding in obtained, the first portType
150:             * name that is encountered is used.
151:             * @return changed service name or null
152:             */
153:            public String parseWSDL(InputStream wsdlInputStream)
154:                    throws IOException, NoWSPortDefinedException {
155:                //parse the wsdl to get SEI class name and target namespace
156:
157:                String changedWsName = null;
158:
159:                PortInformationHandler handler = new PortInformationHandler();
160:
161:                try {
162:                    SAXParserFactory factory = SAXParserFactory.newInstance();
163:                    factory.setNamespaceAware(true);
164:                    SAXParser saxParser = factory.newSAXParser();
165:                    saxParser.parse(wsdlInputStream, handler);
166:                } catch (ParserConfigurationException ex) {
167:                    ErrorManager.getDefault().notify(
168:                            ErrorManager.INFORMATIONAL, ex);
169:                    String mes = NbBundle.getMessage(WebServiceGenerator.class,
170:                            "ERR_WsdlParseFailure"); // NOI18N
171:                    NotifyDescriptor desc = new NotifyDescriptor.Message(mes,
172:                            NotifyDescriptor.Message.ERROR_MESSAGE);
173:                    DialogDisplayer.getDefault().notify(desc);
174:                    return changedWsName;
175:                } catch (SAXException ex) {
176:                    ErrorManager.getDefault().notify(
177:                            ErrorManager.INFORMATIONAL, ex);
178:                    String mes = NbBundle.getMessage(WebServiceGenerator.class,
179:                            "ERR_WsdlParseFailure"); // NOI18N
180:                    NotifyDescriptor desc = new NotifyDescriptor.Message(mes,
181:                            NotifyDescriptor.Message.ERROR_MESSAGE);
182:                    DialogDisplayer.getDefault().notify(desc);
183:                    return changedWsName;
184:                }
185:
186:                List entirePortList = handler.getEntirePortList();
187:                if (entirePortList.isEmpty()) {
188:                    throw new NoWSPortDefinedException();
189:                }
190:                Iterator iterator = entirePortList.iterator();
191:                String firstPortType = null;
192:                while (iterator.hasNext()) {
193:                    PortInformationHandler.PortInfo portInfo = (PortInformationHandler.PortInfo) iterator
194:                            .next();
195:                    if (firstPortType == null) {
196:                        //there should at least be one portType in the WSDL
197:                        firstPortType = portInfo.getPortType();
198:                    }
199:                    //get the first SOAP binding
200:                    if (portInfo.getBindingType() != null
201:                            && portInfo.getBindingType().equals(
202:                                    "http://schemas.xmlsoap.org/wsdl/soap")) { //NOI18N
203:                        portTypeName = portInfo.getPortType();
204:                        soapBinding = portInfo.getBinding();
205:                        break;
206:                    }
207:                }
208:                //if no soap binding was found, use the first portType encountered
209:                if (portTypeName == null) {
210:                    portTypeName = firstPortType;
211:                }
212:                if (portTypeName == null) {
213:                    throw new NoWSPortDefinedException();
214:                }
215:                //get name of SEI and Impl class name from portTypeName. In future, we should get this from
216:                //wscompile spi
217:                intfClass = WSGenerationUtil.getSelectedPackageName(pkg,
218:                        project)
219:                        + "." + normalizePortTypeName(portTypeName);
220:                implBeanClass = intfClass + "_Impl"; //NOI18N
221:                targetNS = handler.getTargetNamespace();
222:                importedSchemaList = handler.getImportedSchemas();
223:                if (changeWsName)
224:                    changedWsName = wsName + "_Service"; //NOI18N
225:                Set features = handler.getWscompileFeatures();
226:                wscompileFeatures = new String[features.size()];
227:                features.toArray(wscompileFeatures);
228:                return changedWsName;
229:            }
230:
231:            /*
232:             * if portTypeName does not start with uppercase character, make it
233:             * uppercase. This is the convention used by wscompile in naming
234:             * the generated SEI and impl bean classes
235:             */
236:            private String normalizePortTypeName(String portTypeName) {
237:                if (portTypeName == null) {
238:                    return "unknown"; //NOI18N
239:                }
240:                String first = portTypeName.substring(0, 1);
241:                String result = first.toUpperCase()
242:                        + ((portTypeName.length() > 1) ? portTypeName
243:                                .substring(1) : "");
244:                if (result.equals(wsName)) {
245:                    changeWsName = true;
246:                }
247:                return result;
248:
249:            }
250:
251:            public void generateMessageHandler(String handlerName)
252:                    throws IOException {
253:                String pkgName = wsgenUtil.getSelectedPackageName(pkg, project);
254:                Bean b = wsgenUtil.getDefaultBean();
255:                b.setCommentDataWsName(handlerName);
256:                b.setClassname(true);
257:                b.setClassnameName(handlerName);
258:                if (pkgName != null) {
259:                    b.setClassnamePackage(pkgName);
260:                }
261:                String handlerClass = wsgenUtil
262:                        .getFullClassName(pkgName, wsgenUtil.generateClass(
263:                                HANDLER_TEMPLATE, b, pkg, true));
264:            }
265:
266:            public void generateWebService(Node[] nodes) throws IOException {
267:                String pkgName = wsgenUtil.getSelectedPackageName(pkg, project);
268:
269:                Bean b = wsgenUtil.getDefaultBean();
270:                b.setCommentDataWsName(wsName);
271:                b.setClassname(true);
272:                b.setDelegateData("");
273:
274:                b.setClassnameName(wsgenUtil.getBeanClassName(wsName));
275:
276:                if (pkgName != null) {
277:                    b.setClassnamePackage(pkgName);
278:                }
279:
280:                //FIXE-ME: need to delegate impl bean class to the web module
281:                if (project.getLookup().lookup(WebModuleImplementation.class) != null) {
282:                    implBeanClass = wsgenUtil.getFullClassName(pkgName,
283:                            wsgenUtil.generateClass(WEBSERVICE_TEMPLATE, b,
284:                                    pkg, true));
285:                    b.setClassnameName(wsgenUtil.getSEIName(wsName));
286:                    intfClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil
287:                            .generateClass(INTERFACE_TEMPLATE, b, pkg, false));
288:                    if (implBeanClass != null) {
289:                        // Retouche
290:                        //                boolean rollback = true;
291:                        //                JMIUtils.beginJmiTransaction(true);
292:                        //                try {
293:                        //                    JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
294:                        //                    if (jc != null && jc.isValid()) {
295:                        //                        addDelegateMethod(nodes, jc);
296:                        //                    }
297:                        //                    rollback=false;
298:                        //                } catch (Exception ex) {
299:                        //                } finally {
300:                        //                    JMIUtils.endJmiTransaction(rollback);
301:                        //                }
302:                    }
303:                } else {
304:                    try {
305:                        Map templateParameters = new HashMap<String, String>();
306:                        FileObject ejbClassFO = GenerationUtils.createClass(
307:                                EJB21_EJBCLASS, pkg, b.getClassnameName(),
308:                                null, templateParameters);
309:                        implBeanClass = wsgenUtil.getFullClassName(pkgName,
310:                                ejbClassFO.getName());
311:                        b.setClassnameName(wsgenUtil.getSEIName(wsName));
312:                        intfClass = wsgenUtil.getFullClassName(pkgName,
313:                                wsgenUtil.generateClass(INTERFACE_TEMPLATE, b,
314:                                        pkg, false));
315:                    } catch (java.io.IOException e) {
316:                        ErrorManager.getDefault().notify(e);
317:                    }
318:                    if (implBeanClass != null) {
319:                        // Retouche
320:                        //                boolean rollback = true;
321:                        //                JMIUtils.beginJmiTransaction(true);
322:                        //                try {
323:                        //                    JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
324:                        //                    if (jc != null) {
325:                        //                        addDelegateMethod(nodes, jc);
326:                        //                    }
327:                        //                    rollback=false;
328:                        //                } catch (Exception ex) {
329:                        //                } finally {
330:                        //                    JMIUtils.endJmiTransaction(rollback);
331:                        //                }
332:                    }
333:                }
334:            }
335:
336:            //    public void addReferences(String beanClassName, Node[] nodes) {
337:            //        for(int i = 0; i < nodes.length; i++) {
338:            //            Node node = nodes[i];
339:            //            EjbReference ref = (EjbReference)node.getCookie(EjbReference.class);
340:            //            if(ref != null) {
341:            //                EnterpriseReferenceContainer erc = (EnterpriseReferenceContainer)project.getLookup()
342:            //                .lookup(EnterpriseReferenceContainer.class);
343:            //                if(ref.supportsRemoteInvocation()) {
344:            //                    EjbRef ejbRef = ref.createRef();
345:            //                    if(ejbRef.getEjbRefType().equals("Session")) { //NOI18N
346:            //                        try {
347:            //// Retouche
348:            ////                            erc.addEjbReference(ejbRef, beanClassName, ref.getClientJarTarget());
349:            //                        }
350:            //                        catch(Exception e) {
351:            //                            throw new RuntimeException(e.getMessage());
352:            //                        }
353:            //                    }
354:            //                }
355:            //                if(!ref.supportsRemoteInvocation() &&
356:            //                ref.supportsLocalInvocation()) {
357:            //                    EjbLocalRef ejbLocalRef = ref.createLocalRef();
358:            //                    if(ejbLocalRef.getEjbRefType().equals("Session")) { //NOI18N
359:            //                        try {
360:            //// Retouche
361:            ////                            erc.addEjbLocalReference(ejbLocalRef, beanClassName, ref.getClientJarTarget());
362:            //                        }
363:            //                        catch(Exception e) {
364:            //                            throw new RuntimeException(e.getMessage());
365:            //                        }
366:            //                    }
367:            //                }
368:            //            }
369:            //            else  //Java class
370:            //            {
371:            //// Retouche
372:            ////                JavaClass classElement = JMIUtils.getJavaClassFromNode(node);
373:            ////                assert (classElement != null);
374:            ////
375:            ////                //find out if the class is in the same project or not
376:            ////                FileObject srcFile = JavaMetamodel.getManager().getDataObject(classElement.getResource()).getPrimaryFile();
377:            ////
378:            ////                Project p = FileOwnerQuery.getOwner(srcFile);
379:            ////                if(p != null) //project can be determined. if not, class is
380:            ////                    //not in any  project and is assumed to already be
381:            ////                    //in the classpath
382:            ////                {
383:            ////                    if(!project.equals(p )) //not in same project
384:            ////                    {
385:            ////                        AntArtifact target = AntArtifactQuery.findArtifactsByType(p, getAntArtifactType(p))[0];
386:            ////                        ReferenceHelper helper = wsSupport.getReferenceHelper();
387:            ////                        if(helper.addReference(target)) {
388:            ////                            AntProjectHelper antHelper = wsSupport.getAntProjectHelper();
389:            ////                            EditableProperties ep =
390:            ////                            antHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
391:            ////                            String s = ep.getProperty("javac.classpath"); //FIX-ME:get from project
392:            ////                            s += File.pathSeparatorChar + helper.createForeignFileReference(target);
393:            ////                            ep.setProperty("javac.classpath", s);
394:            ////                            antHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
395:            ////                        }
396:            ////                        try {
397:            ////                            ProjectManager.getDefault().saveProject(project);
398:            ////                        }
399:            ////                        catch(java.io.IOException e) {
400:            ////                            throw new RuntimeException(e.getMessage());
401:            ////                        }
402:            ////                    }
403:            ////                }
404:            //            }
405:            //        }
406:            //    }
407:
408:            // Retouche
409:            //    public void addDelegateMethod(Node[] nodes, final JavaClass jc) {
410:            //        if (nodes == null) return;
411:            //        for (int i = 0; i < nodes.length; i++) {
412:            //            Node node = nodes[i];
413:            //            EjbReference ref = (EjbReference)node.getCookie(EjbReference.class);
414:            //            if (ref != null) {
415:            //                if (ref.supportsRemoteInvocation()) {
416:            //                    EjbRef ejbRef = ref.createRef();
417:            //                    if (ejbRef.getEjbRefType().equals("Session")) { //NOI18N
418:            //                        try {
419:            //                            Feature f = ref.generateReferenceCode(jc, ejbRef, false);
420:            //                            if (f instanceof Method) {
421:            //                                Method method = (Method) f;
422:            //                                //if Home is returned, add comment on how to get EJB
423:            //                                if(method.getType().getName().equals(ejbRef.getHome())) {
424:            //                                    addMethodJavaDocForHome(method, ejbRef.getHome(), ejbRef.getRemote());
425:            //                                }
426:            //                                ((Method) method).setJavadocText(NbBundle.getMessage(WebServiceGenerator.class,"MSG_JAVADOC_LOOKUP_REMOTE"));
427:            //                            };
428:            //                        } catch(Exception e) {
429:            //                            throw new RuntimeException(e.getMessage());
430:            //                        }
431:            //                    }
432:            //                }
433:            //                if (!ref.supportsRemoteInvocation() && ref.supportsLocalInvocation()) {
434:            //                    EjbLocalRef ejbLocalRef = ref.createLocalRef();
435:            //                    if (ejbLocalRef.getEjbRefType().equals("Session")) {
436:            //                        try {
437:            //                            Feature f = ref.generateReferenceCode(jc, ejbLocalRef, false);
438:            //                            if (f instanceof Method) {
439:            //                                Method method = (Method) f;
440:            //                                //if LocalHome is returned, add comment on how to get EJB
441:            //                                if (method.getType().getName().equals(ejbLocalRef.getLocalHome())) {
442:            //                                    addMethodJavaDocForHome(method, ejbLocalRef.getLocalHome(), ejbLocalRef.getLocal());
443:            //                                }
444:            //                                ((Method) method).setJavadocText(NbBundle.getMessage(WebServiceGenerator.class,"MSG_JAVADOC_LOOKUP_LOCAL"));
445:            //                            }
446:            //                        } catch (Exception e) {
447:            //                            throw new RuntimeException(e.getMessage());
448:            //                        }
449:            //                    }
450:            //                }
451:            //            } else { //Java class
452:            //                JavaClass classElement = JMIUtils.getJavaClassFromNode(node);
453:            //                assert (classElement != null);
454:            //
455:            //                JavaModelPackage jmp = (JavaModelPackage) classElement.refImmediatePackage();
456:            //
457:            //                Field field = jmp.getField().createField();
458:            //                field.setName(classElement.getName());
459:            //                String name = varFromName(classElement.getName());
460:            ////                buffer.append(field.getName() + " " + name + ";");
461:            //            }
462:            //        }
463:            //    }
464:            //
465:            //    private Method createClone(JavaClass jc, Method method, String javadoc) {
466:            //        Method clonnedMethod = JMIUtils.createMethod(jc);
467:            //        clonnedMethod.setBodyText(method.getBodyText());
468:            //        clonnedMethod.setModifiers(method.getModifiers());
469:            //        clonnedMethod.setName(method.getName());
470:            //        clonnedMethod.setType(method.getType());
471:            //        clonnedMethod.setJavadocText(javadoc);
472:            //        return clonnedMethod;
473:            //    }
474:
475:            private static String varFromName(final String name) {
476:                if (name.length() > 0) {
477:                    StringBuffer buf = new StringBuffer(name);
478:
479:                    // If the first character is uppercase, make it lowercase for the variable name,
480:                    // otherwise, prefix an underscore.
481:                    if (Character.isUpperCase(buf.charAt(0))) {
482:                        buf.setCharAt(0, Character.toLowerCase(buf.charAt(0)));
483:                    } else {
484:                        buf.insert(0, '_');
485:                    }
486:
487:                    return buf.toString();
488:                } else {
489:                    return "unknown"; // NOI18N
490:                }
491:            }
492:
493:            //FIX-ME: Is there a better way to find the artifact type of a project?
494:            private String getAntArtifactType(Project project) {
495:                AntArtifactProvider antArtifactProvider = (AntArtifactProvider) project
496:                        .getLookup().lookup(AntArtifactProvider.class);
497:                AntArtifact[] artifacts = antArtifactProvider
498:                        .getBuildArtifacts();
499:                return artifacts[0].getType();
500:            }
501:
502:            // Retouche
503:            //    private void addMethodJavaDocForHome(Method method, String ejbHome, String ejbLocalOrRemote) throws JmiException {
504:            //        StringBuffer text = new StringBuffer("Use this method to instantiate the EJB: \n");
505:            //        String ejbHomeVar = varFromName(ejbHome.substring(ejbHome.lastIndexOf('.') + 1));
506:            //        text.append(ejbHome+ " " + ejbHomeVar + "  = " + method.getName() +"(); \n");
507:            //        String ejbLocalOrRemoteVar = varFromName(ejbLocalOrRemote.substring(ejbLocalOrRemote.lastIndexOf('.') + 1));
508:            //        text.append(ejbLocalOrRemote + " " + ejbLocalOrRemoteVar + " = " + ejbHomeVar + ".create(<args>);");
509:            //        method.setJavadocText(text.toString());
510:            //    }
511:
512:            public String getServantClassName() {
513:                return implBeanClass;
514:            }
515:
516:            public String getSEIClassName() {
517:                return intfClass;
518:            }
519:
520:            public String getSEIBaseName() {
521:                return wsgenUtil.getBaseName(intfClass);
522:            }
523:
524:            public String getSoapBinding() {
525:                return soapBinding;
526:            }
527:
528:            public String getPortTypeName() {
529:                return portTypeName;
530:            }
531:
532:            public List getImportedSchemas() {
533:                return importedSchemaList;
534:            }
535:
536:            public String[] getWscompileFeatures() {
537:                return wscompileFeatures;
538:            }
539:
540:            public void addWebServiceEntry(String seiClassName,
541:                    String portTypeName, URI targetNS)
542:                    throws java.io.IOException {
543:                //Create webservices.xml skeleton file if required
544:                if (wsSupport.getWebservicesDD() == null) {
545:                    try {
546:                        final FileObject wsxmlTemplate = Repository
547:                                .getDefault()
548:                                .getDefaultFileSystem()
549:                                .findResource(
550:                                        "org-netbeans-modules-websvc-jaxrpc/webservices.xml"); //NOI18N
551:                        final FileObject wsddFolder = wsSupport.getWsDDFolder();
552:                        FileSystem fs = wsddFolder.getFileSystem();
553:                        fs.runAtomicAction(new FileSystem.AtomicAction() {
554:                            public void run() throws IOException {
555:                                FileUtil.copyFile(wsxmlTemplate, wsddFolder,
556:                                        WEBSERVICES_DD);
557:                            }
558:                        });
559:                    } catch (IOException ioe) {
560:                        ErrorManager.getDefault().notify(ioe);
561:                    }
562:                }
563:                //Add web service entry in the webservices.xml DD file
564:                org.netbeans.modules.j2ee.dd.api.webservices.DDProvider wsDDProvider = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider
565:                        .getDefault();
566:
567:                Webservices webServices = wsDDProvider.getDDRoot(wsSupport
568:                        .getWebservicesDD());
569:                if (webServices != null) {
570:                    try {
571:                        WebserviceDescription wsDescription = (WebserviceDescription) webServices
572:                                .createBean("WebserviceDescription"); //NOI18N
573:                        wsDescription.setWebserviceDescriptionName(wsName);
574:                        ServiceImplBean serviceImplBean = (ServiceImplBean) webServices
575:                                .createBean("ServiceImplBean"); //NOI18N
576:                        PortComponent portComponent = (PortComponent) webServices
577:                                .createBean("PortComponent"); //NOI18N
578:                        portComponent.setPortComponentName(wsName);
579:                        org.netbeans.modules.schema2beans.QName wsdlPortQName = new org.netbeans.modules.schema2beans.QName(
580:                                targetNS.toString(), //NOI18N
581:                                ((portTypeName == null) ? wsgenUtil
582:                                        .getBaseName(seiClassName)
583:                                        + "Port" : portTypeName + "Port"), //NOI18N
584:                                "wsdl-port_ns"); //TO-DO: get this from user(??)
585:                        portComponent.setWsdlPort(wsdlPortQName);
586:                        portComponent.setServiceEndpointInterface(seiClassName);
587:                        //add sevlet-link or ejb-link entry
588:                        wsSupport.addServiceImplLinkEntry(serviceImplBean,
589:                                wsName);
590:                        String wsDDFolder = wsSupport.getArchiveDDFolderName();
591:                        wsDescription.setWsdlFile(wsDDFolder + "/wsdl/"
592:                                + wsName + ".wsdl"); //NOI18N
593:                        wsDescription.setJaxrpcMappingFile(wsDDFolder + "/"
594:                                + wsName + "-mapping.xml"); //NOI18N
595:                        portComponent.setServiceImplBean(serviceImplBean);
596:                        wsDescription.addPortComponent(portComponent);
597:                        webServices.addWebserviceDescription(wsDescription);
598:                        webServices.write(wsSupport.getWebservicesDD());
599:                    } catch (ClassNotFoundException e) {
600:                        ErrorManager.getDefault().notify(e);
601:                    }
602:                }
603:            }
604:
605:            public URI getTargetNS() throws java.net.URISyntaxException {
606:                if (targetNS != null) {
607:                    return new URI(targetNS);
608:                }
609:                return getDefaultTargetNS(wsName);
610:            }
611:
612:            public URI getDefaultTargetNS(String wsName)
613:                    throws java.net.URISyntaxException {
614:                return new URI("urn:" + wsName + "/wsdl");
615:            }
616:
617:            public URI getDefaultTypeNS(String wsName)
618:                    throws java.net.URISyntaxException {
619:                return new URI("urn:" + wsName + "/types");
620:            }
621:
622:            //FIX-ME: Use DD beans in websvc/core
623:            public FileObject generateConfigFile(URI wsdlLocation)
624:                    throws java.io.IOException {
625:                FileObject configFile = pkg.createData(wsName + "-config",
626:                        "xml"); //NOI18N
627:                Configuration configuration = new Configuration();
628:                WsdlType wsdl = configuration.newWsdlType();
629:                wsdl.setLocation(wsdlLocation);
630:                wsdl.setPackageName(wsgenUtil.getSelectedPackageName(pkg,
631:                        project));
632:                configuration.setWsdl(wsdl);
633:
634:                FileLock lock = null;
635:                OutputStream out = null;
636:                try {
637:                    lock = configFile.lock();
638:                    out = configFile.getOutputStream(lock);
639:                    configuration.write(out, "UTF-8"); //NOI18N
640:                } catch (IOException ioe) {
641:                    ErrorManager.getDefault().notify(ioe);
642:                } finally {
643:                    if (lock != null)
644:                        lock.releaseLock();
645:                    if (out != null)
646:                        out.close();
647:                }
648:                return configFile;
649:            }
650:
651:            //FIX-ME: Use DD beans in websvc/core
652:            public FileObject generateConfigFile(String seiClassName,
653:                    String servantClassName, URI targetNS, URI typeNS)
654:                    throws java.io.IOException {
655:                FileObject configFile = pkg.createData(wsName + "-config",
656:                        "xml"); //NOI18N
657:
658:                Configuration configuration = new Configuration();
659:                org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.ServiceType service = new org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.ServiceType();
660:                service.setName(wsName);
661:                service.setTargetNamespace(targetNS);
662:                service.setTypeNamespace(typeNS);
663:                service.setPackageName(wsgenUtil.getSelectedPackageName(pkg,
664:                        project));
665:                InterfaceType interf = new InterfaceType();
666:                interf.setName(seiClassName);
667:                interf.setServantName(servantClassName);
668:                service.setInterface(new InterfaceType[] { interf });
669:                configuration.setService(service);
670:
671:                FileLock lock = null;
672:                OutputStream out = null;
673:                try {
674:                    lock = configFile.lock();
675:                    out = configFile.getOutputStream(lock);
676:                    configuration.write(out, "UTF-8"); //NOI18N
677:                } catch (IOException ioe) {
678:                    ErrorManager.getDefault().notify(ioe);
679:                } finally {
680:                    if (lock != null)
681:                        lock.releaseLock();
682:                    if (out != null)
683:                        out.close();
684:                }
685:                return configFile;
686:            }
687:
688:            public static final String WSCOMPILE_CLASSPATH = "wscompile.classpath"; //NOI18N
689:
690:        }
www_._j_ava___2___s___.__c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.