KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > WebServiceGenerator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.dev.wizard;
21
22 import org.openide.filesystems.FileObject;
23 import org.netbeans.api.project.Project;
24 import java.io.IOException JavaDoc;
25 import org.netbeans.modules.websvc.dev.dd.gen.wscreation.Bean;
26 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
27 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
28 import org.netbeans.modules.j2ee.dd.api.webservices.ServiceImplBean;
29 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent;
30 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
31 import java.net.URI JavaDoc;
32 import org.openide.filesystems.FileLock;
33 import java.io.OutputStream JavaDoc;
34 import org.netbeans.modules.websvc.dev.dd.gen.Configuration;
35 import org.netbeans.modules.websvc.dev.dd.gen.InterfaceType;
36 import org.openide.filesystems.FileSystem;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.filesystems.Repository;
39 import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation;
40 import org.openide.nodes.Node;
41 import org.netbeans.api.project.ant.AntArtifact;
42 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef;
43 import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
44 import org.netbeans.modules.j2ee.api.ejbjar.EjbReference;
45 import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer;
46 import org.netbeans.spi.project.ant.AntArtifactProvider;
47 import org.netbeans.modules.websvc.dev.dd.gen.WsdlType;
48 import java.util.Iterator JavaDoc;
49 import javax.xml.parsers.ParserConfigurationException JavaDoc;
50 import javax.xml.parsers.SAXParser JavaDoc;
51 import javax.xml.parsers.SAXParserFactory JavaDoc;
52 import javax.xml.transform.stream.StreamSource JavaDoc;
53 import org.netbeans.modules.websvc.wsdl.PortInformationHandler;
54 import org.xml.sax.SAXException JavaDoc;
55 import java.io.InputStream JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Set JavaDoc;
58
59 import org.openide.ErrorManager;
60 import org.openide.NotifyDescriptor;
61 import org.openide.DialogDisplayer;
62 import org.openide.util.NbBundle;
63
64 public class WebServiceGenerator {
65     private WSGenerationUtil wsgenUtil = new WSGenerationUtil();
66     private static final String JavaDoc WEBSERVICE_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE+"WSImplBean.xml"; //NOI18N
67
private static final String JavaDoc WEBSERVICEJAVAEE5_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE+"WSImplBeanJavaEE5.xml"; //NOI18N
68
private static final String JavaDoc INTERFACE_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE+"WSInterface.xml"; //NOI18N
69
private static final String JavaDoc HANDLER_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE+"MessageHandler.xml"; //NOI18N
70
public static final String JavaDoc WSDL_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE+"WSDL.xml"; //NOI18N
71

72     private String JavaDoc implBeanClass = "";
73     private String JavaDoc intfClass = "";
74     private String JavaDoc targetNS = null;
75     private String JavaDoc soapBinding = "";
76     private String JavaDoc portTypeName = null;
77     public static final String JavaDoc WEBSERVICES_DD = "webservices";//NOI18N
78
private WebServicesSupport wsSupport;
79     private String JavaDoc wsName;
80     private FileObject pkg;
81     private Project project;
82     private List JavaDoc importedSchemaList;
83     // flag indicating if service name need to be changed (happens when portName=service name)
84
// Issue 58509
85
private boolean changeWsName;
86     private String JavaDoc[] wscompileFeatures;
87     
88     public WebServiceGenerator(WebServicesSupport wsSupport, String JavaDoc wsName, FileObject pkg, Project project) {
89         this.wsSupport = wsSupport;
90         this.wsName = wsName;
91         this.pkg = pkg;
92         this.project = project;
93     }
94     
95     public WebServiceGenerator(FileObject pkg, Project project){
96         this.pkg = pkg;
97         this.project = project;
98     }
99     
100     public void generateWebService() throws IOException JavaDoc {
101         generateWebService(null);
102     }
103     
104     public FileObject generateWSDL(String JavaDoc template, String JavaDoc wsName, String JavaDoc soapBinding, String JavaDoc portTypeName, FileObject folder, FileObject originalFolder, String JavaDoc wsdlName, StreamSource JavaDoc source) throws IOException JavaDoc {
105         return wsgenUtil.generateWSDL(template, wsName, soapBinding, portTypeName, folder, originalFolder, wsdlName, source);
106     }
107
108     public FileObject generateWSDL(String JavaDoc template, String JavaDoc wsName, String JavaDoc soapBinding, String JavaDoc portTypeName, FileObject folder, String JavaDoc wsdlName, StreamSource JavaDoc source) throws IOException JavaDoc {
109         return wsgenUtil.generateWSDL(template, wsName, soapBinding, portTypeName, folder, wsdlName, source);
110     }
111
112     /**
113      * Parse the original wsdl to obtain the portType name, targetNamespace and SOAP
114      * binding. Note that if no SOAP binding in obtained, the first portType
115      * name that is encountered is used.
116      * @return changed service name or null
117      */

118     public String JavaDoc parseWSDL(InputStream JavaDoc wsdlInputStream) throws IOException JavaDoc, NoWSPortDefinedException {
119         //parse the wsdl to get SEI class name and target namespace
120

121         String JavaDoc changedWsName=null;
122         
123         PortInformationHandler handler = new PortInformationHandler();
124         
125         try {
126             SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
127             factory.setNamespaceAware(true);
128             SAXParser JavaDoc saxParser = factory.newSAXParser();
129             saxParser.parse(wsdlInputStream, handler);
130         }
131         catch(ParserConfigurationException JavaDoc ex) {
132             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
133             String JavaDoc mes = NbBundle.getMessage(WebServiceGenerator.class, "ERR_WsdlParseFailure"); // NOI18N
134
NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
135             DialogDisplayer.getDefault().notify(desc);
136             return changedWsName;
137         }
138         catch(SAXException JavaDoc ex) {
139             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
140             String JavaDoc mes = NbBundle.getMessage(WebServiceGenerator.class, "ERR_WsdlParseFailure"); // NOI18N
141
NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
142             DialogDisplayer.getDefault().notify(desc);
143             return changedWsName;
144         }
145         
146         List JavaDoc entirePortList = handler.getEntirePortList();
147         if (entirePortList.isEmpty()) {
148             throw new NoWSPortDefinedException();
149         }
150         Iterator JavaDoc iterator = entirePortList.iterator();
151         String JavaDoc firstPortType = null;
152         while(iterator.hasNext()) {
153             PortInformationHandler.PortInfo portInfo = (PortInformationHandler.PortInfo)iterator.next();
154             if(firstPortType == null){
155                 //there should at least be one portType in the WSDL
156
firstPortType = portInfo.getPortType();
157             }
158             //get the first SOAP binding
159
if(portInfo.getBindingType() != null &&
160             portInfo.getBindingType().equals("http://schemas.xmlsoap.org/wsdl/soap")) { //NOI18N
161
portTypeName = portInfo.getPortType();
162                 soapBinding = portInfo.getBinding();
163                 break;
164             }
165         }
166         //if no soap binding was found, use the first portType encountered
167
if(portTypeName == null) {
168             portTypeName = firstPortType;
169         }
170         if (portTypeName == null) {
171             throw new NoWSPortDefinedException();
172         }
173         //get name of SEI and Impl class name from portTypeName. In future, we should get this from
174
//wscompile spi
175
intfClass = WSGenerationUtil.getSelectedPackageName(pkg, project) + "." + normalizePortTypeName(portTypeName);
176         implBeanClass = intfClass + "_Impl"; //NOI18N
177
targetNS = handler.getTargetNamespace();
178         importedSchemaList = handler.getImportedSchemas();
179         if (changeWsName) changedWsName=wsName+"_Service"; //NOI18N
180
Set JavaDoc features = handler.getWscompileFeatures();
181         wscompileFeatures=new String JavaDoc[features.size()];
182         features.toArray(wscompileFeatures);
183         return changedWsName;
184     }
185     
186     /*
187      * if portTypeName does not start with uppercase character, make it
188      * uppercase. This is the convention used by wscompile in naming
189      * the generated SEI and impl bean classes
190      */

191     private String JavaDoc normalizePortTypeName(String JavaDoc portTypeName) {
192         if (portTypeName == null) {
193             return "unknown"; //NOI18N
194
}
195         String JavaDoc first = portTypeName.substring(0,1);
196         String JavaDoc result = first.toUpperCase() + ((portTypeName.length() > 1) ? portTypeName.substring(1) : "");
197         if (result.equals(wsName)) {
198             changeWsName=true;
199         }
200         return result;
201             
202     }
203     
204     public void generateMessageHandler(String JavaDoc handlerName) throws IOException JavaDoc{
205         String JavaDoc pkgName = wsgenUtil.getSelectedPackageName(pkg, project);
206         Bean b = wsgenUtil.getDefaultBean();
207         b.setCommentDataWsName(handlerName);
208         b.setClassname(true);
209         b.setClassnameName(handlerName);
210         if(pkgName != null) {
211             b.setClassnamePackage(pkgName);
212         }
213         String JavaDoc handlerClass = wsgenUtil.getFullClassName(pkgName,
214         wsgenUtil.generateClass(HANDLER_TEMPLATE, b, pkg, true));
215     }
216     
217     public void generateWebService( Node[] nodes) throws IOException JavaDoc {
218         String JavaDoc pkgName = wsgenUtil.getSelectedPackageName(pkg, project);
219
220         Bean b = wsgenUtil.getDefaultBean();
221         b.setCommentDataWsName(wsName);
222         b.setClassname(true);
223         b.setDelegateData("");
224
225         b.setClassnameName(wsgenUtil.getBeanClassName(wsName));
226
227         if (pkgName != null) {
228             b.setClassnamePackage(pkgName);
229         }
230
231         //FIXE-ME: need to delegate impl bean class to the web module
232
if (project.getLookup().lookup(WebModuleImplementation.class) != null) {
233             implBeanClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil.generateClass(WEBSERVICE_TEMPLATE, b, pkg, true));
234             b.setClassnameName(wsgenUtil.getSEIName(wsName));
235             intfClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil.generateClass(INTERFACE_TEMPLATE, b, pkg, false));
236             if (implBeanClass!=null) {
237 // Retouche
238
// boolean rollback = true;
239
// JMIUtils.beginJmiTransaction(true);
240
// try {
241
// JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
242
// if (jc != null && jc.isValid()) {
243
// addDelegateMethod(nodes, jc);
244
// }
245
// rollback=false;
246
// } catch (Exception ex) {
247
// } finally {
248
// JMIUtils.endJmiTransaction(rollback);
249
// }
250
}
251         } else {
252             try {
253                 implBeanClass = wsSupport.generateImplementationBean(wsName, pkg, project, null);
254                 b.setClassnameName(wsgenUtil.getSEIName(wsName));
255                 intfClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil.generateClass(INTERFACE_TEMPLATE, b, pkg, false));
256             } catch (java.io.IOException JavaDoc e) {
257                 //FIX-ME: handle this
258
throw new RuntimeException JavaDoc(e.getMessage(), e);
259             }
260             if (implBeanClass!=null) {
261 // Retouche
262
// boolean rollback = true;
263
// JMIUtils.beginJmiTransaction(true);
264
// try {
265
// JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
266
// if (jc != null) {
267
// addDelegateMethod(nodes, jc);
268
// }
269
// rollback=false;
270
// } catch (Exception ex) {
271
// } finally {
272
// JMIUtils.endJmiTransaction(rollback);
273
// }
274
}
275         }
276     }
277
278     public void generateWebServiceJavaEE5(Node[] nodes) throws IOException JavaDoc {
279         String JavaDoc pkgName = wsgenUtil.getSelectedPackageName(pkg, project);
280
281         Bean b = wsgenUtil.getDefaultBean();
282         b.setCommentDataWsName(wsName);
283         b.setClassname(true);
284         b.setDelegateData("");
285
286         b.setClassnameName(wsgenUtil.getBeanClassName(wsName));
287
288         if (pkgName != null) {
289             b.setClassnamePackage(pkgName);
290         }
291
292         //FIXE-ME: need to delegate impl bean class to the web module
293
if (project.getLookup().lookup(WebModuleImplementation.class) != null) {
294             implBeanClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil.generateClass(WEBSERVICEJAVAEE5_TEMPLATE, b, pkg, true));
295             b.setClassnameName(wsgenUtil.getSEIName(wsName));
296             if (implBeanClass!=null) {
297                 boolean rollback = true;
298 // Retouche
299
// JMIUtils.beginJmiTransaction(true);
300
// try {
301
// JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
302
//
303
// Annotation wsAnnotation = JMIGenerationUtil.createAnnotation(jc, "javax.jws.WebService", Collections.EMPTY_LIST); //NOI18N
304
// jc.getAnnotations().add(wsAnnotation);
305
//
306
// if (jc != null && jc.isValid()) {
307
// addDelegateMethod(nodes, jc);
308
// }
309
// rollback=false;
310
// } catch (Exception ex) {
311
// } finally {
312
// JMIUtils.endJmiTransaction(rollback);
313
// }
314
}
315         } else {
316             try {
317                 implBeanClass = wsSupport.generateImplementationBean(wsName, pkg, project, null);
318                 b.setClassnameName(wsgenUtil.getSEIName(wsName));
319             } catch (java.io.IOException JavaDoc e) {
320                 //FIX-ME: handle this
321
throw new RuntimeException JavaDoc(e.getMessage(), e);
322             }
323             if (implBeanClass!=null) {
324 // Retouche
325
// boolean rollback = true;
326
// JMIUtils.beginJmiTransaction(true);
327
// try {
328
// JavaClass jc = JMIUtils.findClass(implBeanClass, pkg);
329
//
330
// Annotation statelessAnnotation = JMIGenerationUtil.createAnnotation(jc, "javax.ejb.Stateless", Collections.EMPTY_LIST); //NOI18N
331
// jc.getAnnotations().add(statelessAnnotation);
332
// Annotation wsAnnotation = JMIGenerationUtil.createAnnotation(jc, "javax.jws.WebService", Collections.EMPTY_LIST); //NOI18N
333
// jc.getAnnotations().add(wsAnnotation);
334
//
335
// if (jc != null) {
336
// addDelegateMethod(nodes, jc);
337
// }
338
// rollback=false;
339
// } catch (Exception ex) {
340
// } finally {
341
// JMIUtils.endJmiTransaction(rollback);
342
// }
343
}
344         }
345     }
346
347     
348     public void addReferences(String JavaDoc beanClassName, Node[] nodes) {
349         for(int i = 0; i < nodes.length; i++) {
350             Node node = nodes[i];
351             EjbReference ref = (EjbReference)node.getCookie(EjbReference.class);
352             if(ref != null) {
353                 EnterpriseReferenceContainer erc = (EnterpriseReferenceContainer)project.getLookup()
354                 .lookup(EnterpriseReferenceContainer.class);
355                 if(ref.supportsRemoteInvocation()) {
356                     EjbRef ejbRef = ref.createRef();
357                     if(ejbRef.getEjbRefType().equals("Session")) { //NOI18N
358
try {
359 // Retouche
360
// erc.addEjbReference(ejbRef, beanClassName, ref.getClientJarTarget());
361
}
362                         catch(Exception JavaDoc e) {
363                             throw new RuntimeException JavaDoc(e.getMessage());
364                         }
365                     }
366                 }
367                 if(!ref.supportsRemoteInvocation() &&
368                 ref.supportsLocalInvocation()) {
369                     EjbLocalRef ejbLocalRef = ref.createLocalRef();
370                     if(ejbLocalRef.getEjbRefType().equals("Session")) { //NOI18N
371
try {
372 // Retouche
373
// erc.addEjbLocalReference(ejbLocalRef, beanClassName, ref.getClientJarTarget());
374
}
375                         catch(Exception JavaDoc e) {
376                             throw new RuntimeException JavaDoc(e.getMessage());
377                         }
378                     }
379                 }
380             }
381             else //Java class
382
{
383 // Retouche
384
// JavaClass classElement = JMIUtils.getJavaClassFromNode(node);
385
// assert (classElement != null);
386
//
387
// //find out if the class is in the same project or not
388
// FileObject srcFile = JavaMetamodel.getManager().getDataObject(classElement.getResource()).getPrimaryFile();
389
//
390
// Project p = FileOwnerQuery.getOwner(srcFile);
391
// if(p != null) //project can be determined. if not, class is
392
// //not in any project and is assumed to already be
393
// //in the classpath
394
// {
395
// if(!project.equals(p )) //not in same project
396
// {
397
// AntArtifact target = AntArtifactQuery.findArtifactsByType(p, getAntArtifactType(p))[0];
398
// ReferenceHelper helper = wsSupport.getReferenceHelper();
399
// if(helper.addReference(target)) {
400
// AntProjectHelper antHelper = wsSupport.getAntProjectHelper();
401
// EditableProperties ep =
402
// antHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
403
// String s = ep.getProperty("javac.classpath"); //FIX-ME:get from project
404
// s += File.pathSeparatorChar + helper.createForeignFileReference(target);
405
// ep.setProperty("javac.classpath", s);
406
// antHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
407
// }
408
// try {
409
// ProjectManager.getDefault().saveProject(project);
410
// }
411
// catch(java.io.IOException e) {
412
// throw new RuntimeException(e.getMessage());
413
// }
414
// }
415
// }
416
}
417         }
418     }
419 // Retouche
420
// public void addDelegateMethod(Node[] nodes, final JavaClass jc) {
421
// if (nodes == null) return;
422
// for (int i = 0; i < nodes.length; i++) {
423
// Node node = nodes[i];
424
// EjbReference ref = (EjbReference)node.getCookie(EjbReference.class);
425
// if (ref != null) {
426
// if (ref.supportsRemoteInvocation()) {
427
// EjbRef ejbRef = ref.createRef();
428
// if (ejbRef.getEjbRefType().equals("Session")) { //NOI18N
429
// try {
430
// Feature f = ref.generateReferenceCode(jc, ejbRef, false);
431
// if (f instanceof Method) {
432
// Method method = (Method) f;
433
// //if Home is returned, add comment on how to get EJB
434
// if(method.getType().getName().equals(ejbRef.getHome())) {
435
// addMethodJavaDocForHome(method, ejbRef.getHome(), ejbRef.getRemote());
436
// }
437
// ((Method) method).setJavadocText(NbBundle.getMessage(WebServiceGenerator.class,"MSG_JAVADOC_LOOKUP_REMOTE"));
438
// };
439
// } catch(Exception e) {
440
// throw new RuntimeException(e.getMessage());
441
// }
442
// }
443
// }
444
// if (!ref.supportsRemoteInvocation() && ref.supportsLocalInvocation()) {
445
// EjbLocalRef ejbLocalRef = ref.createLocalRef();
446
// if (ejbLocalRef.getEjbRefType().equals("Session")) {
447
// try {
448
// Feature f = ref.generateReferenceCode(jc, ejbLocalRef, false);
449
// if (f instanceof Method) {
450
// Method method = (Method) f;
451
// //if LocalHome is returned, add comment on how to get EJB
452
// if (method.getType().getName().equals(ejbLocalRef.getLocalHome())) {
453
// addMethodJavaDocForHome(method, ejbLocalRef.getLocalHome(), ejbLocalRef.getLocal());
454
// }
455
// ((Method) method).setJavadocText(NbBundle.getMessage(WebServiceGenerator.class,"MSG_JAVADOC_LOOKUP_LOCAL"));
456
// }
457
// } catch (Exception e) {
458
// throw new RuntimeException(e.getMessage());
459
// }
460
// }
461
// }
462
// } else { //Java class
463
// JavaClass classElement = JMIUtils.getJavaClassFromNode(node);
464
// assert (classElement != null);
465
//
466
// JavaModelPackage jmp = (JavaModelPackage) classElement.refImmediatePackage();
467
//
468
// Field field = jmp.getField().createField();
469
// field.setName(classElement.getName());
470
// String name = varFromName(classElement.getName());
471
//// buffer.append(field.getName() + " " + name + ";");
472
// }
473
// }
474
// }
475
//
476
// private Method createClone(JavaClass jc, Method method, String javadoc) {
477
// Method clonnedMethod = JMIUtils.createMethod(jc);
478
// clonnedMethod.setBodyText(method.getBodyText());
479
// clonnedMethod.setModifiers(method.getModifiers());
480
// clonnedMethod.setName(method.getName());
481
// clonnedMethod.setType(method.getType());
482
// clonnedMethod.setJavadocText(javadoc);
483
// return clonnedMethod;
484
// }
485

