KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > wsclient > AppClientProjectWebServicesClientSupport


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.j2ee.clientproject.wsclient;
21
22 import static org.netbeans.modules.websvc.api.client.WebServicesClientConstants.*;
23 import java.io.IOException JavaDoc;
24 import java.net.InetAddress JavaDoc;
25 import java.net.URI JavaDoc;
26 import java.net.URISyntaxException JavaDoc;
27 import java.net.UnknownHostException JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Set JavaDoc;
34 import org.netbeans.api.project.Project;
35 import org.netbeans.api.project.ProjectManager;
36 import org.netbeans.api.project.ui.OpenProjects;
37 import org.netbeans.modules.j2ee.clientproject.AppClientProject;
38 import org.netbeans.modules.j2ee.clientproject.AppClientProjectType;
39 import org.netbeans.modules.j2ee.clientproject.AppClientProvider;
40 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties;
41 import org.netbeans.modules.j2ee.dd.api.client.DDProvider;
42 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException;
43 import org.netbeans.modules.j2ee.dd.api.common.PortComponentRef;
44 import org.netbeans.modules.j2ee.dd.api.common.RootInterface;
45 import org.netbeans.modules.j2ee.dd.api.common.ServiceRef;
46 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
47 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor;
48 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport;
49 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl;
50 import org.netbeans.spi.project.support.ant.AntProjectHelper;
51 import org.netbeans.spi.project.support.ant.EditableProperties;
52 import org.netbeans.spi.project.support.ant.PropertyUtils;
53 import org.netbeans.spi.project.support.ant.ReferenceHelper;
54 import org.openide.DialogDisplayer;
55 import org.openide.ErrorManager;
56 import org.openide.NotifyDescriptor;
57 import org.openide.filesystems.FileObject;
58 import org.openide.filesystems.FileUtil;
59 import org.openide.util.NbBundle;
60 import org.w3c.dom.Document JavaDoc;
61 import org.w3c.dom.Element JavaDoc;
62 import org.w3c.dom.Node JavaDoc;
63 import org.w3c.dom.NodeList JavaDoc;
64
65 /**
66  * Implementation of WebServicesSupportImpl and WebServicesClientSupportImpl.
67  *
68  * @author rico
69  */

70 public class AppClientProjectWebServicesClientSupport implements WebServicesClientSupportImpl{
71     
72     private final AppClientProject project;
73     private final AntProjectHelper helper;
74     private final ReferenceHelper referenceHelper;
75     private String JavaDoc proxyHost,proxyPort;
76
77     public static final String JavaDoc WSDL_FOLDER = "wsdl"; //NOI18N
78

79     /** Creates a new instance of J2SEProjectWebServicesSupport */
80     public AppClientProjectWebServicesClientSupport(AppClientProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) {
81         this.project = project;
82         this.helper = helper;
83         this.referenceHelper = referenceHelper;
84     }
85             
86     public AntProjectHelper getAntProjectHelper() {
87         return helper;
88     }
89        
90     public ReferenceHelper getReferenceHelper(){
91         return referenceHelper;
92     }
93
94     // Implementation of WebServiceClientSupportImpl
95
public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) {
96         this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null);
97     }
98     
99     // Implementation of WebServiceClientSupportImpl
100
public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String JavaDoc[] wscompileFeatures) {
101         // !PW FIXME I have two concerns with this implementation:
102
// 1. Since it modifies project.xml, I suspect it should be acquiring
103
// ProjectManager.mutex() for write access.
104
// 2. It seems like it ought to be implemented via the AuxiliaryConfiguration
105
// interface.
106
boolean needsSave = false;
107         boolean modifiedProjectProperties = false;
108         boolean modifiedPrivateProperties = false;
109         
110         /** Locate root of web service client node structure in project,xml, creating it
111          * if it's not found.
112          */

113         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
114         Document JavaDoc doc = data.getOwnerDocument();
115         NodeList JavaDoc nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
116         Element JavaDoc clientElements = null;
117         
118         if(nodes.getLength() == 0) {
119             // 'needsSave' deliberately left false here because this is a trival change
120
// that only should be saved if additional changes are also made below.
121
clientElements = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENTS);
122             NodeList JavaDoc srcRoots = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); // NOI18N
123
assert srcRoots.getLength() == 1 : "Invalid project.xml."; // NOI18N
124
data.insertBefore(clientElements, srcRoots.item(0));
125         } else {
126             clientElements = (Element JavaDoc) nodes.item(0);
127         }
128         
129         /** Make sure this service is not already registered in project.xml
130          */

