1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 22 import java.net.URI ; 23 import java.net.URISyntaxException ; 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.io.IOException ; 30 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException; 31 import org.netbeans.modules.j2ee.dd.api.common.PortComponentRef; 32 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 33 import org.netbeans.modules.j2ee.dd.api.common.ServiceRef; 34 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor; 35 import static org.netbeans.modules.websvc.api.client.WebServicesClientConstants.*; 36 import org.w3c.dom.Document ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.NodeList ; 39 import org.netbeans.spi.project.support.ant.AntProjectHelper; 40 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl; 41 import org.netbeans.spi.project.support.ant.EditableProperties; 42 import org.netbeans.spi.project.support.ant.PropertyUtils; 43 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 44 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 45 import org.netbeans.api.project.ProjectManager; 46 import org.netbeans.api.project.ProjectUtils; 47 import org.netbeans.api.project.SourceGroup; 48 import org.netbeans.api.project.Sources; 49 import org.openide.ErrorManager; 50 import org.openide.DialogDisplayer; 51 import org.openide.NotifyDescriptor; 52 import org.openide.filesystems.FileObject; 53 import org.openide.filesystems.FileUtil; 54 import org.openide.util.NbBundle; 55 import org.netbeans.api.java.project.JavaProjectConstants; 56 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 57 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport; 58 import org.netbeans.spi.project.support.ant.ReferenceHelper; 59 60 65 public class EjbJarWebServicesClientSupport implements WebServicesClientSupportImpl{ 66 67 private EjbJarProject project; 68 private AntProjectHelper helper; 69 private ReferenceHelper referenceHelper; 70 71 72 public EjbJarWebServicesClientSupport(EjbJarProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) { 73 this.project = project; 74 this.helper = helper; 75 this.referenceHelper = referenceHelper; 76 } 77 78 89 96 104 105 public AntProjectHelper getAntProjectHelper() { 106 return helper; 107 } 108 109 public ReferenceHelper getReferenceHelper(){ 110 return referenceHelper; 111 } 112 113 private boolean updateWsCompileProperties(String serviceName) { 114 126 boolean globalPropertiesChanged = false; 127 128 EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); 129 if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 130 globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); 131 132 try { 133 PropertyUtils.putGlobalProperties(globalProperties); 134 } catch(java.io.IOException ex) { 135 String mes = "Error saving global properties when adding wscompile.tools.classpath for service '" + serviceName + "'\r\n" + ex.getMessage(); 136 NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE); 137 DialogDisplayer.getDefault().notify(desc); 138 } 139 140 globalPropertiesChanged = true; 141 } 142 143 boolean projectPropertiesChanged = false; 144 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 145 146 { HashSet wscJars = new HashSet (); 148 boolean newWscJars = false; 149 String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); 150 if(wscClientClasspath != null) { 151 String [] libs = PropertyUtils.tokenizePath(wscClientClasspath); 152 for(int i = 0; i < libs.length; i++) { 153 wscJars.add(libs[i]); 154 } 155 } 156 157 for(int i = 0; i < WSCOMPILE_JARS.length; i++) { 158 if(!wscJars.contains(WSCOMPILE_JARS[i])) { 159 wscJars.add(WSCOMPILE_JARS[i]); 160 newWscJars = true; 161 } 162 } 163 164 if(newWscJars) { 165 StringBuffer newClasspathBuf = new StringBuffer (256); 166 for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { 167 newClasspathBuf.append(iter.next().toString()); 168 if(iter.hasNext()) { 169 newClasspathBuf.append(":"); 170 } 171 } 172 projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); 173 projectPropertiesChanged = true; 174 } 175 } 176 177 if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 179 projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); projectPropertiesChanged = true; 181 } 182 183 if(projectPropertiesChanged) { 184 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 185 } 186 return globalPropertiesChanged || projectPropertiesChanged; 187 } 188 189 190 private EjbJar getEjbJar() { 191 try { 192 return DDProvider.getDefault().getMergedDDRoot(org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project)[0].getMetadataUnit()); 194 } catch (java.io.IOException e) { 195 org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage()); 196 } 197 return null; 198 } 199 200 public FileObject getMetaInf() { 201 EjbJarProvider provider = (EjbJarProvider)project.getLookup().lookup(EjbJarProvider.class); 202 return provider.getMetaInf(); 203 } 204 205 public FileObject getDeploymentDescriptor() { 206 FileObject metaInfFo = getMetaInf(); 207 if (metaInfFo==null) { 208 return null; 209 } 210 return metaInfFo.getFileObject(EjbJarProvider.FILE_DD); 211 } 212 213 private String getPackageName(FileObject file){ 214 FileObject parent = file.getParent(); 215 Sources sources = ProjectUtils.getSources(project); 216 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 217 String packageName = null; 218 for (int i = 0; i < groups.length && packageName == null; i++) { 219 packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), parent); 220 if (packageName != null) { 221 packageName = groups[i].getName() + "/" + packageName; 222 } 223 } 224 return packageName + ""; 225 } 226 227 private FileObject getFileObject(String propname) { 228 String prop = helper.getStandardPropertyEvaluator().getProperty(propname); 229 if (prop != null) { 230 return helper.resolveFileObject(prop); 231 } 232 233 return null; 234 } 235 236 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) { 238 this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null); 239 } 240 241 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String [] wscompileFeatures) { 243 boolean needsSave = false; 249 boolean modifiedProjectProperties = false; 250 251 254 Element data = helper.getPrimaryConfigurationData(true); 255 Document doc = data.getOwnerDocument(); 256 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 257 Element clientElements = null; 258 259 if(nodes.getLength() == 0) { 260 clientElements = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENTS); 263 NodeList srcRoots = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); assert srcRoots.getLength() == 1 : "Invalid project.xml."; data.insertBefore(clientElements, srcRoots.item(0)); 266 } else { 267 clientElements = (Element ) nodes.item(0); 268 } 269 270 272 boolean serviceAlreadyAdded = false; 273 NodeList clientNameList = clientElements.getElementsByTagNameNS( 274 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 275 for(int i = 0; i < clientNameList.getLength(); i++ ) { 276 Element clientNameElement = (Element ) clientNameList.item(i); 277 NodeList nl = clientNameElement.getChildNodes(); 278 if(nl.getLength() >= 1) { 279 org.w3c.dom.Node n = nl.item(0); 280 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 281 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 282 serviceAlreadyAdded = true; 283 284 } 288 } 289 } 290 } 291 292 294 if(!serviceAlreadyAdded) { 295 Element clientElement = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT); 296 clientElements.appendChild(clientElement); 297 Element clientElementName = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 298 clientElement.appendChild(clientElementName); 299 clientElementName.appendChild(doc.createTextNode(serviceName)); 300 Element clientElementStubType = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE); 301 clientElement.appendChild(clientElementStubType); 302 clientElementStubType.appendChild(doc.createTextNode(stubDescriptor.getName())); 303 Element clientElementSourceUrl = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 304 clientElement.appendChild(clientElementSourceUrl); 305 clientElementSourceUrl.appendChild(doc.createTextNode(sourceUrl)); 306 helper.putPrimaryConfigurationData(data, true); 307 needsSave = true; 308 } 309 310 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 311 { 313 String featurePropertyName = "wscompile.client." + serviceName + ".features"; String defaultFeatures = "wsi, strict"; if (stubDescriptor instanceof JAXRPCClientStubDescriptor) { 316 JAXRPCClientStubDescriptor stubDesc = (JAXRPCClientStubDescriptor) stubDescriptor; 317 if (wscompileFeatures!=null) stubDesc.setDefaultFeatures(wscompileFeatures); 318 defaultFeatures = stubDesc.getDefaultFeaturesAsArgument(); 319 } else { 320 } 322 String oldFeatures = projectProperties.getProperty(featurePropertyName); 323 if(!defaultFeatures.equals(oldFeatures)) { 324 projectProperties.put(featurePropertyName, defaultFeatures); 325 modifiedProjectProperties = true; 326 } 327 } 328 329 { 331 String packagePropertyName = "wscompile.client." + serviceName + ".package"; String oldPackageName = projectProperties.getProperty(packagePropertyName); 333 if(!packageName.equals(oldPackageName)) { 334 projectProperties.put(packagePropertyName, packageName); 335 modifiedProjectProperties = true; 336 } 337 } 338 339 if(modifiedProjectProperties) { 340 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 341 needsSave = true; 342 } 343 344 if(updateWsCompileProperties(serviceName)) { 347 needsSave = true; 348 } 349 350 if(needsSave) { 353 try { 354 ProjectManager.getDefault().saveProject(project); 355 } catch(IOException ex) { 356 NotifyDescriptor desc = new NotifyDescriptor.Message( 357 NbBundle.getMessage(EjbJarWebServicesSupport.class, 358 "MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 360 DialogDisplayer.getDefault().notify(desc); 361 } 362 } 363 } 364 365 public FileObject[] getJavaSources() { 366 return project.getSourceRoots().getRoots(); 367 } 368 369 public void addServiceClientReference(String serviceName, String fqServiceName, String relativeWsdlPath, String relativeMappingPath, String [] portSEIInfo) { 370 371 FileObject ddFO = getDeploymentDescriptor(); 372 373 if (ddFO != null) { 375 376 try { 377 RootInterface rootDD = DDProvider.getDefault().getMergedDDRoot(org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project)[0].getMetadataUnit()); 379 380 ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", serviceName); if (serviceRef == null) { 382 serviceRef = (ServiceRef) rootDD.addBean("ServiceRef", new String [] { 384 "ServiceRefName", "ServiceInterface", "WsdlFile", "JaxrpcMappingFile" }, 389 new String [] { 390 serviceName, 392 fqServiceName, 394 relativeWsdlPath, 396 relativeMappingPath 398 }, 399 "ServiceRefName"); } else { 401 serviceRef.setServiceInterface(fqServiceName); 402 serviceRef.setWsdlFile(new URI (relativeWsdlPath)); 403 serviceRef.setJaxrpcMappingFile(relativeMappingPath); 404 } 405 406 PortComponentRef [] portRefArray = new PortComponentRef [portSEIInfo.length]; 407 for (int pi = 0; pi < portRefArray.length; pi++) { 408 portRefArray[pi] = (PortComponentRef) serviceRef.createBean("PortComponentRef"); portRefArray[pi].setServiceEndpointInterface(portSEIInfo[pi]); } 411 serviceRef.setPortComponentRef(portRefArray); 412 rootDD.write(ddFO); 413 414 } catch (IOException ex) { 415 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 417 } catch (NameAlreadyUsedException ex) { 418 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 420 } catch (URISyntaxException ex) { 421 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 423 } catch (ClassNotFoundException ex) { 424 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 426 } 427 428 } 429 430 } 431 432 public void removeServiceClient(String serviceName) { 433 boolean needsSave = false; 437 438 440 String featureProperty = "wscompile.client." + serviceName + ".features"; String packageProperty = "wscompile.client." + serviceName + ".package"; EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 443 444 if(ep.getProperty(featureProperty) != null) { 445 ep.remove(featureProperty); 446 needsSave = true; 447 } 448 449 if(ep.getProperty(packageProperty) != null) { 450 ep.remove(packageProperty); 451 needsSave = true; 452 } 453 454 if(needsSave) { 455 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 456 } 457 458 460 Element data = helper.getPrimaryConfigurationData(true); 461 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 462 Element clientElements = null; 463 464 467 if(nodes.getLength() >= 1) { 468 clientElements = (Element ) nodes.item(0); 469 NodeList clientNameList = clientElements.getElementsByTagNameNS( 470 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 471 for(int i = 0; i < clientNameList.getLength(); i++ ) { 472 Element clientNameElement = (Element ) clientNameList.item(i); 473 NodeList nl = clientNameElement.getChildNodes(); 474 if(nl.getLength() == 1) { 475 org.w3c.dom.Node n = nl.item(0); 476 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 477 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 478 org.w3c.dom.Node serviceNode = clientNameElement.getParentNode(); 480 clientElements.removeChild(serviceNode); 481 helper.putPrimaryConfigurationData(data, true); 482 needsSave = true; 483 } 484 } 485 } 486 } 487 } 488 489 if(needsSave) { 492 try { 493 ProjectManager.getDefault().saveProject(project); 494 } catch(IOException ex) { 495 NotifyDescriptor desc = new NotifyDescriptor.Message( 496 NbBundle.getMessage(EjbJarWebServicesSupport.class, 497 "MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 499 DialogDisplayer.getDefault().notify(desc); 500 } 501 } 502 } 503 504 public FileObject getWsdlFolder(boolean create) throws IOException { 505 FileObject wsdlFolder = null; 506 FileObject metaInf = getMetaInf(); 507 508 if(metaInf != null) { 509 wsdlFolder = metaInf.getFileObject(WSDL_FOLDER); 510 if(wsdlFolder == null && create) { 511 wsdlFolder = metaInf.createFolder(WSDL_FOLDER); 512 } 513 } else if(create) { 514 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, 517 NbBundle.getMessage(EjbJarWebServicesSupport.class, "MSG_MetaInfNotFoundForWsdlFolder")); 518 } 519 520 return wsdlFolder; 521 } 522 523 public List getStubDescriptors() { 524 ArrayList stubs = new ArrayList (2); 525 530 stubs.add(jaxrpcClientStub); 531 return stubs; 532 } 533 534 542 private static final String [] WSCOMPILE_CLIENT_FEATURES = { 543 "datahandleronly", "explicitcontext", 547 "jaxbenumtype", 549 "nodatabinding", "noencodedtypes", 551 "nomultirefs", 552 "norpcstructures", "novalidation", "resolveidref", 555 "searchschema", "serializeinterfaces", 557 "strict", "wsi", "unwrap", "donotoverride", "donotunwrap", }; 564 565 private static final List allClientFeatures = Arrays.asList(WSCOMPILE_CLIENT_FEATURES); 566 567 private static final String [] WSCOMPILE_KEY_CLIENT_FEATURES = { 568 "wsi", 569 "strict", 570 "unwrap", 571 "donotunwrap", 572 "donotoverride", 573 "datahandleronly", 574 "nodatabinding", 575 "norpcstructures", 576 "novalidation", 577 "searchschema", 578 }; 579 580 private static final List importantClientFeatures = Arrays.asList(WSCOMPILE_KEY_CLIENT_FEATURES); 581 582 public List getServiceClients() { 583 List serviceNames = new ArrayList (); 584 585 Element data = helper.getPrimaryConfigurationData(true); 586 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 587 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 588 589 if(nodes.getLength() != 0) { 590 Element clientElements = (Element ) nodes.item(0); 591 NodeList clientNameList = clientElements.getElementsByTagNameNS( 592 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 593 for(int i = 0; i < clientNameList.getLength(); i++ ) { 594 Element clientNameElement = (Element ) clientNameList.item(i); 595 NodeList nl = clientNameElement.getChildNodes(); 596 if(nl.getLength() == 1) { 597 org.w3c.dom.Node n = nl.item(0); 598 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 599 String serviceName = n.getNodeValue(); 600 String currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features"); 601 if(currentFeatures == null) { 602 currentFeatures = "wsi, strict"; 610 } 611 ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode()); 612 boolean propVerbose = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".verbose")); boolean propDebug = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".debug")); boolean propPrintStackTrace = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".xPrintStackTrace")); boolean propExtensible = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".xSerializable")); boolean propOptimize = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".optimize")); boolean[] options = new boolean[] { propVerbose,propDebug,propPrintStackTrace,propExtensible,propOptimize 624 }; 625 WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings( 626 serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures); 627 serviceNames.add(settings); 628 } else { 629 } 631 } else { 632 } 634 } 635 } 636 637 return serviceNames; 638 } 639 640 private ClientStubDescriptor getClientStubDescriptor(org.w3c.dom.Node parentNode) { 641 ClientStubDescriptor result = null; 642 643 if(parentNode instanceof Element ) { 644 Element parentElement = (Element ) parentNode; 645 NodeList clientNameList = parentElement.getElementsByTagNameNS( 646 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesConstants.WEB_SERVICE_STUB_TYPE); 647 if(clientNameList.getLength() == 1) { 648 Element clientStubElement = (Element ) clientNameList.item(0); 649 NodeList nl = clientStubElement.getChildNodes(); 650 if(nl.getLength() == 1) { 651 org.w3c.dom.Node n = nl.item(0); 652 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 653 String stubName = n.getNodeValue(); 654 if (ClientStubDescriptor.JSR109_CLIENT_STUB.equals(stubName)) { 655 result = jsr109ClientStub; 656 } else if (ClientStubDescriptor.JAXRPC_CLIENT_STUB.equals(stubName)) { 657 result = jaxrpcClientStub; 658 } 659 } 660 } 661 } 662 } 663 664 return result; 665 } 666 667 public String getWsdlSource(String serviceName) { 668 Element data = helper.getPrimaryConfigurationData(true); 669 String wsdlSource = null; 670 671 Element clientElement = getWebServiceClientNode(data, serviceName); 672 if(clientElement != null) { 673 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 674 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesConstants.CLIENT_SOURCE_URL); 675 if(fromWsdlList.getLength() == 1) { 676 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 677 NodeList nl = fromWsdlElement.getChildNodes(); 678 if(nl.getLength() == 1) { 679 org.w3c.dom.Node n = nl.item(0); 680 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 681 wsdlSource = n.getNodeValue(); 682 } 683 } 684 } 685 } 686 687 return wsdlSource; 688 } 689 690 public void setWsdlSource(String serviceName, String wsdlSource) { 691 Element data = helper.getPrimaryConfigurationData(true); 692 Document doc = data.getOwnerDocument(); 693 boolean needsSave = false; 694 695 Element clientElement = getWebServiceClientNode(data, serviceName); 696 if(clientElement != null) { 697 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 698 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WebServicesConstants.CLIENT_SOURCE_URL); 699 if(fromWsdlList.getLength() > 0) { 700 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 701 NodeList nl = fromWsdlElement.getChildNodes(); 702 if(nl.getLength() > 0) { 703 org.w3c.dom.Node n = nl.item(0); 704 n.setNodeValue(wsdlSource); 705 } else { 706 fromWsdlElement.appendChild(doc.createTextNode(wsdlSource)); 707 } 708 } else { 709 Element clientElementSourceUrl = doc.createElementNS( 710 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 711 clientElement.appendChild(clientElementSourceUrl); 712 clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource)); 713 } 714 715 needsSave = true; 716 } 717 718 if(needsSave) { 720 try { 721 ProjectManager.getDefault().saveProject(project); 722 } catch(IOException ex) { 723 NotifyDescriptor desc = new NotifyDescriptor.Message( 724 NbBundle.getMessage(EjbJarWebServicesSupport.class, 725 "MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 727 DialogDisplayer.getDefault().notify(desc); 728 } 729 } 730 } 731 732 private Element getWebServiceClientNode(Element data, String serviceName) { 733 Element clientElement = null; 734 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 735 736 if(nodes.getLength() != 0) { 737 Element clientElements = (Element ) nodes.item(0); 738 NodeList clientNameList = clientElements.getElementsByTagNameNS( 739 EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 740 for(int i = 0; i < clientNameList.getLength(); i++ ) { 741 Element clientNameElement = (Element ) clientNameList.item(i); 742 NodeList nl = clientNameElement.getChildNodes(); 743 if(nl.getLength() == 1) { 744 org.w3c.dom.Node n = nl.item(0); 745 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 746 String name = n.getNodeValue(); 747 if(serviceName.equals(name)) { 748 org.w3c.dom.Node node = clientNameElement.getParentNode(); 749 clientElement = (node instanceof Element ) ? (Element ) node : null; 750 break; 751 } 752 } else { 753 } 755 } 756 } 757 } 758 759 return clientElement; 760 } 761 762 private static final JAXRPCClientStubDescriptor jsr109ClientStub = new JAXRPCClientStubDescriptor( 764 ClientStubDescriptor.JSR109_CLIENT_STUB, 765 NbBundle.getMessage(EjbJarWebServicesSupport.class,"LBL_JSR109ClientStub"), 766 new String [] { "wsi", "strict" }); 767 768 private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor( 769 ClientStubDescriptor.JAXRPC_CLIENT_STUB, 770 NbBundle.getMessage(EjbJarWebServicesSupport.class,"LBL_JAXRPCStaticClientStub"), 771 new String [] { "wsi", "strict" }); 772 773 774 public void setProxyJVMOptions(String proxyHost, String proxyPort) { 775 } 776 777 public String getServiceRefName(String serviceName) { 778 return "service/" + serviceName; 779 } 780 781 782 784 private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor { 785 786 private String [] defaultFeatures; 787 788 public JAXRPCClientStubDescriptor(String name, String displayName, String [] defaultFeatures) { 789 super(name, displayName); 790 791 this.defaultFeatures = defaultFeatures; 792 } 793 794 public String [] getDefaultFeatures() { 795 return defaultFeatures; 796 } 797 798 public String getDefaultFeaturesAsArgument() { 799 StringBuffer buf = new StringBuffer (defaultFeatures.length*32); 800 for(int i = 0; i < defaultFeatures.length; i++) { 801 if(i > 0) { 802 buf.append(","); 803 } 804 805 buf.append(defaultFeatures[i]); 806 } 807 return buf.toString(); 808 } 809 810 void setDefaultFeatures(String [] defaultFeatures) { 811 this.defaultFeatures=defaultFeatures; 812 } 813 } 814 } 815 | Popular Tags |