KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > WebProjectWebServicesSupport


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.web.project;
21
22 import org.netbeans.api.java.classpath.ClassPath;
23 import org.netbeans.modules.j2ee.metadata.ClassPathSupport;
24 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException;
25 import org.netbeans.modules.websvc.api.client.WebServicesClientConstants;
26 import org.netbeans.modules.websvc.spi.webservices.WebServicesSupportImpl;
27 import java.io.IOException JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import org.netbeans.api.java.project.JavaProjectConstants;
34 import org.netbeans.api.project.Project;
35 import org.netbeans.api.project.ProjectManager;
36 import org.netbeans.api.project.ProjectUtils;
37 import org.netbeans.api.project.SourceGroup;
38 import org.netbeans.api.project.Sources;
39 import org.netbeans.api.project.ui.OpenProjects;
40 import org.netbeans.modules.j2ee.dd.api.webservices.ServiceImplBean;
41 import org.netbeans.spi.project.support.ant.AntProjectHelper;
42 import org.netbeans.spi.project.support.ant.EditableProperties;
43 import org.netbeans.spi.project.support.ant.PropertyUtils;
44 import org.openide.ErrorManager;
45 import org.openide.DialogDisplayer;
46 import org.openide.NotifyDescriptor;
47 import org.openide.filesystems.FileObject;
48 import org.openide.filesystems.FileUtil;
49 import org.openide.util.NbBundle;
50 import org.w3c.dom.Document JavaDoc;
51 import org.w3c.dom.Element JavaDoc;
52 import org.w3c.dom.Node JavaDoc;
53 import org.w3c.dom.NodeList JavaDoc;
54 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
55 import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
56 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
57 import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
58 import org.netbeans.modules.web.project.classpath.ClassPathProviderImpl;
59 import static org.netbeans.modules.websvc.spi.webservices.WebServicesConstants.*;
60 import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport;
61 import org.netbeans.modules.websvc.api.webservices.StubDescriptor;
62 import org.netbeans.spi.project.support.ant.ReferenceHelper;
63
64 /**
65  *
66  * @author rico
67  * Implementation of WebServicesSupportImpl
68  */