131         boolean serviceAlreadyAdded = false;
132         NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
133         for(int i = 0; i < clientNameList.getLength(); i++ ) {
134             Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
135             NodeList JavaDoc nl = clientNameElement.getChildNodes();
136             if(nl.getLength() >= 1) {
137                 Node JavaDoc n = nl.item(0);
138                 if(n.getNodeType() == Node.TEXT_NODE) {
139                     if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
140                         serviceAlreadyAdded = true;
141                         
142                         // !PW FIXME should force stub type to match value passed in
143
// in case someone is overwriting a current service with a different
144
// stub type.
145
}
146                 }
147             }
148         }
149         
150         /** Add entry for the client to project.xml and regenerate build-impl.xml.
151          */

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

279         boolean globalPropertiesChanged = false;
280         
281         EditableProperties globalProperties = PropertyUtils.getGlobalProperties();
282         if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
283             globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
284

285             try {
286                 PropertyUtils.putGlobalProperties(globalProperties);
287             } catch(IOException JavaDoc ex) {
288                 NotifyDescriptor desc = new NotifyDescriptor.Message(
289                 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), // NOI18N
290
NotifyDescriptor.ERROR_MESSAGE);
291                 DialogDisplayer.getDefault().notify(desc);
292             }
293             
294             globalPropertiesChanged = true;
295         }
296         
297         
298         boolean projectPropertiesChanged = false;
299         EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
300         
301         { // Block that adjusts wscompile.client.classpath as necessary.
302
Set JavaDoc<String JavaDoc> wscJars = new HashSet JavaDoc<String JavaDoc>();
303             boolean newWscJars = false;
304             String JavaDoc wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH);
305             if(wscClientClasspath != null) {
306                 String JavaDoc [] libs = PropertyUtils.tokenizePath(wscClientClasspath);
307                 for(int i = 0; i < libs.length; i++) {
308                     wscJars.add(libs[i]);
309                 }
310             }
311             
312             for(int i = 0; i < WSCOMPILE_JARS.length; i++) {
313                 if(!wscJars.contains(WSCOMPILE_JARS[i])) {
314                     wscJars.add(WSCOMPILE_JARS[i]);
315                     newWscJars = true;
316                 }
317             }
318             
319             if(newWscJars) {
320                 StringBuffer JavaDoc newClasspathBuf = new StringBuffer JavaDoc(256);
321                 for(Iterator JavaDoc iter = wscJars.iterator(); iter.hasNext(); ) {
322                     newClasspathBuf.append(iter.next().toString());
323                     if(iter.hasNext()) {
324                         newClasspathBuf.append(':');
325                     }
326                 }
327                 projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString());
328                 projectPropertiesChanged = true;
329             }
330         }
331         
332         // set tools.jar property if not set
333
if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) {
334             projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); // NOI18N
335
projectPropertiesChanged = true;
336         }
337         
338         if(projectPropertiesChanged) {
339             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties);
340         }
341         
342         return globalPropertiesChanged || projectPropertiesChanged;
343     }
344     
345     public void removeServiceClient(String JavaDoc serviceName) {
346         // 2. Remove service from project.xml
347
// Side effect: Regenerate build-impl.xsl
348
// Optional - if last service, remove properties we generated.
349
boolean needsSave = false;
350         boolean needsSave1 = false;
351         
352         /** Remove properties from project.properties
353          */

354         String JavaDoc featureProperty = "wscompile.client." + serviceName + ".features"; // NOI18N
355
String JavaDoc packageProperty = "wscompile.client." + serviceName + ".package"; // NOI18N
356
String JavaDoc proxyProperty = "wscompile.client." + serviceName + ".proxy"; //NOI18N
357

358         EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
359         EditableProperties ep1 = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
360         
361         if(ep.getProperty(featureProperty) != null) {
362             ep.remove(featureProperty);
363             needsSave = true;
364         }
365         
366         if(ep.getProperty(packageProperty) != null) {
367             ep.remove(packageProperty);
368             needsSave = true;
369         }
370         
371         if(ep1.getProperty(proxyProperty) != null) {
372             ep1.remove(proxyProperty);
373             needsSave1 = true;
374         }
375         
376         if(needsSave) {
377             helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
378         }
379         
380         if(needsSave1) {
381             helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep1);
382         }
383         
384         /** Locate root of web service client node structure in project,xml
385          */

386         Element JavaDoc data = helper.getPrimaryConfigurationData(true);
387         NodeList JavaDoc nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS);
388         Element JavaDoc clientElements = null;
389         
390         /* If there is a root, get all the names of the child services and search
391          * for the one we want to remove.
392          */

