KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

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

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

416     private static String JavaDoc varFromName(final String JavaDoc name) {
417         if(name.length() > 0) {
418             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(name);
419             
420             // If the first character is uppercase, make it lowercase for the variable name,
421
// otherwise, prefix an underscore.
422
if(Character.isUpperCase(buf.charAt(0))) {
423                 buf.setCharAt(0, Character.toLowerCase(buf.charAt(0)));
424             } else {
425                 buf.insert(0, '_');
426             }
427             
428             return buf.toString();
429         } else {
430             return "unknown"; // NOI18N
431
}
432     }
433     
434     //FIX-ME: Is there a better way to find the artifact type of a project?
435
private String JavaDoc getAntArtifactType(Project project){
436         AntArtifactProvider antArtifactProvider = (AntArtifactProvider)project.getLookup().lookup(AntArtifactProvider.class);
437         AntArtifact[] artifacts = antArtifactProvider.getBuildArtifacts();
438         return artifacts[0].getType();
439     }
440
441 // Retouche
442
// private void addMethodJavaDocForHome(Method method, String ejbHome, String ejbLocalOrRemote) throws JmiException {
443
// StringBuffer text = new StringBuffer("Use this method to instantiate the EJB: \n");
444
// String ejbHomeVar = varFromName(ejbHome.substring(ejbHome.lastIndexOf('.') + 1));
445
// text.append(ejbHome+ " " + ejbHomeVar + " = " + method.getName() +"(); \n");
446
// String ejbLocalOrRemoteVar = varFromName(ejbLocalOrRemote.substring(ejbLocalOrRemote.lastIndexOf('.') + 1));
447
// text.append(ejbLocalOrRemote + " " + ejbLocalOrRemoteVar + " = " + ejbHomeVar + ".create(<args>);");
448
// method.setJavadocText(text.toString());
449
// }
450

