KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > wsclient > J2SEProjectWebServicesClientSupport


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.java.j2seproject.wsclient;
21 import java.io.File JavaDoc;
22 import java.net.UnknownHostException JavaDoc;
23 import org.netbeans.modules.java.j2seproject.J2SEProject;
24 import org.netbeans.modules.java.j2seproject.J2SEProjectType;
25 import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties;
26 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor;
27 import org.netbeans.modules.websvc.api.client.WebServicesClientConstants;
28 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport;
29 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl;
30 import java.io.IOException JavaDoc;
31 import java.util.Arrays JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.List JavaDoc;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.api.project.ProjectManager;
37 import org.netbeans.api.project.ui.OpenProjects;
38 import org.netbeans.spi.project.support.ant.AntProjectHelper;
39 import org.netbeans.spi.project.support.ant.EditableProperties;
40 import org.netbeans.spi.project.support.ant.PropertyUtils;
41 import org.openide.DialogDisplayer;
42 import org.openide.NotifyDescriptor;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.util.NbBundle;
46 import org.w3c.dom.Document JavaDoc;
47 import org.w3c.dom.Element JavaDoc;
48 import org.w3c.dom.NodeList JavaDoc;
49 import org.netbeans.spi.project.support.ant.ReferenceHelper;
50
51
52 /**
53  *
54  * @author rico
55  * Implementation of WebServicesSupportImpl and WebServicesClientSupportImpl
56  */

57 public class J2SEProjectWebServicesClientSupport implements WebServicesClientSupportImpl{
58
59     private J2SEProject project;
60     private AntProjectHelper helper;
61     private ReferenceHelper referenceHelper;
62     private String JavaDoc proxyHost,proxyPort;
63
64     public static final String JavaDoc WSDL_FOLDER = "wsdl"; //NOI18N
65

66     /** Creates a new instance of J2SEProjectWebServicesSupport */
67     public J2SEProjectWebServicesClientSupport(J2SEProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) {
68         this.project = project;
69         this.helper = helper;
70         this.referenceHelper = referenceHelper;
71     }
72             
73     public AntProjectHelper getAntProjectHelper() {
74         return helper;
75     }
76        
77     public ReferenceHelper getReferenceHelper(){
78         return referenceHelper;
79     }
80
81     // Implementation of WebServiceClientSupportImpl
82
public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) {
83         this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null);
84     }
85     
86     // Implementation of WebServiceClientSupportImpl
87
public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String JavaDoc[] wscompileFeatures) {
88         // !PW FIXME I have two concerns with this implementation:
89
// 1. Since it modifies project.xml, I suspect it should be acquiring
90
// ProjectManager.mutex() for write access.
91
// 2. It seems like it ought to be implemented via the AuxiliaryConfiguration
92
// interface.
93
boolean needsSave = false;
94         boolean modifiedProjectProperties = false;
95         boolean modifiedPrivateProperties = false;
96         
97         /** Locate root of web service client node structure in project,xml, creating it
98          * if it's not found.
99          */

100         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
101         Document JavaDoc doc = data.getOwnerDocument();
102         NodeList JavaDoc nodes = data.getElementsByTagName(WebServicesClientConstants.WEB_SERVICE_CLIENTS);
103         Element JavaDoc clientElements = null;
104         
105         if(nodes.getLength() == 0) {
106             // 'needsSave' deliberately left false here because this is a trival change
107
// that only should be saved if additional changes are also made below.
108
clientElements = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENTS);
109             NodeList JavaDoc srcRoots = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); // NOI18N
110
assert srcRoots.getLength() == 1 : "Invalid project.xml."; // NOI18N
111
data.insertBefore(clientElements, srcRoots.item(0));
112         } else {
113             clientElements = (Element JavaDoc) nodes.item(0);
114         }
115         
116         /** Make sure this service is not already registered in project.xml
117          */

118         boolean serviceAlreadyAdded = false;
119         NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);
120         for(int i = 0; i < clientNameList.getLength(); i++ ) {
121             Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
122             NodeList JavaDoc nl = clientNameElement.getChildNodes();
123             if(nl.getLength() >= 1) {
124                 org.w3c.dom.Node JavaDoc n = nl.item(0);
125                 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
126                     if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
127                         serviceAlreadyAdded = true;
128                         
129                         // !PW FIXME should force stub type to match value passed in
130
// in case someone is overwriting a current service with a different
131
// stub type.
132
}
133                 }
134             }
135         }
136         
137         /** Add entry for the client to project.xml and regenerate build-impl.xml.
138          */