69 public class WebProjectWebServicesSupport implements WebServicesSupportImpl {
70     private WebProject project;
71     private AntProjectHelper helper;
72     private ReferenceHelper referenceHelper;
73     private ClassPath projectSourcesClassPath;
74     
75     /** Creates a new instance of WebProjectWebServicesSupport */
76     public WebProjectWebServicesSupport(WebProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) {
77         this.project = project;
78         this.helper = helper;
79         this.referenceHelper = referenceHelper;
80     }
81     
82     public void addServiceImpl(String JavaDoc serviceName, FileObject configFile, boolean fromWSDL) {
83         this.addServiceImpl(serviceName, configFile, fromWSDL,null);
84     }
85     //implementation of WebServicesSupportImpl
86
public void addServiceImpl(String JavaDoc serviceName, FileObject configFile, boolean fromWSDL, String JavaDoc[] wscompileFeatures) {
87         //Add properties to project.properties file
88
EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
89         String JavaDoc packageName = getPackageName(configFile);
90         ep.put(serviceName + CONFIG_PROP_SUFFIX, packageName +
91         (packageName.equals("") ? "" : "/") + configFile.getNameExt()); //NOI18N
92
ep.put(serviceName + MAPPING_PROP_SUFFIX, serviceName + MAPPING_FILE_SUFFIX); //NOI18N
93
// Add property for wscompile
94
String JavaDoc featurePropertyName = "wscompile.service." + serviceName + ".features"; // NOI18N
95
getWebservicesDD();
96         JAXRPCStubDescriptor stubDesc = null;
97         if (fromWSDL) {
98             if (wscompileFeatures!=null)
99                 stubDesc = new JAXRPCStubDescriptor(StubDescriptor.WSDL_SERVICE_STUB,
100                                 NbBundle.getMessage(WebProjectWebServicesSupport.class,"LBL_WSDLServiceStub"),
101                                 wscompileFeatures);
102             else stubDesc = wsdlServiceStub;
103         } else {
104             stubDesc = seiServiceStub;
105         }
106         String JavaDoc defaultFeatures = stubDesc.getDefaultFeaturesAsArgument();
107             ep.put(featurePropertyName, defaultFeatures);
108             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
109             //Add web-services information in project.xml
110
Element JavaDoc data = helper.getPrimaryConfigurationData(true);
111             Document JavaDoc doc = data.getOwnerDocument();
112             NodeList JavaDoc nodes = data.getElementsByTagName(WEB_SERVICES); //NOI18N
113
Element JavaDoc webservices = null;
114             if (nodes.getLength() == 0){
115                 webservices = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICES); //NOI18N
116
NodeList JavaDoc insertBefore = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENTS);
117                 if (insertBefore.getLength() <= 0) {
118                     insertBefore = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); // NOI18N
119
assert insertBefore.getLength() == 1 : "Invalid project.xml file."; // NOI18N
120
}
121                 data.insertBefore(webservices, insertBefore.item(0));
122             } else {
123                 webservices = (Element JavaDoc)nodes.item(0);
124             }
125             Element JavaDoc webservice = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE); //NOI18N
126
webservices.appendChild(webservice);
127             Element JavaDoc webserviceName = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_NAME); //NOI18N
128
webservice.appendChild(webserviceName);
129             webserviceName.appendChild(doc.createTextNode(serviceName));
130             if(fromWSDL) {
131                 Element JavaDoc fromWSDLElem = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "from-wsdl");
132                 webservice.appendChild(fromWSDLElem);
133             }
134             helper.putPrimaryConfigurationData(data, true);
135             // Update wscompile related properties. boolean return indicates whether
136
// any changes were made.
137
updateWsCompileProperties(serviceName);
138             try {
139                 ProjectManager.getDefault().saveProject(project);
140             }catch(java.io.IOException JavaDoc ioe){
141                 throw new RuntimeException JavaDoc(ioe.getMessage());
142             }
143     }
144     
145     private WebApp getWebApp() {
146         try {
147             FileObject deploymentDescriptor = getDeploymentDescriptor();
148             if(deploymentDescriptor != null) {
149                 return DDProvider.getDefault().getDDRoot(deploymentDescriptor);
150             }
151         } catch (java.io.IOException JavaDoc e) {
152             org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage());
153         }
154         return null;
155     }
156     
157     public void addServiceEntriesToDD(String JavaDoc serviceName, String JavaDoc serviceEndpointInterface, String JavaDoc servantClassName) {
158         //add servlet entry to web.xml
159
String JavaDoc servletName = WebServiceServlet_PREFIX + serviceName;
160         WebApp webApp = getWebApp();
161         if(webApp != null){
162             Servlet servlet = null;
163             try{
164                 servlet = (Servlet)webApp.addBean("Servlet", new String JavaDoc[]{"ServletName","ServletClass"},
165                 new Object JavaDoc[]{servletName,servantClassName}, "ServletName");
166                 servlet.setLoadOnStartup(new java.math.BigInteger JavaDoc("1"));
167                 ServletMapping servletMapping = (ServletMapping)
168                 webApp.addBean("ServletMapping", new String JavaDoc[]{"ServletName","UrlPattern"},
169                 new Object JavaDoc[]{servletName, "/" + serviceName}, "ServletName");
170                 
171                 // This also saves server specific configuration, if necessary.
172
webApp.write(getDeploymentDescriptor());
173             } catch (ClassNotFoundException JavaDoc exc) {
174                 exc.printStackTrace();
175                 throw new RuntimeException JavaDoc(exc.getMessage());
176             } catch (NameAlreadyUsedException exc) {
177                 exc.printStackTrace();
178                 throw new RuntimeException JavaDoc(exc.getMessage());
179             } catch (IOException JavaDoc exc) {
180                 exc.printStackTrace();
181                 throw new RuntimeException JavaDoc(exc.getMessage());
182             }
183         }
184     }
185     
186     
187     /**
188      * Get the webservices.xml file object
189      * descriptive in interface, e.g., getWebserviceDD
190      */