393         if(nodes.getLength() >= 1) {
394             clientElements = (Element JavaDoc) nodes.item(0);
395             NodeList JavaDoc clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME);
396             for(int i = 0; i < clientNameList.getLength(); i++ ) {
397                 Element JavaDoc clientNameElement = (Element JavaDoc) clientNameList.item(i);
398                 NodeList JavaDoc nl = clientNameElement.getChildNodes();
399                 if(nl.getLength() == 1) {
400                     Node JavaDoc n = nl.item(0);
401                     if(n.getNodeType() == Node.TEXT_NODE) {
402                         if(serviceName.equalsIgnoreCase(n.getNodeValue())) {
403                             // Found it! Now remove it.
404
Node JavaDoc serviceNode = clientNameElement.getParentNode();
405                             clientElements.removeChild(serviceNode);
406                             helper.putPrimaryConfigurationData(data, true);
407                             needsSave = true;
408                         }
409                     }
410                 }
411             }
412         }
413         
414         // !PW Lastly, save the project if we actually made any changes to any
415
// properties or the build script.
416
if(needsSave || needsSave1) {
417             try {
418                 ProjectManager.getDefault().saveProject(project);
419             } catch(IOException JavaDoc ex) {
420                 NotifyDescriptor desc = new NotifyDescriptor.Message(
421                 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), // NOI18N
422
NotifyDescriptor.ERROR_MESSAGE);
423                 DialogDisplayer.getDefault().notify(desc);
424             }
425         }
426     }
427     
428     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
429         String JavaDoc metaInfStr = helper.getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.META_INF);
430         String JavaDoc wsdlFolderStr = metaInfStr + '/' + WSDL_FOLDER; // NOI18N
431
FileObject wsdlFolder = project.getProjectDirectory().getFileObject(wsdlFolderStr);
432         if (wsdlFolder == null && create) {
433             wsdlFolder = FileUtil.createFolder(project.getProjectDirectory(), wsdlFolderStr);
434         }
435         
436         return wsdlFolder;
437     }
438     
439     public List JavaDoc<ClientStubDescriptor> getStubDescriptors() {
440         ArrayList JavaDoc<ClientStubDescriptor> stubs = new ArrayList JavaDoc<ClientStubDescriptor>(2);
441         String JavaDoc version = project.getCarModule().getJ2eePlatformVersion();
442         if(J2eeModule.J2EE_14.equals(version)) {
443             stubs.add(jsr109ClientStub);
444         }
445         stubs.add(jaxrpcClientStub);
446         return stubs;
447     }
448     
449     private boolean isProjectOpened() {
450         Project[] projects = OpenProjects.getDefault().getOpenProjects();
451         for (int i = 0; i < projects.length; i++) {
452             if (projects[i].equals(project))
453                 return true;
454         }
455         return false;
456     }
457     
458     /** !PW This method is exposed in the client support API. Though it's
459      * implementation makes more sense here than anywhere else, perhaps this
460      * and the other project.xml/project.properties related methods in this
461      * object should be refactored into another object that this one delegates
462      * to. That way, this method would be directly available within the web
463      * web module, as it is needed, and remain missing from the API (where it
464      * probably does not belong at this time.
465      */

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

690     private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor(
691         ClientStubDescriptor.JAXRPC_CLIENT_STUB,
692         NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"LBL_JAXRPCStaticClientStub"),
693         new String JavaDoc [] { "wsi", "strict" }); // NOI18N
694

695     public void addServiceClientReference(String JavaDoc serviceName, String JavaDoc fqServiceName, String JavaDoc relativeWsdlPath, String JavaDoc relativeMappingPath, String JavaDoc[] portSEIInfo) {
696
697         FileObject ddFO = getDeploymentDescriptor();
698
699         // If we get null for the deployment descriptor, ignore this step.
700
if (ddFO != null) {
701
702             try {
703                 RootInterface rootDD = DDProvider.getDefault().getDDRoot(ddFO);
704
705                 ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", serviceName); // NOI18N
706
if(serviceRef == null) {
707                     serviceRef = (ServiceRef) rootDD.addBean("ServiceRef", // NOI18N
708
new String JavaDoc [] { /* property list */
709                             "ServiceRefName", // NOI18N
710
"ServiceInterface", // NOI18N
711
"WsdlFile", // NOI18N
712
"JaxrpcMappingFile" // NOI18N
713
},
714                         new String JavaDoc [] { /* property values */
715                             // service name
716
serviceName,
717                             // interface package . service name
718
fqServiceName,
719                             // web doc base / wsdl folder / wsdl file name
720
relativeWsdlPath,
721                             // web doc base / mapping file name
722
relativeMappingPath
723                         },
724                         "ServiceRefName"); // NOI18N
725
} else {
726                     serviceRef.setServiceInterface(fqServiceName);
727                     serviceRef.setWsdlFile(new URI JavaDoc(relativeWsdlPath));
728                     serviceRef.setJaxrpcMappingFile(relativeMappingPath);
729                 }
730
731                 PortComponentRef [] portRefArray = new PortComponentRef [portSEIInfo.length];
732                 for (int pi = 0; pi < portRefArray.length; pi++) {
733                     portRefArray[pi] = (PortComponentRef) serviceRef.createBean("PortComponentRef"); // NOI18N
734
portRefArray[pi].setServiceEndpointInterface(portSEIInfo[pi]); // NOI18N
735
}
736                 serviceRef.setPortComponentRef(portRefArray);
737                 rootDD.write(ddFO);
738
739             } catch (IOException JavaDoc ex) {
740                 // Strange thing happen
741
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
742             } catch (NameAlreadyUsedException ex) {
743                 // Should never happen because we look for it by name first.
744
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
745             } catch (URISyntaxException JavaDoc ex) {
746                 // Programmer error - validation of input data should ensure this never happens.
747
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
748             } catch (ClassNotFoundException JavaDoc ex) {
749                 // Programmer error - mistyped object name.
750
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
751             }
752             
753         }
754         
755     }
756     
757     /** Stub descriptor for services and clients supported by this project type.
758      */