139         if(!serviceAlreadyAdded) {
140             Element JavaDoc clientElement = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT);
141             clientElements.appendChild(clientElement);
142             Element JavaDoc clientElementName = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);
143             clientElement.appendChild(clientElementName);
144             clientElementName.appendChild(doc.createTextNode(serviceName));
145             Element JavaDoc clientElementStubType = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_STUB_TYPE);
146             clientElement.appendChild(clientElementStubType);
147             clientElementStubType.appendChild(doc.createTextNode(stubDescriptor.getName()));
148             Element JavaDoc clientElementSourceUrl = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.CLIENT_SOURCE_URL);
149             clientElement.appendChild(clientElementSourceUrl);
150             clientElementSourceUrl.appendChild(doc.createTextNode(sourceUrl));
151             helper.putPrimaryConfigurationData(data, true);
152             needsSave = true;
153         }
154         
155         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
156         EditableProperties privateProperties = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
157         // Add property for wscompile features
158
{
159             String JavaDoc featurePropertyName = "wscompile.client." + serviceName + ".features"; // NOI18N
160
String JavaDoc defaultFeatures = "wsi, strict"; // NOI18N -- defaults if stub descriptor is bad type (should never happen?)
161
if(stubDescriptor instanceof JAXRPCClientStubDescriptor) {
162                 JAXRPCClientStubDescriptor stubDesc = (JAXRPCClientStubDescriptor) stubDescriptor;
163                 if (wscompileFeatures!=null) stubDesc.setDefaultFeatures(wscompileFeatures);
164                 defaultFeatures = stubDesc.getDefaultFeaturesAsArgument();
165             } else {
166                 // !PW FIXME wrong stub type -- log error message.
167
}
168             String JavaDoc oldFeatures = projectProperties.getProperty(featurePropertyName);
169             if(!defaultFeatures.equals(oldFeatures)) {
170                 projectProperties.put(featurePropertyName, defaultFeatures);
171                 modifiedProjectProperties = true;
172             }
173         }
174         
175         // Add package name property
176
{
177             String JavaDoc packagePropertyName = "wscompile.client." + serviceName + ".package"; // NOI18N
178
String JavaDoc oldPackageName = projectProperties.getProperty(packagePropertyName);
179             if(!packageName.equals(oldPackageName)) {
180                 projectProperties.put(packagePropertyName, packageName);
181                 modifiedProjectProperties = true;
182             }
183         }
184         
185         // Add http.proxyHost, http.proxyPort and http.nonProxyHosts JVM options
186
// create wscompile:httpproxy property
187
if (proxyHost!=null && proxyHost.length()>0) {
188             boolean modif = addJVMProxyOptions(projectProperties,proxyHost,proxyPort);
189             if (modif) modifiedProjectProperties = true;
190             String JavaDoc proxyProperty = "wscompile.client." + serviceName + ".proxy"; // NOI18N
191
String JavaDoc oldProxyProperty = privateProperties.getProperty(proxyProperty);
192             if(!proxyProperty.equals(oldProxyProperty)) {
193                 privateProperties.put(proxyProperty, proxyHost+":"+(proxyPort==null?"8080":proxyPort)); //NOI18N
194
modifiedPrivateProperties = true;
195             }
196         }
197         
198         if(modifiedProjectProperties) {
199             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
200             needsSave = true;
201         }
202         if(modifiedPrivateProperties) {
203             helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties);
204             needsSave = true;
205         }
206         
207         // Update wscompile related properties. boolean return indicates whether
208
// any changes were made.
209
if(updateWsCompileProperties(serviceName)) {
210             needsSave = true;
211         }
212         
213         // !PW Lastly, save the project if we actually made any changes to any
214
// properties or the build script.
215
if(needsSave) {
216             try {
217                 ProjectManager.getDefault().saveProject(project);
218             } catch(IOException JavaDoc ex) {
219                 NotifyDescriptor desc = new NotifyDescriptor.Message(
220                 NbBundle.getMessage(J2SEProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), // NOI18N
221
NotifyDescriptor.ERROR_MESSAGE);
222                 DialogDisplayer.getDefault().notify(desc);
223             }
224         }
225     }
226     
227     public void addInfrastructure(String JavaDoc implBeanClass, FileObject pkg) {
228         //nothing to do here, there are no infrastructure elements
229
}
230     
231     public FileObject getDeploymentDescriptor() {
232         return null;
233     }
234         
235     private FileObject getFileObject(String JavaDoc propname) {
236         String JavaDoc prop = helper.getStandardPropertyEvaluator().getProperty(propname);
237         if (prop != null) {
238             return helper.resolveFileObject(prop);
239         } else {
240             return null;
241         }
242     }
243     
244     private boolean updateWsCompileProperties(String JavaDoc serviceName) {
245         /** Ensure wscompile.classpath and wscompile.tools.classpath are
246          * properly defined.
247          *
248          * wscompile.classpath goes in project properties and includes
249          * jaxrpc and qname right now.
250          *
251          * wscompile.tools.classpath is for tools.jar which is needed when
252          * running under the Sun JDK to invoke javac. It is placed in
253          * user.properties so that if we compute it incorrectly (say on a mac)
254          * the user can change it and we will not blow away the change.
255          * Hopefully we can do this better for release.
256          */

257         boolean globalPropertiesChanged = false;
258         
259         EditableProperties globalProperties = PropertyUtils.getGlobalProperties();
260         if(globalProperties.getProperty(WebServicesClientConstants.WSCOMPILE_TOOLS_CLASSPATH) == null) {
261             globalProperties.setProperty(WebServicesClientConstants.WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
262

263             try {
264                 PropertyUtils.putGlobalProperties(globalProperties);
265             } catch(IOException JavaDoc ex) {
266                 NotifyDescriptor desc = new NotifyDescriptor.Message(
267                 NbBundle.getMessage(J2SEProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N
268
NotifyDescriptor.ERROR_MESSAGE);
269                 DialogDisplayer.getDefault().notify(desc);
270             }
271             
272             globalPropertiesChanged = true;
273         }
274         
275         
276         boolean projectPropertiesChanged = false;
277         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
278         
279         { // Block that adjusts wscompile.client.classpath as necessary.
280
HashSet JavaDoc wscJars = new HashSet JavaDoc();
281             boolean newWscJars = false;
282             String JavaDoc wscClientClasspath = projectProperties.getProperty(WebServicesClientConstants.WSCOMPILE_CLASSPATH);
283             if (wscClientClasspath == null) {
284                 wscClientClasspath = "${" + WebServicesClientConstants.WSCOMPILE_TOOLS_CLASSPATH + "}" + ":${javac.classpath}";
285                 projectProperties.put(WebServicesClientConstants.WSCOMPILE_CLASSPATH, wscClientClasspath);
286                 projectPropertiesChanged = true;
287             }
288             
289 // for(int i = 0; i < WSCOMPILE_JARS.length; i++) {
290
// if(!wscJars.contains(WSCOMPILE_JARS[i])) {
291
// wscJars.add(WSCOMPILE_JARS[i]);
292
// newWscJars = true;
293
// }
294
// }
295

296 // if(newWscJars) {
297
// StringBuffer newClasspathBuf = new StringBuffer(256);
298
// for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) {
299
// newClasspathBuf.append(iter.next().toString());
300
// if(iter.hasNext()) {
301
// newClasspathBuf.append(":");
302
// }
303
// }
304
// projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString());
305
// projectPropertiesChanged = true;
306
// }
307
}
308         
309         // set tools.jar property if not set
310
if(projectProperties.getProperty(WebServicesClientConstants.WSCOMPILE_TOOLS_CLASSPATH) == null) {
311             projectProperties.setProperty(WebServicesClientConstants.WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
312
projectPropertiesChanged = true;
313         }
314         
315         if(projectPropertiesChanged) {
316             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
317         }
318         
319         return globalPropertiesChanged || projectPropertiesChanged;
320     }
321     
322     public void removeServiceClient(String JavaDoc serviceName) {
323         // 2. Remove service from project.xml
324
// Side effect: Regenerate build-impl.xsl
325
// Optional - if last service, remove properties we generated.
326
boolean needsSave = false;
327         boolean needsSave1 = false;
328         
329         /** Remove properties from project.properties
330          */

331         String JavaDoc featureProperty = "wscompile.client." + serviceName + ".features"; // NOI18N
332
String JavaDoc packageProperty = "wscompile.client." + serviceName + ".package"; // NOI18N
333
String JavaDoc proxyProperty = "wscompile.client." + serviceName + ".proxy"; //NOI18N
334

335         EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
336         EditableProperties ep1 = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
337         
338         if(ep.getProperty(featureProperty) != null) {
339             ep.remove(featureProperty);
340             needsSave = true;
341         }
342         
343         if(ep.getProperty(packageProperty) != null) {
344             ep.remove(packageProperty);
345             needsSave = true;
346         }
347         
348         if(ep1.getProperty(proxyProperty) != null) {
349             ep1.remove(proxyProperty);
350             needsSave1 = true;
351         }
352         
353         if(needsSave) {
354             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
355         }
356         
357         if(needsSave1) {
358             helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep1);
359         }
360         
361         /** Locate root of web service client node structure in project,xml
362          */

363         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
364         Document JavaDoc doc = data.getOwnerDocument();
365         NodeList JavaDoc nodes = data.getElementsByTagName(WebServicesClientConstants.WEB_SERVICE_CLIENTS);
366         Element JavaDoc clientElements = null;
367         
368         /* If there is a root, get all the names of the child services and search
369          * for the one we want to remove.
370          */

371         if(nodes.getLength() >= 1) {
372             clientElements = (Element JavaDoc) nodes.item(0);
373             NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);
374             for(int i = 0; i < clientNameList.getLength(); i++ ) {
375                 Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
376                 NodeList JavaDoc nl = clientNameElement.getChildNodes();
377                 if(nl.getLength() == 1) {
378                     org.w3c.dom.Node JavaDoc n = nl.item(0);
379                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
380                         if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
381                             // Found it! Now remove it.
382
org.w3c.dom.Node JavaDoc serviceNode = clientNameElement.getParentNode();
383                             clientElements.removeChild(serviceNode);
384                             helper.putPrimaryConfigurationData(data, true);
385                             needsSave = true;
386                         }
387                     }
388                 }
389             }
390         }
391         
392         // !PW Lastly, save the project if we actually made any changes to any
393
// properties or the build script.
394
if(needsSave || needsSave1) {
395             try {
396                 ProjectManager.getDefault().saveProject(project);
397             } catch(IOException JavaDoc ex) {
398                 NotifyDescriptor desc = new NotifyDescriptor.Message(
399                 NbBundle.getMessage(J2SEProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), // NOI18N
400
NotifyDescriptor.ERROR_MESSAGE);
401                 DialogDisplayer.getDefault().notify(desc);
402             }
403         }
404     }
405     
406     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
407
408         EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
409         String JavaDoc metaInfStr = helper.getStandardPropertyEvaluator().getProperty("meta.inf.dir");
410         String JavaDoc wsdlFolderStr = metaInfStr + "/" + WSDL_FOLDER; // NOI18N
411
FileObject wsdlFolder = project.getProjectDirectory().getFileObject(wsdlFolderStr);
412         if (wsdlFolder == null && create) {
413             wsdlFolder = FileUtil.createFolder(project.getProjectDirectory(), wsdlFolderStr);
414         }
415         
416         return wsdlFolder;
417     }
418     
419     public List JavaDoc/*ClientStubDescriptor*/ getStubDescriptors() {
420         ArrayList JavaDoc stubs = new ArrayList JavaDoc(2);
421         stubs.add(jaxrpcClientStub);
422         return stubs;
423     }
424     
425     private boolean isProjectOpened() {
426         Project[] projects = OpenProjects.getDefault().getOpenProjects();
427         for (int i = 0; i < projects.length; i++) {
428             if (projects[i].equals(project))
429                 return true;
430         }
431         return false;
432     }
433     
434     /** !PW This method is exposed in the client support API. Though it's
435      * implementation makes more sense here than anywhere else, perhaps this
436      * and the other project.xml/project.properties related methods in this
437      * object should be refactored into another object that this one delegates
438      * to. That way, this method would be directly available within the web
439      * web module, as it is needed, and remain missing from the API (where it
440      * probably does not belong at this time.
441      */