191     public FileObject getWebservicesDD() {
192         FileObject webInfFo = getWebInf();
193         if (webInfFo==null) {
194             if (isProjectOpened()) {
195                 DialogDisplayer.getDefault().notify(
196                 new NotifyDescriptor.Message(NbBundle.getMessage(WebProjectWebServicesSupport.class,"MSG_WebInfCorrupted"),
197                 NotifyDescriptor.ERROR_MESSAGE));
198             }
199             return null;
200         }
201         return getWebInf().getFileObject(WEBSERVICES_DD, "xml");
202     }
203     
204     /**
205      * Returns the directory that contains webservices.xml in the project
206      */

207     public FileObject getWsDDFolder() {
208         return getWebInf();
209     }
210     
211     /**
212      * Returns the name of the directory that contains the webservices.xml in
213      * the archive
214      */

215     public String JavaDoc getArchiveDDFolderName() {
216         return "WEB-INF"; // NOI18N
217
}
218     
219     /**
220      * Returns the name of the implementation bean class
221      * given the servlet-link name
222      */

223     public String JavaDoc getImplementationBean(String JavaDoc linkName) {
224         WebApp webApp = getWebApp();
225         org.netbeans.modules.j2ee.dd.api.web.Servlet[] servlets = webApp.getServlet();
226         for(int i = 0; i < servlets.length; i++) {
227             if(servlets[i].getServletName().equals(linkName)) {
228                 return servlets[i].getServletClass();
229             }
230         }
231         return null;
232     }
233     
234     public boolean isFromWSDL(String JavaDoc serviceName) {
235         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
236         NodeList JavaDoc nodes = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
237         WEB_SERVICES); //NOI18N
238
Element JavaDoc webservices = null;
239         Element JavaDoc wsNameNode = null;
240         if(nodes.getLength() == 1){
241             webservices = (Element JavaDoc)nodes.item(0);
242             NodeList JavaDoc wsNodes = webservices.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
243             WEB_SERVICE); //NOI18N
244
for(int j = 0; j < wsNodes.getLength(); j++) {
245                 Element JavaDoc wsNode = (Element JavaDoc)wsNodes.item(j);
246                 NodeList JavaDoc wsNameNodes = wsNode.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
247                 WEB_SERVICE_NAME); //NOI18N
248
if(wsNameNodes.getLength() == 1) {
249                     wsNameNode = (Element JavaDoc)wsNameNodes.item(0);
250                     NodeList JavaDoc nl = wsNameNode.getChildNodes();
251                     if(nl.getLength() == 1) {
252                         Node JavaDoc n = nl.item(0);
253                         if(n.getNodeType() == Node.TEXT_NODE) {
254                             if(serviceName.equals(n.getNodeValue())) {
255                                 NodeList JavaDoc fromWSDLNodes = wsNode.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
256                                 WEB_SERVICE_FROM_WSDL); //NOI18N
257
if(fromWSDLNodes.getLength() == 1) {
258                                     return true;
259                                 }
260                             }
261                         }
262                     }
263                 }
264             }
265         }
266         return false;
267     }
268     
269     public void removeProjectEntries(String JavaDoc serviceName) {
270         boolean needsSave = false;
271         
272         //Remove entries in the project.properties file
273
//FIX-ME:we should move this to websvc
274
EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
275         String JavaDoc configProperty = serviceName + CONFIG_PROP_SUFFIX;
276         String JavaDoc mappingProperty = serviceName + MAPPING_PROP_SUFFIX;
277         if(ep.getProperty(configProperty) != null) {
278             ep.remove(configProperty);
279             needsSave = true;
280         }
281         if(ep.getProperty(mappingProperty) != null) {
282             ep.remove(mappingProperty);
283             needsSave = true;
284         }
285         String JavaDoc featureProperty = "wscompile.service." + serviceName + ".features"; // NOI18N
286
if(ep.getProperty(featureProperty) != null) {
287             ep.remove(featureProperty);
288             needsSave = true;
289         }
290         if(needsSave){
291             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
292         }
293         //Remove entry in the project.xml file (we should move this to websvc)
294
Element JavaDoc data = helper.getPrimaryConfigurationData(true);
295         NodeList JavaDoc nodes = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
296         WEB_SERVICES); //NOI18N
297
Element JavaDoc webservices = null;
298         Element JavaDoc wsNameNode = null;
299         if(nodes.getLength() == 1){
300             webservices = (Element JavaDoc)nodes.item(0);
301             NodeList JavaDoc wsNodes = webservices.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
302             WEB_SERVICE); //NOI18N
303
for(int j = 0; j < wsNodes.getLength(); j++) {
304                 Element JavaDoc wsNode = (Element JavaDoc)wsNodes.item(j);
305                 NodeList JavaDoc wsNameNodes = wsNode.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,
306                 WEB_SERVICE_NAME); //NOI18N
307
if(wsNameNodes.getLength() == 1) {
308                     wsNameNode = (Element JavaDoc)wsNameNodes.item(0);
309                     NodeList JavaDoc nl = wsNameNode.getChildNodes();
310                     if(nl.getLength() == 1) {
311                         Node JavaDoc n = nl.item(0);
312                         if(n.getNodeType() == Node.TEXT_NODE) {
313                             if(serviceName.equals(n.getNodeValue())) {
314                                 webservices.removeChild(wsNode);
315                                 //if there are no more children, remove the web-services node
316
NodeList JavaDoc children = webservices.getChildNodes();
317                                 if(children.getLength() == 0) {
318                                     data.removeChild(webservices);
319                                 }
320                                 needsSave = true;
321                                 break;
322                             }
323                         }
324                     }
325                 }
326             }
327         }
328         if(needsSave) {
329             helper.putPrimaryConfigurationData(data, true);
330             try {
331                 ProjectManager.getDefault().saveProject(project);
332             } catch(IOException JavaDoc ex) {
333                 String JavaDoc mes = NbBundle.getMessage(this.getClass(), "MSG_ErrorSavingOnWSRemove") + serviceName // NOI18N
334
+ "'\r\n" + ex.getMessage();
335                 NotifyDescriptor desc = new NotifyDescriptor.
336
                Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
337                 DialogDisplayer.getDefault().notify(desc); }
338         }
339     }
340     
341     public void removeServiceEntry(String JavaDoc linkName) {
342         //remove servlet entry in web.xml
343
WebApp webApp = getWebApp();
344         Servlet[] servlets = webApp.getServlet();
345         for(int i = 0; i < servlets.length; i++) {
346             Servlet servlet = servlets[i];
347             if(servlet.getServletName().equals(linkName)) {
348                 webApp.removeServlet(servlet);
349                 break;
350             }
351         }
352         ServletMapping[] mappings = webApp.getServletMapping();
353         for(int j = 0; j < mappings.length; j++ ) {
354             ServletMapping mapping = mappings[j];
355             if(mapping.getServletName().equals(linkName)) {
356                 webApp.removeServletMapping(mapping);
357             }
358         }
359         try {
360             // This also saves server specific configuration, if necessary.
361
webApp.write(getDeploymentDescriptor());
362         }
363         catch(java.io.IOException JavaDoc e) {
364             NotifyDescriptor ndd =
365             new NotifyDescriptor.Message(NbBundle.getMessage(this.getClass(), "MSG_Unable_WRITE_WS_DD"), // NOI18N
366
NotifyDescriptor.ERROR_MESSAGE);
367             DialogDisplayer.getDefault().notify(ndd);
368         }
369     }
370     
371     public AntProjectHelper getAntProjectHelper() {
372         return helper;
373     }
374     
375     public String JavaDoc generateImplementationBean(String JavaDoc wsName, FileObject pkg, Project project, String JavaDoc delegateData)
376     throws java.io.IOException JavaDoc {
377         return null;
378         //FIX-ME: move impl bean generation here
379
}
380     
381     public void addServiceImplLinkEntry(ServiceImplBean serviceImplBean, String JavaDoc wsName) {
382         serviceImplBean.setServletLink(WebServiceServlet_PREFIX + wsName);
383     }
384     
385     public ReferenceHelper getReferenceHelper(){
386         return referenceHelper;
387     }
388     
389     /** !PW This method is exposed in the service support API. Though it's
390      * implementation makes more sense here than anywhere else, perhaps this
391      * and the other project.xml/project.properties related methods in this
392      * object should be refactored into another object that this one delegates
393      * to. That way, this method would be directly available within the web or
394      * ejb module, as it is needed, and remain missing from the API (where it
395      * probably does not belong at this time.
396      */