451     public String JavaDoc getServantClassName() {
452         return implBeanClass;
453     }
454     
455     public String JavaDoc getSEIClassName() {
456         return intfClass;
457     }
458     
459     public String JavaDoc getSEIBaseName() {
460         return wsgenUtil.getBaseName(intfClass);
461     }
462     
463     public String JavaDoc getSoapBinding(){
464         return soapBinding;
465     }
466     
467     public String JavaDoc getPortTypeName(){
468         return portTypeName;
469     }
470     
471     public List JavaDoc getImportedSchemas() {
472         return importedSchemaList;
473     }
474     
475     public String JavaDoc[] getWscompileFeatures() {
476         return wscompileFeatures;
477     }
478     
479     public void addWebServiceEntry(String JavaDoc seiClassName, String JavaDoc portTypeName, URI JavaDoc targetNS )
480     throws java.io.IOException JavaDoc {
481         //Create webservices.xml skeleton file if required
482
if(wsSupport.getWebservicesDD() == null) {
483               try {
484                 final FileObject wsxmlTemplate = Repository.getDefault().getDefaultFileSystem().
485                         findResource("org-netbeans-modules-websvc-jaxrpc/webservices.xml"); //NOI18N
486
System.out.println("wsxmlTemplate = " + wsxmlTemplate);
487                 final FileObject wsddFolder = wsSupport.getWsDDFolder();
488                 FileSystem fs = wsddFolder.getFileSystem();
489                 fs.runAtomicAction(new FileSystem.AtomicAction() {
490                     public void run() throws IOException JavaDoc {
491                         FileUtil.copyFile(wsxmlTemplate, wsddFolder, WEBSERVICES_DD);
492                     }
493                 });
494             } catch(IOException JavaDoc ioe) {
495
496                 throw new RuntimeException JavaDoc(ioe.getMessage());
497             }
498         }
499         //Add web service entry in the webservices.xml DD file
500
org.netbeans.modules.j2ee.dd.api.webservices.DDProvider wsDDProvider =
501         org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault();
502         
503         Webservices webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD());
504         if(webServices != null){
505             try{
506                 WebserviceDescription wsDescription =
507                 (WebserviceDescription)webServices.createBean("WebserviceDescription"); //NOI18N
508
wsDescription.setWebserviceDescriptionName(wsName);
509                 ServiceImplBean serviceImplBean =
510                 (ServiceImplBean)webServices.createBean("ServiceImplBean"); //NOI18N
511
PortComponent portComponent =
512                 (PortComponent)webServices.createBean("PortComponent"); //NOI18N
513
portComponent.setPortComponentName(wsName);
514                 org.netbeans.modules.schema2beans.QName wsdlPortQName =
515                     new org.netbeans.modules.schema2beans.QName(targetNS.toString(), //NOI18N
516
((portTypeName == null) ? wsgenUtil.getBaseName(seiClassName) + "Port" : portTypeName + "Port"), //NOI18N
517
"wsdl-port_ns"); //TO-DO: get this from user(??)
518
portComponent.setWsdlPort(wsdlPortQName);
519                 portComponent.setServiceEndpointInterface
520                 (seiClassName);
521                 //add sevlet-link or ejb-link entry
522
wsSupport.addServiceImplLinkEntry(serviceImplBean, wsName);
523                 String JavaDoc wsDDFolder = wsSupport.getArchiveDDFolderName();
524                 wsDescription.setWsdlFile( wsDDFolder + "/wsdl/" + wsName + ".wsdl"); //NOI18N
525
wsDescription.setJaxrpcMappingFile(wsDDFolder +"/" + wsName + "-mapping.xml"); //NOI18N
526
portComponent.setServiceImplBean(serviceImplBean);
527                 wsDescription.addPortComponent(portComponent);
528                 webServices.addWebserviceDescription(wsDescription);
529                 webServices.write(wsSupport.getWebservicesDD());
530             }catch(ClassNotFoundException JavaDoc e){
531                 throw new RuntimeException JavaDoc(e.getMessage());
532             }
533         }
534     }
535     
536     public URI JavaDoc getTargetNS() throws java.net.URISyntaxException JavaDoc {
537         if(targetNS != null) {
538             return new URI JavaDoc(targetNS);
539         }
540         return getDefaultTargetNS(wsName);
541     }
542     
543     
544     public URI JavaDoc getDefaultTargetNS(String JavaDoc wsName) throws java.net.URISyntaxException JavaDoc {
545         return new URI JavaDoc("urn:" + wsName + "/wsdl");
546     }
547     
548     public URI JavaDoc getDefaultTypeNS(String JavaDoc wsName) throws java.net.URISyntaxException JavaDoc {
549         return new URI JavaDoc("urn:" + wsName + "/types");
550     }
551     
552     //FIX-ME: Use DD beans in websvc/core
553
public FileObject generateConfigFile(URI JavaDoc wsdlLocation)throws java.io.IOException JavaDoc {
554         FileObject configFile = pkg.createData(wsName + "-config", "xml"); //NOI18N
555
Configuration configuration = new Configuration();
556         WsdlType wsdl = configuration.newWsdlType();
557         wsdl.setLocation(wsdlLocation);
558         wsdl.setPackageName(wsgenUtil.getSelectedPackageName(pkg, project));
559         configuration.setWsdl(wsdl);
560         
561         FileLock lock = null;
562         OutputStream JavaDoc out = null;
563         try{
564             lock = configFile.lock();
565             out = configFile.getOutputStream(lock);
566             configuration.write(out, "UTF-8"); //NOI18N
567
}
568         catch(IOException JavaDoc ioe){
569             throw new RuntimeException JavaDoc(ioe.getMessage());
570         }
571         finally {
572             if(lock != null)
573                 lock.releaseLock();
574             if(out != null)
575                 out.close();
576         }
577         return configFile;
578     }
579     
580     
581     //FIX-ME: Use DD beans in websvc/core
582
public FileObject generateConfigFile(String JavaDoc seiClassName, String JavaDoc servantClassName, URI JavaDoc targetNS, URI JavaDoc typeNS) throws java.io.IOException JavaDoc {
583         FileObject configFile = pkg.createData(wsName + "-config", "xml"); //NOI18N
584

585         Configuration configuration = new Configuration();
586         org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.ServiceType service =
587         new org.netbeans.modules.websvc.jaxrpc.dev.dd.gen.ServiceType();
588         service.setName(wsName);
589         service.setTargetNamespace(targetNS);
590         service.setTypeNamespace(typeNS);
591         service.setPackageName(wsgenUtil.getSelectedPackageName(pkg, project));
592         InterfaceType interf = new InterfaceType();
593         interf.setName(seiClassName);
594         interf.setServantName(servantClassName);
595         service.setInterface(new InterfaceType[] {interf});
596         configuration.setService(service);
597         
598         FileLock lock = null;
599         OutputStream JavaDoc out = null;
600         try{
601             lock = configFile.lock();
602             out = configFile.getOutputStream(lock);
603             configuration.write(out, "UTF-8"); //NOI18N
604
}
605         catch(IOException JavaDoc ioe){
606             throw new RuntimeException JavaDoc(ioe.getMessage());
607         }
608         finally {
609             if(lock != null)
610                 lock.releaseLock();
611             if(out != null)
612                 out.close();
613         }
614         return configFile;
615     }
616     
617     public static final String JavaDoc WSCOMPILE_CLASSPATH = "wscompile.classpath"; //NOI18N
618

619 }
620
621
622
Popular Tags