442     private static final String JavaDoc [] WSCOMPILE_CLIENT_FEATURES = {
443         "datahandleronly", // - portable
444
// "documentliteral", // SEI ONLY
445
// "rpcliteral", // SEI ONLY
446
"explicitcontext",
447         // "infix:<name>", // difficult to implement.
448
"jaxbenumtype",
449         "nodatabinding", // - portable
450
"noencodedtypes",
451         "nomultirefs",
452         "norpcstructures", // - portable
453
"novalidation", // - portable
454
"resolveidref",
455         "searchschema", // - portable
456
"serializeinterfaces",
457         "strict", // - portable
458
// "useonewayoperations", // SEI ONLY
459
"wsi", // - portable
460
"unwrap",// - portable
461
"donotoverride", // - portable
462
"donotunwrap", // - portable
463
};
464     
465     private static final List JavaDoc allClientFeatures = Arrays.asList(WSCOMPILE_CLIENT_FEATURES);
466     
467     private static final String JavaDoc [] WSCOMPILE_KEY_CLIENT_FEATURES = {
468         "wsi",
469         "strict",
470         "norpcstructures",
471         "unwrap",
472         "donotunwrap",
473         "donotoverride",
474         "datahandleronly",
475         "nodatabinding",
476         "novalidation",
477         "searchschema",
478     };
479     
480     private static final List JavaDoc importantClientFeatures = Arrays.asList(WSCOMPILE_KEY_CLIENT_FEATURES);
481     
482     public List JavaDoc getServiceClients() {
483         List JavaDoc serviceNames = new ArrayList JavaDoc();
484         
485         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
486         NodeList JavaDoc nodes = data.getElementsByTagName(WebServicesClientConstants.WEB_SERVICE_CLIENTS);
487         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
488         
489         if(nodes.getLength() != 0) {
490             Element JavaDoc clientElements = (Element JavaDoc) nodes.item(0);
491             NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(
492             J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);
493             for(int i = 0; i < clientNameList.getLength(); i++ ) {
494                 Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
495                 NodeList JavaDoc nl = clientNameElement.getChildNodes();
496                 if(nl.getLength() == 1) {
497                     org.w3c.dom.Node JavaDoc n = nl.item(0);
498                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
499                         String JavaDoc serviceName = n.getNodeValue();
500                         String JavaDoc currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features"); //NOI18N
501
if(currentFeatures == null) {
502                             // !PW should probably retrieve default features for stub type.
503
// For now, this will work because this is the same value we'd get doing that.
504
//
505
// Defaults if we can't find any feature property for this client
506
// Mostly for upgrading EA1, EA2 projects which did not have
507
// this property, but also useful if the user deletes it from
508
// project.properties.
509
currentFeatures = "wsi, strict";
510                         }
511                         ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode());
512                         boolean propVerbose = "true".equalsIgnoreCase( //NOI18N
513
projectProperties.getProperty("wscompile.client." + serviceName + ".verbose")); //NOI18N
514
boolean propDebug = "true".equalsIgnoreCase( //NOI18N
515
projectProperties.getProperty("wscompile.client." + serviceName + ".debug")); //NOI18N
516
boolean propPrintStackTrace = "true".equalsIgnoreCase( //NOI18N
517
projectProperties.getProperty("wscompile.client." + serviceName + ".xPrintStackTrace")); //NOI18N
518
boolean propExtensible = "true".equalsIgnoreCase( //NOI18N
519
projectProperties.getProperty("wscompile.client." + serviceName + ".xSerializable")); //NOI18N
520
boolean propOptimize = "true".equalsIgnoreCase( //NOI18N
521
projectProperties.getProperty("wscompile.client." + serviceName + ".optimize")); //NOI18N
522
boolean[] options = new boolean[] { //NOI18N
523
propVerbose,propDebug,propPrintStackTrace,propExtensible,propOptimize
524                         };
525                         WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings(
526                         serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures);
527                         serviceNames.add(settings);
528                     } else {
529                         // !PW FIXME node is wrong type?! - log message or trace?
530
}
531                 } else {
532                     // !PW FIXME no name for this service entry - notify user
533
}
534             }
535         }
536         
537         return serviceNames;
538     }
539     
540     private ClientStubDescriptor getClientStubDescriptor(org.w3c.dom.Node JavaDoc parentNode) {
541         ClientStubDescriptor result = null;
542         
543         if(parentNode instanceof Element JavaDoc) {
544             Element JavaDoc parentElement = (Element JavaDoc) parentNode;
545             NodeList JavaDoc clientNameList = parentElement.getElementsByTagNameNS(
546             J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_STUB_TYPE);
547             if(clientNameList.getLength() == 1) {
548                 Element JavaDoc clientStubElement = (Element JavaDoc) clientNameList.item(0);
549                 NodeList JavaDoc nl = clientStubElement.getChildNodes();
550                 if(nl.getLength() == 1) {
551                     org.w3c.dom.Node JavaDoc n = nl.item(0);
552                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
553                         String JavaDoc stubName = n.getNodeValue();
554                         if (ClientStubDescriptor.JAXRPC_CLIENT_STUB.equals(stubName)) {
555                             result = jaxrpcClientStub;
556                         }
557                     }
558                 }
559             }
560         }
561         
562         return result;
563     }
564     
565     public String JavaDoc getWsdlSource(String JavaDoc serviceName) {
566         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
567         Document JavaDoc doc = data.getOwnerDocument();
568         String JavaDoc wsdlSource = null;
569         
570         Element JavaDoc clientElement = getWebServiceClientNode(data, serviceName);
571         if(clientElement != null) {
572             NodeList JavaDoc fromWsdlList = clientElement.getElementsByTagNameNS(
573             J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.CLIENT_SOURCE_URL);
574             if(fromWsdlList.getLength() == 1) {
575                 Element JavaDoc fromWsdlElement = (Element JavaDoc) fromWsdlList.item(0);
576                 NodeList JavaDoc nl = fromWsdlElement.getChildNodes();
577                 if(nl.getLength() == 1) {
578                     org.w3c.dom.Node JavaDoc n = nl.item(0);
579                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
580                         wsdlSource = n.getNodeValue();
581                     }
582                 }
583             }
584         }
585         
586         return wsdlSource;
587     }
588     
589     public void setWsdlSource(String JavaDoc serviceName, String JavaDoc wsdlSource) {
590         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
591         Document JavaDoc doc = data.getOwnerDocument();
592         boolean needsSave = false;
593         
594         Element JavaDoc clientElement = getWebServiceClientNode(data, serviceName);
595         if(clientElement != null) {
596             NodeList JavaDoc fromWsdlList = clientElement.getElementsByTagNameNS(
597             J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.CLIENT_SOURCE_URL);
598             if(fromWsdlList.getLength() > 0) {
599                 Element JavaDoc fromWsdlElement = (Element JavaDoc) fromWsdlList.item(0);
600                 NodeList JavaDoc nl = fromWsdlElement.getChildNodes();
601                 if(nl.getLength() > 0) {
602                     org.w3c.dom.Node JavaDoc n = nl.item(0);
603                     n.setNodeValue(wsdlSource);
604                 } else {
605                     fromWsdlElement.appendChild(doc.createTextNode(wsdlSource));
606                 }
607             } else {
608                 Element JavaDoc clientElementSourceUrl = doc.createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.CLIENT_SOURCE_URL);
609                 clientElement.appendChild(clientElementSourceUrl);
610                 clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource));
611             }
612             
613             needsSave = true;
614         }
615         
616         // !PW Save the project if we were able to make the change.
617
if(needsSave) {
618             try {
619                 ProjectManager.getDefault().saveProject(project);
620             } catch(IOException JavaDoc ex) {
621                 NotifyDescriptor desc = new NotifyDescriptor.Message(
622                 NbBundle.getMessage(J2SEProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), // NOI18N
623
NotifyDescriptor.ERROR_MESSAGE);
624                 DialogDisplayer.getDefault().notify(desc);
625             }
626         }
627     }
628     
629     private Element JavaDoc getWebServiceClientNode(Element JavaDoc data, String JavaDoc serviceName) {
630         Element JavaDoc clientElement = null;
631         NodeList JavaDoc nodes = data.getElementsByTagName(WebServicesClientConstants.WEB_SERVICE_CLIENTS);
632         
633         if(nodes.getLength() != 0) {
634             Element JavaDoc clientElements = (Element JavaDoc) nodes.item(0);
635             NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(
636             J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesClientConstants.WEB_SERVICE_CLIENT_NAME);
637             for(int i = 0; i < clientNameList.getLength(); i++ ) {
638                 Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
639                 NodeList JavaDoc nl = clientNameElement.getChildNodes();
640                 if(nl.getLength() == 1) {
641                     org.w3c.dom.Node JavaDoc n = nl.item(0);
642                     if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
643                         String JavaDoc name = n.getNodeValue();
644                         if(serviceName.equals(name)) {
645                             org.w3c.dom.Node JavaDoc node = clientNameElement.getParentNode();
646                             clientElement = (node instanceof Element JavaDoc) ? (Element JavaDoc) node : null;
647                             break;
648                         }
649                     } else {
650                         // !PW FIXME node is wrong type?! - log message or trace?
651
}
652                 }
653             }
654         }
655         
656         return clientElement;
657     }
658     
659     private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor(
660         ClientStubDescriptor.JAXRPC_CLIENT_STUB,
661         NbBundle.getMessage(J2SEProjectWebServicesClientSupport.class,"LBL_JAXRPCStaticClientStub"),
662         new String JavaDoc [] { "wsi", "strict" });
663
664     public void addServiceClientReference(String JavaDoc serviceName, String JavaDoc fqServiceName, String JavaDoc relativeWsdlPath, String JavaDoc relativeMappingPath, String JavaDoc[] portSEIInfo) {
665         // nothing to do in J2se
666
}
667     
668     /** Stub descriptor for services and clients supported by this project type.
669      */