397     private static final String JavaDoc [] WSCOMPILE_SEI_SERVICE_FEATURES = {
398         // "datahandleronly", // WSDL - portable
399
"documentliteral", // SEI ONLY - portable
400
"rpcliteral", // SEI ONLY - portable
401
// "explicitcontext", // WSDL - portable
402
// "infix:<name>", // difficult handle with current API
403
// "jaxbenumtype", // WSDL
404
// "nodatabinding", // WSDL - portable
405
"noencodedtypes",
406         "nomultirefs",
407         // "norpcstructures", // import only - portable
408
// "novalidation", // WSDL - portable
409
// "resolveidref", // WSDL
410
// "searchschema", // WSDL - portable
411
"serializeinterfaces",
412         "strict", // - portable
413
"useonewayoperations", // SEI ONLY - portable
414
// "wsi", // WSDL - portable
415
// "unwrap", // WSDL - portable
416
"donotoverride", // - portable
417
// "donotunwrap", // WSDL - portable
418
};
419     
420     private static final List JavaDoc allSeiServiceFeatures = Arrays.asList(WSCOMPILE_SEI_SERVICE_FEATURES);
421     
422     private static final String JavaDoc [] WSCOMPILE_KEY_SEI_SERVICE_FEATURES = {
423         "documentliteral",
424         "rpcliteral",
425         "strict",
426         "useonewayoperations",
427         "donotoverride"
428     };
429     
430     private static final List JavaDoc importantSeiServiceFeatures = Arrays.asList(WSCOMPILE_KEY_SEI_SERVICE_FEATURES);
431     
432     private static final String JavaDoc [] WSCOMPILE_WSDL_SERVICE_FEATURES = {
433         "datahandleronly", // WSDL - portable
434
// "documentliteral", // SEI ONLY - portable
435
// "rpcliteral", // SEI ONLY - portable
436
"explicitcontext", // WSDL - portable
437
// "infix:<name>", // difficult handle with current API
438
"jaxbenumtype", // WSDL
439
"nodatabinding", // WSDL - portable
440
"noencodedtypes",
441         "nomultirefs",
442         "norpcstructures", // import only - portable
443
"novalidation", // WSDL - portable
444
"resolveidref", // WSDL
445
"searchschema", // WSDL - portable
446
"serializeinterfaces",
447         "strict", // - portable
448
// "useonewayoperations", // SEI ONLY - portable
449
"wsi", // WSDL - portable
450
"unwrap", // WSDL - portable
451
"donotoverride", // - portable
452
"donotunwrap", // WSDL - portable
453
};
454     
455     private static final List JavaDoc allWsdlServiceFeatures = Arrays.asList(WSCOMPILE_WSDL_SERVICE_FEATURES);
456     
457     private static final String JavaDoc [] WSCOMPILE_KEY_WSDL_SERVICE_FEATURES = {
458         "wsi",
459         "strict",
460         "unwrap",
461         "donotunwrap",
462         "donotoverride",
463         "datahandleronly",
464         "nodatabinding",
465         "novalidation",
466         "searchschema",
467         "explicitcontext",
468     };
469     
470     private static final List JavaDoc importantWsdlServiceFeatures = Arrays.asList(WSCOMPILE_KEY_WSDL_SERVICE_FEATURES);
471     
472     public List JavaDoc/*WsCompileEditorSupport.ServiceSettings*/ getServices() {
473         List JavaDoc serviceList = new ArrayList JavaDoc();
474         
475         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
476         NodeList JavaDoc nodes = data.getElementsByTagName(WEB_SERVICES);
477         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
478         
479         if(nodes.getLength() != 0) {
480             Element JavaDoc serviceElements = (Element JavaDoc) nodes.item(0);
481             NodeList JavaDoc serviceNameList = serviceElements.getElementsByTagNameNS(
482             WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_NAME);
483             for(int i = 0; i < serviceNameList.getLength(); i++ ) {
484                 Element JavaDoc serviceNameElement = (Element JavaDoc) serviceNameList.item(i);
485                 NodeList JavaDoc nl = serviceNameElement.getChildNodes();
486                 if(nl.getLength() == 1) {
487                     org.w3c.dom.Node JavaDoc n = nl.item(0);
488                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
489                         String JavaDoc serviceName = n.getNodeValue();
490                         String JavaDoc currentFeatures = projectProperties.getProperty("wscompile.service." + serviceName + ".features"); // NOI18N
491
StubDescriptor stubType = getServiceStubDescriptor(serviceNameElement.getParentNode());
492                         WsCompileEditorSupport.ServiceSettings settings;
493                         
494                         // !PW The logic for managing wscompile options needs refactoring badly.
495
if(seiServiceStub == stubType) {
496                             if(currentFeatures == null) {
497                                 // default for SEI generation
498
currentFeatures = seiServiceStub.getDefaultFeaturesAsArgument();
499                             }
500                             settings = new WsCompileEditorSupport.ServiceSettings(
501                             serviceName, stubType, currentFeatures, allSeiServiceFeatures, importantSeiServiceFeatures);
502                         } else { // Should only ever be wsdl node here.)
503
if(currentFeatures == null) {
504                                 // default for WSDL generation
505
currentFeatures = wsdlServiceStub.getDefaultFeaturesAsArgument();
506                             }
507                             settings = new WsCompileEditorSupport.ServiceSettings(
508                             serviceName, stubType, currentFeatures, allWsdlServiceFeatures, importantWsdlServiceFeatures);
509                         }
510                         serviceList.add(settings);
511                     } else {
512                         // !PW FIXME node is wrong type?! - log message or trace?
513
}
514                 } else {
515                     // !PW FIXME no name for this service entry - notify user
516
}
517             }
518         }
519         
520         return serviceList;
521     }
522     
523     private StubDescriptor getServiceStubDescriptor(org.w3c.dom.Node JavaDoc parentNode) {
524         StubDescriptor result = null;
525         
526         if(parentNode instanceof Element JavaDoc) {
527             Element JavaDoc parentElement = (Element JavaDoc) parentNode;
528             NodeList JavaDoc fromWsdlList = parentElement.getElementsByTagNameNS(
529             WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_FROM_WSDL);
530             if(fromWsdlList.getLength() == 1) {
531                 result = wsdlServiceStub;
532             } else {
533                 result = seiServiceStub;
534             }
535         }
536         
537         return result;
538     }
539     
540     private String JavaDoc getPackageName(FileObject file){
541         FileObject parent = file.getParent();
542         Sources sources = ProjectUtils.getSources(project);
543         SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
544         String JavaDoc packageName = null;
545         for (int i = 0; i < groups.length && packageName == null; i++) {
546             packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), parent);
547             if (packageName != null) {
548                 packageName = groups[i].getName() + "/" + packageName;
549             }
550         }
551         return packageName + "";
552     }
553     
554     public void addInfrastructure(String JavaDoc implBeanClass, FileObject pkg) {
555         //nothing to do here, there are no infrastructure elements
556
}
557     
558     public FileObject getDeploymentDescriptor() {
559         FileObject webInfFo = getWebInf();
560         if (webInfFo==null) {
561             if (isProjectOpened()) {
562                 DialogDisplayer.getDefault().notify(
563                 new NotifyDescriptor.Message(NbBundle.getMessage(WebProjectWebServicesSupport.class,"MSG_WebInfCorrupted"), // NOI18N
564
NotifyDescriptor.ERROR_MESSAGE));
565             }
566             return null;
567         }
568         return getWebInf().getFileObject(ProjectWebModule.FILE_DD);
569     }
570     
571     public FileObject getWebInf() {
572         FileObject documentBase = getDocumentBase();
573         if (documentBase != null)
574             return documentBase.getFileObject(ProjectWebModule.FOLDER_WEB_INF);
575         else
576             return null;
577     }
578     
579     public FileObject getDocumentBase() {
580         return getFileObject("web.docbase.dir"); // NOI18N
581
}
582     
583     private FileObject getFileObject(String JavaDoc propname) {
584         String JavaDoc prop = helper.getStandardPropertyEvaluator().getProperty(propname);
585         if (prop != null) {
586             return helper.resolveFileObject(prop);
587         } else {
588             return null;
589         }
590     }
591     
592     private boolean updateWsCompileProperties(String JavaDoc serviceName) {
593         /** Ensure wscompile.classpath and wscompile.tools.classpath are
594          * properly defined.
595          *
596          * wscompile.classpath goes in project properties and includes
597          * jaxrpc and qname right now.
598          *
599          * wscompile.tools.classpath is for tools.jar which is needed when
600          * running under the Sun JDK to invoke javac. It is placed in
601          * user.properties so that if we compute it incorrectly (say on a mac)
602          * the user can change it and we will not blow away the change.
603          * Hopefully we can do this better for release.
604          */

605         boolean globalPropertiesChanged = false;
606         
607         EditableProperties globalProperties = PropertyUtils.getGlobalProperties();
608         if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
609             globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
610

611             try {
612                 PropertyUtils.putGlobalProperties(globalProperties);
613             } catch(IOException JavaDoc ex) {
614                 NotifyDescriptor desc = new NotifyDescriptor.Message(
615                 NbBundle.getMessage(WebProjectWebServicesSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N
616
NotifyDescriptor.ERROR_MESSAGE);
617                 DialogDisplayer.getDefault().notify(desc);
618             }
619             
620             globalPropertiesChanged = true;
621         }
622         
623         
624         boolean projectPropertiesChanged = false;
625         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
626         
627         { // Block that adjusts wscompile.client.classpath as necessary.
628
HashSet JavaDoc wscJars = new HashSet JavaDoc();
629             boolean newWscJars = false;
630             String JavaDoc wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH);
631             if(wscClientClasspath != null) {
632                 String JavaDoc [] libs = PropertyUtils.tokenizePath(wscClientClasspath);
633                 for(int i = 0; i < libs.length; i++) {
634                     wscJars.add(libs[i]);
635                 }
636             }
637             
638             for(int i = 0; i < WSCOMPILE_JARS.length; i++) {
639                 if(!wscJars.contains(WSCOMPILE_JARS[i])) {
640                     wscJars.add(WSCOMPILE_JARS[i]);
641                     newWscJars = true;
642                 }
643             }
644             
645             if(newWscJars) {
646                 StringBuffer JavaDoc newClasspathBuf = new StringBuffer JavaDoc(256);
647                 for(Iterator JavaDoc iter = wscJars.iterator(); iter.hasNext(); ) {
648                     newClasspathBuf.append(iter.next().toString());
649                     if(iter.hasNext()) {
650                         newClasspathBuf.append(':');
651                     }
652                 }
653                 projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString());
654                 projectPropertiesChanged = true;
655             }
656         }
657         
658         // set tools.jar property if not set
659
if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
660             projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
661
projectPropertiesChanged = true;
662         }
663         
664         if(projectPropertiesChanged) {
665             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
666         }
667         
668         return globalPropertiesChanged || projectPropertiesChanged;
669     }
670         
671     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
672         FileObject wsdlFolder = null;
673         FileObject webInf = getWebInf();
674         
675         if(webInf != null) {
676             wsdlFolder = webInf.getFileObject(WSDL_FOLDER);
677             if(wsdlFolder == null && create) {
678                 wsdlFolder = webInf.createFolder(WSDL_FOLDER);
679             }
680         } else if(create) {
681             // Create was specified, but no WEB-INF was found, so how do we create it?
682
// Expect an NPE if we return null for this case, but log it anyway.
683
ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
684             NbBundle.getMessage(WebProjectWebServicesSupport.class,"MSG_WebInfNotFoundForWsdlFolder"));
685         }
686         
687         return wsdlFolder;
688     }
689     
690     private boolean isProjectOpened() {
691         // XXX workaround: OpenProjects.getDefault() can be null
692
// when called from ProjectOpenedHook.projectOpened() upon IDE startup
693
if (OpenProjects.getDefault() == null)
694             return true;
695         
696         Project[] projects = OpenProjects.getDefault().getOpenProjects();
697         for (int i = 0; i < projects.length; i++) {
698             if (projects[i].equals(project))
699                 return true;
700         }
701         return false;
702     }
703
704     public ClassPath getClassPath() {
705         synchronized (this) {
706             if (projectSourcesClassPath == null) {
707                 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)project.getLookup().lookup(ClassPathProviderImpl.class);
708                 projectSourcesClassPath = ClassPathSupport.createWeakProxyClassPath(new ClassPath[] {
709                     cpProvider.getProjectSourcesClassPath(ClassPath.SOURCE),
710                     cpProvider.getJ2eePlatformClassPath(),
711                 });
712             }
713             return projectSourcesClassPath;
714         }
715     }
716         
717     // Service stub descriptors
718
private static final JAXRPCStubDescriptor seiServiceStub = new JAXRPCStubDescriptor(
719     StubDescriptor.SEI_SERVICE_STUB,
720     NbBundle.getMessage(WebProjectWebServicesSupport.class,"LBL_SEIServiceStub"),
721     new String JavaDoc [] { "documentliteral", "strict", "useonewayoperations" });
722     
723     private static final JAXRPCStubDescriptor wsdlServiceStub = new JAXRPCStubDescriptor(
724     StubDescriptor.WSDL_SERVICE_STUB,
725     NbBundle.getMessage(WebProjectWebServicesSupport.class,"LBL_WSDLServiceStub"),
726     new String JavaDoc [] { "wsi", "strict" });
727         
728     /** Stub descriptor for services and clients supported by this project type.
729      */

730     private static class JAXRPCStubDescriptor extends StubDescriptor {
731         
732         private String JavaDoc [] defaultFeatures;
733         
734         public JAXRPCStubDescriptor(String JavaDoc name, String JavaDoc displayName, String JavaDoc [] defaultFeatures) {
735             super(name, displayName);
736             
737             this.defaultFeatures = defaultFeatures;
738         }
739         
740         public String JavaDoc [] getDefaultFeatures() {
741             return defaultFeatures;
742         }
743         
744         public String JavaDoc getDefaultFeaturesAsArgument() {
745             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(defaultFeatures.length*32);
746             for(int i = 0; i < defaultFeatures.length; i++) {
747                 if(i > 0) {
748                     buf.append(',');
749                 }
750                 
751                 buf.append(defaultFeatures[i]);
752             }
753             return buf.toString();
754         }
755     }
756 }
757
Popular Tags