1 19 20 package org.netbeans.modules.web.project; 21 22 import java.net.URI ; 23 import java.net.URISyntaxException ; 24 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException; 25 import org.netbeans.modules.j2ee.dd.api.common.PortComponentRef; 26 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 27 import org.netbeans.modules.j2ee.dd.api.common.ServiceRef; 28 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor; 29 import static org.netbeans.modules.websvc.api.client.WebServicesClientConstants.*; 30 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport; 31 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl; 32 import java.io.IOException ; 33 import java.util.Arrays ; 34 import java.util.ArrayList ; 35 import java.util.HashSet ; 36 import java.util.List ; 37 import java.util.Iterator ; 38 import org.netbeans.api.project.Project; 39 import org.netbeans.api.project.ProjectManager; 40 import org.netbeans.api.project.ui.OpenProjects; 41 import org.netbeans.spi.project.support.ant.AntProjectHelper; 42 import org.netbeans.spi.project.support.ant.EditableProperties; 43 import org.netbeans.spi.project.support.ant.PropertyUtils; 44 import org.openide.ErrorManager; 45 import org.openide.DialogDisplayer; 46 import org.openide.NotifyDescriptor; 47 import org.openide.filesystems.FileObject; 48 import org.openide.util.NbBundle; 49 import org.w3c.dom.Document ; 50 import org.w3c.dom.Element ; 51 import org.w3c.dom.NodeList ; 52 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 53 import org.netbeans.modules.j2ee.dd.api.web.ServletMapping; 54 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 55 import org.netbeans.modules.j2ee.dd.api.web.DDProvider; 56 import org.netbeans.modules.web.api.webmodule.WebModule; 57 import org.netbeans.spi.project.support.ant.ReferenceHelper; 58 59 60 65 public class WebProjectWebServicesClientSupport implements WebServicesClientSupportImpl{ 66 private WebProject project; 67 private AntProjectHelper helper; 68 private ReferenceHelper referenceHelper; 69 70 71 public WebProjectWebServicesClientSupport(WebProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) { 72 this.project = project; 73 this.helper = helper; 74 this.referenceHelper = referenceHelper; 75 } 76 77 private WebApp getWebApp() { 78 try { 79 FileObject deploymentDescriptor = getDeploymentDescriptor(); 80 if(deploymentDescriptor != null) { 81 return DDProvider.getDefault().getDDRoot(deploymentDescriptor); 82 } 83 } catch (java.io.IOException e) { 84 org.openide.ErrorManager.getDefault().log(e.getLocalizedMessage()); 85 } 86 return null; 87 } 88 89 106 109 public FileObject getWsDDFolder() { 110 return getWebInf(); 111 } 112 113 117 public String getArchiveDDFolderName() { 118 return "WEB-INF"; } 120 121 125 public String getImplementationBean(String linkName) { 126 WebApp webApp = getWebApp(); 127 org.netbeans.modules.j2ee.dd.api.web.Servlet[] servlets = webApp.getServlet(); 128 for(int i = 0; i < servlets.length; i++) { 129 if(servlets[i].getServletName().equals(linkName)) { 130 return servlets[i].getServletClass(); 131 } 132 } 133 return null; 134 } 135 136 public void removeServiceEntry(String linkName) { 137 WebApp webApp = getWebApp(); 139 Servlet[] servlets = webApp.getServlet(); 140 for(int i = 0; i < servlets.length; i++) { 141 Servlet servlet = servlets[i]; 142 if(servlet.getServletName().equals(linkName)) { 143 webApp.removeServlet(servlet); 144 break; 145 } 146 } 147 ServletMapping[] mappings = webApp.getServletMapping(); 148 for(int j = 0; j < mappings.length; j++ ) { 149 ServletMapping mapping = mappings[j]; 150 if(mapping.getServletName().equals(linkName)) { 151 webApp.removeServletMapping(mapping); 152 } 153 } 154 try { 155 webApp.write(getDeploymentDescriptor()); 157 } 158 catch(java.io.IOException e) { 159 NotifyDescriptor ndd = 160 new NotifyDescriptor.Message(NbBundle.getMessage(this.getClass(), "MSG_Unable_WRITE_WS_DD"), NotifyDescriptor.ERROR_MESSAGE); 162 DialogDisplayer.getDefault().notify(ndd); 163 } 164 } 165 166 public AntProjectHelper getAntProjectHelper() { 167 return helper; 168 } 169 170 public ReferenceHelper getReferenceHelper(){ 171 return referenceHelper; 172 } 173 174 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) { 176 this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null); 177 } 178 179 180 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String [] wscompileFeatures) { 182 boolean needsSave = false; 188 boolean modifiedProjectProperties = false; 189 boolean modifiedPrivateProperties = false; 190 191 194 Element data = helper.getPrimaryConfigurationData(true); 195 Document doc = data.getOwnerDocument(); 196 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 197 Element clientElements = null; 198 199 if(nodes.getLength() == 0) { 200 clientElements = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENTS); 203 NodeList srcRoots = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); assert srcRoots.getLength() == 1 : "Invalid project.xml."; data.insertBefore(clientElements, srcRoots.item(0)); 206 } else { 207 clientElements = (Element ) nodes.item(0); 208 } 209 210 212 boolean serviceAlreadyAdded = false; 213 NodeList clientNameList = clientElements.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 214 for(int i = 0; i < clientNameList.getLength(); i++ ) { 215 Element clientNameElement = (Element ) clientNameList.item(i); 216 NodeList nl = clientNameElement.getChildNodes(); 217 if(nl.getLength() >= 1) { 218 org.w3c.dom.Node n = nl.item(0); 219 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 220 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 221 serviceAlreadyAdded = true; 222 223 } 227 } 228 } 229 } 230 231 233 if(!serviceAlreadyAdded) { 234 Element clientElement = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT); 235 clientElements.appendChild(clientElement); 236 Element clientElementName = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 237 clientElement.appendChild(clientElementName); 238 clientElementName.appendChild(doc.createTextNode(serviceName)); 239 Element clientElementStubType = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE); 240 clientElement.appendChild(clientElementStubType); 241 clientElementStubType.appendChild(doc.createTextNode(stubDescriptor.getName())); 242 Element clientElementSourceUrl = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 243 clientElement.appendChild(clientElementSourceUrl); 244 clientElementSourceUrl.appendChild(doc.createTextNode(sourceUrl)); 245 helper.putPrimaryConfigurationData(data, true); 246 needsSave = true; 247 } 248 249 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 250 EditableProperties privateProperties = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 251 252 { 254 String featurePropertyName = "wscompile.client." + serviceName + ".features"; String defaultFeatures = "wsi, strict"; if(stubDescriptor instanceof JAXRPCClientStubDescriptor) { 257 JAXRPCClientStubDescriptor stubDesc = (JAXRPCClientStubDescriptor) stubDescriptor; 258 if (wscompileFeatures!=null) stubDesc.setDefaultFeatures(wscompileFeatures); 259 defaultFeatures = stubDesc.getDefaultFeaturesAsArgument(); 260 } else { 261 } 263 String oldFeatures = projectProperties.getProperty(featurePropertyName); 264 if(!defaultFeatures.equals(oldFeatures)) { 265 projectProperties.put(featurePropertyName, defaultFeatures); 266 modifiedProjectProperties = true; 267 } 268 } 269 270 { 272 String packagePropertyName = "wscompile.client." + serviceName + ".package"; String oldPackageName = projectProperties.getProperty(packagePropertyName); 274 if(!packageName.equals(oldPackageName)) { 275 projectProperties.put(packagePropertyName, packageName); 276 modifiedProjectProperties = true; 277 } 278 } 279 280 if (proxyHost!=null && proxyHost.length()>0) { 282 String proxyProperty = "wscompile.client." + serviceName + ".proxy"; String oldProxyProperty = privateProperties.getProperty(proxyProperty); 284 if(!proxyProperty.equals(oldProxyProperty)) { 285 privateProperties.put(proxyProperty, proxyHost+":"+(proxyPort==null?"8080":proxyPort)); modifiedPrivateProperties = true; 287 } 288 } 289 290 if(modifiedProjectProperties) { 291 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 292 needsSave = true; 293 } 294 if(modifiedPrivateProperties) { 295 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties); 296 needsSave = true; 297 } 298 299 if(updateWsCompileProperties(serviceName)) { 302 needsSave = true; 303 } 304 305 if(needsSave) { 308 try { 309 ProjectManager.getDefault().saveProject(project); 310 } catch(IOException ex) { 311 NotifyDescriptor desc = new NotifyDescriptor.Message( 312 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 314 DialogDisplayer.getDefault().notify(desc); 315 } 316 } 317 } 318 319 public void addInfrastructure(String implBeanClass, FileObject pkg) { 320 } 322 323 public FileObject getDeploymentDescriptor() { 324 FileObject webInfFo = getWebInf(); 325 if (webInfFo==null) { 326 if (isProjectOpened()) { 327 DialogDisplayer.getDefault().notify( 328 new NotifyDescriptor.Message(NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_WebInfCorrupted"), NotifyDescriptor.ERROR_MESSAGE)); 330 } 331 return null; 332 } 333 return getWebInf().getFileObject(ProjectWebModule.FILE_DD); 334 } 335 336 public FileObject getWebInf() { 337 FileObject documentBase = getDocumentBase(); 338 if (documentBase != null) 339 return documentBase.getFileObject(ProjectWebModule.FOLDER_WEB_INF); 340 else 341 return null; 342 } 343 344 public FileObject getDocumentBase() { 345 return getFileObject("web.docbase.dir"); } 347 348 private FileObject getFileObject(String propname) { 349 String prop = helper.getStandardPropertyEvaluator().getProperty(propname); 350 if (prop != null) { 351 return helper.resolveFileObject(prop); 352 } else { 353 return null; 354 } 355 } 356 357 private boolean updateWsCompileProperties(String serviceName) { 358 370 boolean globalPropertiesChanged = false; 371 372 EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); 373 if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 374 globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); 376 try { 377 PropertyUtils.putGlobalProperties(globalProperties); 378 } catch(IOException ex) { 379 NotifyDescriptor desc = new NotifyDescriptor.Message( 380 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 382 DialogDisplayer.getDefault().notify(desc); 383 } 384 385 globalPropertiesChanged = true; 386 } 387 388 389 boolean projectPropertiesChanged = false; 390 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 391 392 { HashSet wscJars = new HashSet (); 394 boolean newWscJars = false; 395 String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); 396 if(wscClientClasspath != null) { 397 String [] libs = PropertyUtils.tokenizePath(wscClientClasspath); 398 for(int i = 0; i < libs.length; i++) { 399 wscJars.add(libs[i]); 400 } 401 } 402 403 for(int i = 0; i < WSCOMPILE_JARS.length; i++) { 404 if(!wscJars.contains(WSCOMPILE_JARS[i])) { 405 wscJars.add(WSCOMPILE_JARS[i]); 406 newWscJars = true; 407 } 408 } 409 410 if(newWscJars) { 411 StringBuffer newClasspathBuf = new StringBuffer (256); 412 for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { 413 newClasspathBuf.append(iter.next().toString()); 414 if(iter.hasNext()) { 415 newClasspathBuf.append(':'); 416 } 417 } 418 projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); 419 projectPropertiesChanged = true; 420 } 421 } 422 423 if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 425 projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); projectPropertiesChanged = true; 427 } 428 429 if(projectPropertiesChanged) { 430 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 431 } 432 433 return globalPropertiesChanged || projectPropertiesChanged; 434 } 435 436 public void removeServiceClient(String serviceName) { 437 boolean needsSave = false; 441 boolean needsSave1 = false; 442 443 445 String featureProperty = "wscompile.client." + serviceName + ".features"; String packageProperty = "wscompile.client." + serviceName + ".package"; String proxyProperty = "wscompile.client." + serviceName + ".proxy"; 449 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 450 EditableProperties ep1 = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 451 452 if(ep.getProperty(featureProperty) != null) { 453 ep.remove(featureProperty); 454 needsSave = true; 455 } 456 457 if(ep.getProperty(packageProperty) != null) { 458 ep.remove(packageProperty); 459 needsSave = true; 460 } 461 462 if(ep1.getProperty(proxyProperty) != null) { 463 ep1.remove(proxyProperty); 464 needsSave1 = true; 465 } 466 467 if(needsSave) { 468 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 469 } 470 471 if(needsSave1) { 472 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep1); 473 } 474 475 477 Element data = helper.getPrimaryConfigurationData(true); 478 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 479 Element clientElements = null; 480 481 484 if(nodes.getLength() >= 1) { 485 clientElements = (Element ) nodes.item(0); 486 NodeList clientNameList = clientElements.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 487 for(int i = 0; i < clientNameList.getLength(); i++ ) { 488 Element clientNameElement = (Element ) clientNameList.item(i); 489 NodeList nl = clientNameElement.getChildNodes(); 490 if(nl.getLength() == 1) { 491 org.w3c.dom.Node n = nl.item(0); 492 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 493 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 494 org.w3c.dom.Node serviceNode = clientNameElement.getParentNode(); 496 clientElements.removeChild(serviceNode); 497 helper.putPrimaryConfigurationData(data, true); 498 needsSave = true; 499 } 500 } 501 } 502 } 503 } 504 505 if(needsSave || needsSave1) { 508 try { 509 ProjectManager.getDefault().saveProject(project); 510 } catch(IOException ex) { 511 NotifyDescriptor desc = new NotifyDescriptor.Message( 512 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 514 DialogDisplayer.getDefault().notify(desc); 515 } 516 } 517 } 518 519 public FileObject getWsdlFolder(boolean create) throws IOException { 520 FileObject wsdlFolder = null; 521 FileObject webInf = getWebInf(); 522 523 if(webInf != null) { 524 wsdlFolder = webInf.getFileObject(WSDL_FOLDER); 525 if(wsdlFolder == null && create) { 526 wsdlFolder = webInf.createFolder(WSDL_FOLDER); 527 } 528 } else if(create) { 529 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, 532 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_WebInfNotFoundForWsdlFolder")); 533 } 534 535 return wsdlFolder; 536 } 537 538 public List getStubDescriptors() { 539 ArrayList stubs = new ArrayList (2); 540 String version = project.getWebModule().getJ2eePlatformVersion(); 541 if(WebModule.J2EE_14_LEVEL.equals(version)) { 542 stubs.add(jsr109ClientStub); 543 } 544 stubs.add(jaxrpcClientStub); 545 return stubs; 546 } 547 548 private boolean isProjectOpened() { 549 if (OpenProjects.getDefault() == null) 552 return true; 553 554 Project[] projects = OpenProjects.getDefault().getOpenProjects(); 555 for (int i = 0; i < projects.length; i++) { 556 if (projects[i].equals(project)) 557 return true; 558 } 559 return false; 560 } 561 562 570 private static final String [] WSCOMPILE_CLIENT_FEATURES = { 571 "datahandleronly", "explicitcontext", 575 "jaxbenumtype", 577 "nodatabinding", "noencodedtypes", 579 "nomultirefs", 580 "norpcstructures", "novalidation", "resolveidref", 583 "searchschema", "serializeinterfaces", 585 "strict", "wsi", "unwrap", "donotoverride", "donotunwrap", }; 592 593 private static final List allClientFeatures = Arrays.asList(WSCOMPILE_CLIENT_FEATURES); 594 595 private static final String [] WSCOMPILE_KEY_CLIENT_FEATURES = { 596 "wsi", 597 "strict", 598 "norpcstructures", 599 "unwrap", 600 "donotunwrap", 601 "donotoverride", 602 "datahandleronly", 603 "nodatabinding", 604 "novalidation", 605 "searchschema", 606 }; 607 608 private static final List importantClientFeatures = Arrays.asList(WSCOMPILE_KEY_CLIENT_FEATURES); 609 610 public List getServiceClients() { 611 List serviceNames = new ArrayList (); 612 613 Element data = helper.getPrimaryConfigurationData(true); 614 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 615 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 616 617 if(nodes.getLength() != 0) { 618 Element clientElements = (Element ) nodes.item(0); 619 NodeList clientNameList = clientElements.getElementsByTagNameNS( 620 WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 621 for(int i = 0; i < clientNameList.getLength(); i++ ) { 622 Element clientNameElement = (Element ) clientNameList.item(i); 623 NodeList nl = clientNameElement.getChildNodes(); 624 if(nl.getLength() == 1) { 625 org.w3c.dom.Node n = nl.item(0); 626 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 627 String serviceName = n.getNodeValue(); 628 String currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features"); 629 if(currentFeatures == null) { 630 currentFeatures = "wsi, strict"; 638 } 639 ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode()); 640 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 652 }; 653 WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings( 654 serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures); 655 serviceNames.add(settings); 656 } else { 657 } 659 } else { 660 } 662 } 663 } 664 665 return serviceNames; 666 } 667 668 private ClientStubDescriptor getClientStubDescriptor(org.w3c.dom.Node parentNode) { 669 ClientStubDescriptor result = null; 670 671 if(parentNode instanceof Element ) { 672 Element parentElement = (Element ) parentNode; 673 NodeList clientNameList = parentElement.getElementsByTagNameNS( 674 WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE); 675 if(clientNameList.getLength() == 1) { 676 Element clientStubElement = (Element ) clientNameList.item(0); 677 NodeList nl = clientStubElement.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 String stubName = n.getNodeValue(); 682 if(ClientStubDescriptor.JSR109_CLIENT_STUB.equals(stubName)) { 683 result = jsr109ClientStub; 684 } else if(ClientStubDescriptor.JAXRPC_CLIENT_STUB.equals(stubName)) { 685 result = jaxrpcClientStub; 686 } 687 } 688 } 689 } 690 } 691 692 return result; 693 } 694 695 public String getWsdlSource(String serviceName) { 696 Element data = helper.getPrimaryConfigurationData(true); 697 String wsdlSource = null; 698 699 Element clientElement = getWebServiceClientNode(data, serviceName); 700 if(clientElement != null) { 701 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 702 WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 703 if(fromWsdlList.getLength() == 1) { 704 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 705 NodeList nl = fromWsdlElement.getChildNodes(); 706 if(nl.getLength() == 1) { 707 org.w3c.dom.Node n = nl.item(0); 708 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 709 wsdlSource = n.getNodeValue(); 710 } 711 } 712 } 713 } 714 715 return wsdlSource; 716 } 717 718 public void setWsdlSource(String serviceName, String wsdlSource) { 719 Element data = helper.getPrimaryConfigurationData(true); 720 Document doc = data.getOwnerDocument(); 721 boolean needsSave = false; 722 723 Element clientElement = getWebServiceClientNode(data, serviceName); 724 if(clientElement != null) { 725 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 726 WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 727 if(fromWsdlList.getLength() > 0) { 728 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 729 NodeList nl = fromWsdlElement.getChildNodes(); 730 if(nl.getLength() > 0) { 731 org.w3c.dom.Node n = nl.item(0); 732 n.setNodeValue(wsdlSource); 733 } else { 734 fromWsdlElement.appendChild(doc.createTextNode(wsdlSource)); 735 } 736 } else { 737 Element clientElementSourceUrl = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 738 clientElement.appendChild(clientElementSourceUrl); 739 clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource)); 740 } 741 742 needsSave = true; 743 } 744 745 if(needsSave) { 747 try { 748 ProjectManager.getDefault().saveProject(project); 749 } catch(IOException ex) { 750 NotifyDescriptor desc = new NotifyDescriptor.Message( 751 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 753 DialogDisplayer.getDefault().notify(desc); 754 } 755 } 756 } 757 758 private Element getWebServiceClientNode(Element data, String serviceName) { 759 Element clientElement = null; 760 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 761 762 if(nodes.getLength() != 0) { 763 Element clientElements = (Element ) nodes.item(0); 764 NodeList clientNameList = clientElements.getElementsByTagNameNS( 765 WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 766 for(int i = 0; i < clientNameList.getLength(); i++ ) { 767 Element clientNameElement = (Element ) clientNameList.item(i); 768 NodeList nl = clientNameElement.getChildNodes(); 769 if(nl.getLength() == 1) { 770 org.w3c.dom.Node n = nl.item(0); 771 if(n.getNodeType() == org.w3c.dom.Node.TEXT_NODE) { 772 String name = n.getNodeValue(); 773 if(serviceName.equals(name)) { 774 org.w3c.dom.Node node = clientNameElement.getParentNode(); 775 clientElement = (node instanceof Element ) ? (Element ) node : null; 776 break; 777 } 778 } else { 779 } 781 } 782 } 783 } 784 785 return clientElement; 786 } 787 788 private static final JAXRPCClientStubDescriptor jsr109ClientStub = new JAXRPCClientStubDescriptor( 790 ClientStubDescriptor.JSR109_CLIENT_STUB, 791 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"LBL_JSR109ClientStub"), 792 new String [] { "wsi", "strict" }); 793 794 private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor( 795 ClientStubDescriptor.JAXRPC_CLIENT_STUB, 796 NbBundle.getMessage(WebProjectWebServicesClientSupport.class,"LBL_JAXRPCStaticClientStub"), 797 new String [] { "wsi", "strict" }); 798 799 public void addServiceClientReference(String serviceName, String fqServiceName, String relativeWsdlPath, String relativeMappingPath, String [] portSEIInfo) { 800 801 FileObject ddFO = getDeploymentDescriptor(); 802 803 if (ddFO != null) { 805 806 try { 807 RootInterface rootDD = DDProvider.getDefault().getDDRoot(ddFO); 808 809 ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", serviceName); if(serviceRef == null) { 811 serviceRef = (ServiceRef) rootDD.addBean("ServiceRef", new String [] { 813 "ServiceRefName", "ServiceInterface", "WsdlFile", "JaxrpcMappingFile" }, 818 new String [] { 819 serviceName, 821 fqServiceName, 823 relativeWsdlPath, 825 relativeMappingPath 827 }, 828 "ServiceRefName"); } else { 830 serviceRef.setServiceInterface(fqServiceName); 831 serviceRef.setWsdlFile(new URI (relativeWsdlPath)); 832 serviceRef.setJaxrpcMappingFile(relativeMappingPath); 833 } 834 835 PortComponentRef [] portRefArray = new PortComponentRef [portSEIInfo.length]; 836 for (int pi = 0; pi < portRefArray.length; pi++) { 837 portRefArray[pi] = (PortComponentRef) serviceRef.createBean("PortComponentRef"); portRefArray[pi].setServiceEndpointInterface(portSEIInfo[pi]); } 840 serviceRef.setPortComponentRef(portRefArray); 841 rootDD.write(ddFO); 842 843 } catch (IOException ex) { 844 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 846 } catch (NameAlreadyUsedException ex) { 847 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 849 } catch (URISyntaxException ex) { 850 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 852 } catch (ClassNotFoundException ex) { 853 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 855 } 856 857 } 858 859 } 860 861 private String proxyHost,proxyPort; 862 863 864 public void setProxyJVMOptions(String proxyHost, String proxyPort) { 865 this.proxyHost=proxyHost; 866 this.proxyPort=proxyPort; 867 } 868 869 public String getServiceRefName(String serviceName) { 870 return "service/" + serviceName; 871 } 872 873 875 private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor { 876 877 private String [] defaultFeatures; 878 879 public JAXRPCClientStubDescriptor(String name, String displayName, String [] defaultFeatures) { 880 super(name, displayName); 881 882 this.defaultFeatures = defaultFeatures; 883 } 884 885 public String [] getDefaultFeatures() { 886 return defaultFeatures; 887 } 888 889 public String getDefaultFeaturesAsArgument() { 890 StringBuffer buf = new StringBuffer (defaultFeatures.length*32); 891 for(int i = 0; i < defaultFeatures.length; i++) { 892 if(i > 0) { 893 buf.append(','); 894 } 895 896 buf.append(defaultFeatures[i]); 897 } 898 return buf.toString(); 899 } 900 901 void setDefaultFeatures(String [] defaultFeatures) { 902 this.defaultFeatures=defaultFeatures; 903 } 904 } 905 906 } 907 | Popular Tags |