670     private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor {
671         
672         private String JavaDoc [] defaultFeatures;
673         
674         public JAXRPCClientStubDescriptor(String JavaDoc name, String JavaDoc displayName, String JavaDoc [] defaultFeatures) {
675             super(name, displayName);
676             
677             this.defaultFeatures = defaultFeatures;
678         }
679         
680         public String JavaDoc [] getDefaultFeatures() {
681             return defaultFeatures;
682         }
683         
684         public String JavaDoc getDefaultFeaturesAsArgument() {
685             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(defaultFeatures.length*32);
686             for(int i = 0; i < defaultFeatures.length; i++) {
687                 if(i > 0) {
688                     buf.append(",");
689                 }
690                 
691                 buf.append(defaultFeatures[i]);
692             }
693             return buf.toString();
694         }
695         
696         void setDefaultFeatures(String JavaDoc[] defaultFeatures) {
697             this.defaultFeatures=defaultFeatures;
698         }
699     }
700     
701     public void setProxyJVMOptions(String JavaDoc proxyHost, String JavaDoc proxyPort) {
702         this.proxyHost=proxyHost;
703         this.proxyPort=proxyPort;
704     }
705     
706     private static final String JavaDoc PROXY_HOST_OPTION="-Dhttp.proxyHost"; //NOI18N
707
private static final String JavaDoc PROXY_PORT_OPTION="-Dhttp.proxyPort"; //NOI18N
708
private static final String JavaDoc NON_PROXY_HOSTS_OPTION="-Dhttp.nonProxyHosts"; //NOI18N
709