759     private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor {
760         
761         private String JavaDoc [] defaultFeatures;
762         
763         public JAXRPCClientStubDescriptor(String JavaDoc name, String JavaDoc displayName, String JavaDoc [] defaultFeatures) {
764             super(name, displayName);
765             
766             this.defaultFeatures = defaultFeatures;
767         }
768         
769         public String JavaDoc [] getDefaultFeatures() {
770             return defaultFeatures;
771         }
772         
773         public String JavaDoc getDefaultFeaturesAsArgument() {
774             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(defaultFeatures.length*32);
775             for(int i = 0; i < defaultFeatures.length; i++) {
776                 if(i > 0) {
777                     buf.append(','); // NOI18N
778
}
779                 
780                 buf.append(defaultFeatures[i]);
781             }
782             return buf.toString();
783         }
784         
785         void setDefaultFeatures(String JavaDoc[] defaultFeatures) {
786             this.defaultFeatures=defaultFeatures;
787         }
788     }
789     
790     public void setProxyJVMOptions(String JavaDoc proxyHost, String JavaDoc proxyPort) {
791         this.proxyHost=proxyHost;
792         this.proxyPort=proxyPort;
793     }
794     
795     private static final String JavaDoc PROXY_HOST_OPTION="-Dhttp.proxyHost"; //NOI18N
796
private static final String JavaDoc PROXY_PORT_OPTION="-Dhttp.proxyPort"; //NOI18N
797
private static final String JavaDoc NON_PROXY_HOSTS_OPTION="-Dhttp.nonProxyHosts"; //NOI18N
798

799     private boolean addJVMProxyOptions(EditableProperties prop, String JavaDoc proxyHost, String JavaDoc proxyPort) {
800         String JavaDoc jvmOptions = prop.getProperty(AppClientProjectProperties.RUN_JVM_ARGS);
801         boolean modif=false;
802         String JavaDoc localHosts = "localhost"; //NOI18N
803
try {
804             localHosts = InetAddress.getLocalHost().getCanonicalHostName();
805         } catch (UnknownHostException JavaDoc ex) {}
806         if (!"localhost".equals(localHosts)) localHosts='\"'+localHosts+"|localhost\""; //NOI18N
807
if (jvmOptions==null || jvmOptions.length()==0) {
808             jvmOptions = PROXY_HOST_OPTION+'='+proxyHost+
809                     ' '+PROXY_PORT_OPTION+'='+proxyPort+
810                     ' '+NON_PROXY_HOSTS_OPTION+'='+localHosts;
811             modif=true;
812         } else {
813             if (jvmOptions.indexOf(PROXY_HOST_OPTION)<0) {
814                 jvmOptions+=' '+PROXY_HOST_OPTION+'='+proxyHost;
815                 modif=true;
816             }
817             if (jvmOptions.indexOf(PROXY_PORT_OPTION)<0) {
818                 jvmOptions+=' '+PROXY_PORT_OPTION+'='+proxyPort;
819                 modif=true;
820             }
821             if (jvmOptions.indexOf(NON_PROXY_HOSTS_OPTION)<0) {
822                 jvmOptions+=' '+NON_PROXY_HOSTS_OPTION+'='+localHosts;
823                 modif=true;
824             }
825         }
826         if (modif) prop.setProperty(AppClientProjectProperties.RUN_JVM_ARGS,jvmOptions);
827         return modif;
828     }
829
830     public String JavaDoc getServiceRefName(String JavaDoc serviceName) {
831         //noop
832
return null;
833     }
834     
835 }
836
Popular Tags