486     private static String JavaDoc varFromName(final String JavaDoc name) {
487         if(name.length() > 0) {
488             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(name);
489             
490             // If the first character is uppercase, make it lowercase for the variable name,
491
// otherwise, prefix an underscore.
492
if(Character.isUpperCase(buf.charAt(0))) {
493                 buf.setCharAt(0, Character.toLowerCase(buf.charAt(0)));
494             } else {
495                 buf.insert(0, '_');
496             }
497             
498             return buf.toString();
499         } else {
500             return "unknown"; // NOI18N
501
}
502     }
503     
504     //FIX-ME: Is there a better way to find the artifact type of a project?
505
private String JavaDoc getAntArtifactType(Project project){
506         AntArtifactProvider antArtifactProvider = (AntArtifactProvider)project.getLookup().lookup(AntArtifactProvider.class);
507         AntArtifact[] artifacts = antArtifactProvider.getBuildArtifacts();
508         return artifacts[0].getType();
509     }
510
511 // Retouche
512
// private void addMethodJavaDocForHome(Method method, String ejbHome, String ejbLocalOrRemote) throws JmiException {
513
// StringBuffer text = new StringBuffer("Use this method to instantiate the EJB: \n");
514
// String ejbHomeVar = varFromName(ejbHome.substring(ejbHome.lastIndexOf('.') + 1));
515
// text.append(ejbHome+ " " + ejbHomeVar + " = " + method.getName() +"(); \n");
516
// String ejbLocalOrRemoteVar = varFromName(ejbLocalOrRemote.substring(ejbLocalOrRemote.lastIndexOf('.') + 1));
517
// text.append(ejbLocalOrRemote + " " + ejbLocalOrRemoteVar + " = " + ejbHomeVar + ".create(<args>);");
518
// method.setJavadocText(text.toString());
519
// }
520