710     private boolean addJVMProxyOptions(EditableProperties prop, String JavaDoc proxyHost, String JavaDoc proxyPort) {
711         String JavaDoc jvmOptions = prop.getProperty(J2SEProjectProperties.RUN_JVM_ARGS);
712         boolean modif=false;
713         String JavaDoc localHosts = "localhost"; //NOI18N
714
try {
715             localHosts = java.net.InetAddress.getLocalHost().getCanonicalHostName();
716         } catch (java.net.UnknownHostException JavaDoc ex) {}
717         if (!"localhost".equals(localHosts)) localHosts="\""+localHosts+"|localhost\""; //NOI18N
718
if (jvmOptions==null || jvmOptions.length()==0) {
719             jvmOptions = PROXY_HOST_OPTION+"="+proxyHost+ //NOI18N
720
" "+PROXY_PORT_OPTION+"="+proxyPort+ //NOI18N
721
" "+NON_PROXY_HOSTS_OPTION+"="+localHosts; //NOI18N
722
modif=true;
723         } else {
724             if (jvmOptions.indexOf(PROXY_HOST_OPTION)<0) {
725                 jvmOptions+=" "+PROXY_HOST_OPTION+"="+proxyHost; //NOI18N
726
modif=true;
727             }
728             if (jvmOptions.indexOf(PROXY_PORT_OPTION)<0) {
729                 jvmOptions+=" "+PROXY_PORT_OPTION+"="+proxyPort; //NOI18N
730
modif=true;
731             }
732             if (jvmOptions.indexOf(NON_PROXY_HOSTS_OPTION)<0) {
733                 jvmOptions+=" "+NON_PROXY_HOSTS_OPTION+"="+localHosts; //NOI18N
734
modif=true;
735             }
736         }
737         if (modif) prop.setProperty(J2SEProjectProperties.RUN_JVM_ARGS,jvmOptions);
738         return modif;
739     }
740
741     public String JavaDoc getServiceRefName(String JavaDoc serviceName) {
742         //noop
743
return null;
744     }
745     
746 }
747
Popular Tags