521     public String JavaDoc getServantClassName() {
522         return implBeanClass;
523     }
524     
525     public String JavaDoc getSEIClassName() {
526         return intfClass;
527     }
528     
529     public String JavaDoc getSEIBaseName() {
530         return wsgenUtil.getBaseName(intfClass);
531     }
532     
533     public String JavaDoc getSoapBinding(){
534         return soapBinding;
535     }
536     
537     public String JavaDoc getPortTypeName(){
538         return portTypeName;
539     }
540     
541     public List JavaDoc getImportedSchemas() {
542         return importedSchemaList;
543     }
544     
545     public String JavaDoc[] getWscompileFeatures() {
546         return wscompileFeatures;
547     }
548     
549     public void addWebServiceEntry(String JavaDoc seiClassName, String JavaDoc portTypeName, URI JavaDoc targetNS )
550     throws java.io.IOException JavaDoc {
551         //Create webservices.xml skeleton file if required
552
if(wsSupport.getWebservicesDD() == null) {
553               try {
554                 final FileObject wsxmlTemplate = Repository.getDefault().getDefaultFileSystem().
555                         findResource("org-netbeans-modules-websvc-dev/webservices.xml"); //NOI18N
556
final FileObject wsddFolder = wsSupport.getWsDDFolder();
557                 FileSystem fs = wsddFolder.getFileSystem();
558                 fs.runAtomicAction(new FileSystem.AtomicAction() {
559                     public void run() throws IOException JavaDoc {
560                         FileUtil.copyFile(wsxmlTemplate, wsddFolder, WEBSERVICES_DD);
561                     }
562                 });
563             } catch(IOException JavaDoc ioe) {
564
565                 throw new RuntimeException JavaDoc(ioe.getMessage());
566             }
567         }
568         //Add web service entry in the webservices.xml DD file
569
org.netbeans.modules.j2ee.dd.api.webservices.DDProvider wsDDProvider =
570         org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault();
571         
572         Webservices webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD());
573         if(webServices != null){
574             try{
575                 WebserviceDescription wsDescription =
576                 (WebserviceDescription)webServices.createBean("WebserviceDescription"); //NOI18N
577
wsDescription.setWebserviceDescriptionName(wsName);
578                 ServiceImplBean serviceImplBean =
579                 (ServiceImplBean)webServices.createBean("ServiceImplBean"); //NOI18N
580
PortComponent portComponent =
581                 (PortComponent)webServices.createBean("PortComponent"); //NOI18N
582
portComponent.setPortComponentName(wsName);
583                 org.netbeans.modules.schema2beans.QName wsdlPortQName =
584                     new org.netbeans.modules.schema2beans.QName(targetNS.toString(), //NOI18N
585
((portTypeName == null) ? wsgenUtil.getBaseName(seiClassName) + "Port" : portTypeName + "Port"), //NOI18N
586
"wsdl-port_ns"); //TO-DO: get this from user(??)
587
portComponent.setWsdlPort(wsdlPortQName);
588                 portComponent.setServiceEndpointInterface
589                 (seiClassName);
590                 //add sevlet-link or ejb-link entry
591
wsSupport.addServiceImplLinkEntry(serviceImplBean, wsName);
592                 String JavaDoc wsDDFolder = wsSupport.getArchiveDDFolderName();
593                 wsDescription.setWsdlFile( wsDDFolder + "/wsdl/" + wsName + ".wsdl"); //NOI18N
594
wsDescription.setJaxrpcMappingFile(wsDDFolder +"/" + wsName + "-mapping.xml"); //NOI18N
595
portComponent.setServiceImplBean(serviceImplBean);
596                 wsDescription.addPortComponent(portComponent);
597                 webServices.addWebserviceDescription(wsDescription);
598                 webServices.write(wsSupport.getWebservicesDD());
599             }catch(ClassNotFoundException JavaDoc e){
600                 throw new RuntimeException JavaDoc(e.getMessage());
601             }
602         }
603     }
604     
605     public URI JavaDoc getTargetNS() throws java.net.URISyntaxException JavaDoc {
606         if(targetNS != null) {
607             return new URI JavaDoc(targetNS);
608         }
609         return getDefaultTargetNS(wsName);
610     }
611     
612     
613     public URI JavaDoc getDefaultTargetNS(String JavaDoc wsName) throws java.net.URISyntaxException JavaDoc {
614         return new URI JavaDoc("urn:" + wsName + "/wsdl");
615     }
616     
617     public URI JavaDoc getDefaultTypeNS(String JavaDoc wsName) throws java.net.URISyntaxException JavaDoc {
618         return new URI JavaDoc("urn:" + wsName + "/types");
619     }
620     
621     //FIX-ME: Use DD beans in websvc/core
622
public FileObject generateConfigFile(URI JavaDoc wsdlLocation)throws java.io.IOException JavaDoc {
623         FileObject configFile = pkg.createData(wsName + "-config", "xml"); //NOI18N
624
Configuration configuration = new Configuration();
625         WsdlType wsdl = configuration.newWsdlType();
626         wsdl.setLocation(wsdlLocation);
627         wsdl.setPackageName(wsgenUtil.getSelectedPackageName(pkg, project));
628         configuration.setWsdl(wsdl);
629         
630         FileLock lock = null;
631         OutputStream JavaDoc out = null;
632         try{
633             lock = configFile.lock();
634             out = configFile.getOutputStream(lock);
635             configuration.write(out, "UTF-8"); //NOI18N
636
}
637         catch(IOException JavaDoc ioe){
638             throw new RuntimeException JavaDoc(ioe.getMessage());
639         }
640         finally {
641             if(lock != null)
642                 lock.releaseLock();
643             if(out != null)
644                 out.close();
645         }
646         return configFile;
647     }
648     
649     
650     //FIX-ME: Use DD beans in websvc/core
651
public FileObject generateConfigFile(String JavaDoc seiClassName, String JavaDoc servantClassName, URI JavaDoc targetNS, URI JavaDoc typeNS) throws java.io.IOException JavaDoc {
652         FileObject configFile = pkg.createData(wsName + "-config", "xml"); //NOI18N
653

654         Configuration configuration = new Configuration();
655         org.netbeans.modules.websvc.dev.dd.gen.ServiceType service =
656         new org.netbeans.modules.websvc.dev.dd.gen.ServiceType();
657         service.setName(wsName);
658         service.setTargetNamespace(targetNS);
659         service.setTypeNamespace(typeNS);
660         service.setPackageName(wsgenUtil.getSelectedPackageName(pkg, project));
661         InterfaceType interf = new InterfaceType();
662         interf.setName(seiClassName);
663         interf.setServantName(servantClassName);
664         service.setInterface(new InterfaceType[] {interf});
665         configuration.setService(service);
666         
667         FileLock lock = null;
668         OutputStream JavaDoc out = null;
669         try{
670             lock = configFile.lock();
671             out = configFile.getOutputStream(lock);
672             configuration.write(out, "UTF-8"); //NOI18N
673
}
674         catch(IOException JavaDoc ioe){
675             throw new RuntimeException JavaDoc(ioe.getMessage());
676         }
677         finally {
678             if(lock != null)
679                 lock.releaseLock();
680             if(out != null)
681                 out.close();
682         }
683         return configFile;
684     }
685     
686     public static final String JavaDoc WSCOMPILE_CLASSPATH = "wscompile.classpath"; //NOI18N
687

688 }
689
690
691
Popular Tags