1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.beans.PropertyVetoException ; 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.text.MessageFormat ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 32 import javax.enterprise.deploy.model.DDBean ; 33 import javax.enterprise.deploy.model.XpathEvent ; 34 35 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 36 import org.netbeans.modules.j2ee.sun.dd.api.RootInterface; 37 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 38 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageSecurityBinding; 39 import org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceEndpoint; 40 import org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceDescription; 41 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb; 42 import org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans; 43 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar; 44 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 45 import org.netbeans.modules.j2ee.sun.dd.api.web.Servlet; 46 47 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 48 49 105 public class WebServiceDescriptor extends Base { 106 107 109 public static final String WEBSERVICE_DESCRIPTION_NAME = "webserviceDescriptionName"; public static final String WEBSERVICE_ENDPOINT = "webserviceEndpoint"; public static final String ENDPOINT_SECURITY_BINDING = "endpointSecurityBinding"; public static final String COMPONENT_LINK_NAME = "componentLinkName"; 114 115 116 private DDBean webServiceDescriptionNameDD; 117 118 119 private String wsdlPublishLocation; 120 121 122 private Map webServiceEndpointMap; 123 124 125 private EndpointHelper helper; 126 127 130 private boolean requiresDefaultEndpointUri; 131 132 133 public WebServiceDescriptor() { 134 setDescriptorElement(bundle.getString("BDN_WebServiceDescriptor")); } 136 137 142 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 143 super.init(dDBean, parent); 144 145 148 BaseRoot masterRoot = getConfig().getMasterDCBRoot(); 149 if(masterRoot instanceof WebAppRoot) { 150 helper = servletHelper; 151 requiresDefaultEndpointUri = false; 152 } else if(masterRoot instanceof EjbJarRoot) { 153 helper = ejbHelper; 154 requiresDefaultEndpointUri = (getJ2EEModuleVersion().compareSpecification(J2EEVersion.JAVAEE_5_0) < 0); 155 } else { 156 throw new ConfigurationException ("Unexpected master DConfigBean type: " + masterRoot); } 158 159 dDBean.addXpathListener(dDBean.getXpath(), this); 160 webServiceDescriptionNameDD = getNameDD("webservice-description-name"); 162 updateNamedBeanCache(SunWebApp.WEBSERVICE_DESCRIPTION); 163 164 loadFromPlanFile(getConfig()); 165 } 166 167 protected String getComponentName() { 168 return getWebServiceDescriptionName(); 169 } 170 171 174 175 public static final String FIELD_WSDL_PUBLISH_LOCATION = "wsdl-publish-location"; 177 178 protected void updateValidationFieldList() { 179 super.updateValidationFieldList(); 180 validationFieldList.add(FIELD_WSDL_PUBLISH_LOCATION); 181 } 182 183 public boolean validateField(String fieldId) { 184 ValidationError error = null; 185 186 if(fieldId.equals(FIELD_WSDL_PUBLISH_LOCATION)) { 190 String absoluteFieldXpath = getAbsoluteXpath(fieldId); 191 192 if(Utils.notEmpty(wsdlPublishLocation)) { 193 try { 194 URL testUrl = new URL (wsdlPublishLocation); 195 } catch(MalformedURLException ex) { 196 Object [] args = new Object [1]; 197 args[0] = wsdlPublishLocation; String message = MessageFormat.format(bundle.getString("ERR_InvalidUrl"), args); error = ValidationError.getValidationError(ValidationError.PARTITION_GLOBAL, absoluteFieldXpath, message); 200 } 201 } 202 203 if(error == null) { 204 error = ValidationError.getValidationErrorMask(ValidationError.PARTITION_GLOBAL, absoluteFieldXpath); 205 } 206 } 207 208 if(error != null) { 209 getMessageDB().updateError(error); 210 } 211 212 return (error == null || !Utils.notEmpty(error.getMessage())); 214 } 215 216 219 public String getHelpId() { 220 return "AS_CFG_WebServiceDescriptor"; 221 } 222 223 227 public String getWebServiceDescriptionName() { 228 return cleanDDBeanText(webServiceDescriptionNameDD); 229 } 230 231 233 public boolean isWarModule() { 234 return helper instanceof ServletHelper; 236 } 237 238 public boolean isEjbModule() { 239 return helper instanceof EjbHelper; 241 } 242 243 247 Collection getSnippets() { 248 Collection snippets = new ArrayList (); 249 250 Snippet snipOne = new DefaultSnippet() { 251 public CommonDDBean getDDSnippet() { 252 WebserviceDescription wsDesc = getConfig().getStorageFactory().createWebserviceDescription(); 254 wsDesc.setWebserviceDescriptionName(getWebServiceDescriptionName()); 255 wsDesc.setWsdlPublishLocation(getWsdlPublishLocation()); 256 return wsDesc; 257 } 258 259 public boolean hasDDSnippet() { 260 if(wsdlPublishLocation != null && wsdlPublishLocation.length() > 0) { 261 return true; 262 } 263 264 return false; 265 } 266 267 public String getPropertyName() { 268 return SunWebApp.WEBSERVICE_DESCRIPTION; 269 } 270 271 public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) { 272 CommonDDBean newBean = getDDSnippet(); 273 if(newBean != null) { 274 if(ddParent != null) { 275 helper.addWebServiceDescription(ddParent, newBean); 276 } 277 } 278 return newBean; 279 } 280 281 }; 282 283 Snippet snipTwo = new DefaultSnippet() { 284 public CommonDDBean getDDSnippet() { 285 return null; 292 } 293 294 public boolean hasDDSnippet() { 295 if(webServiceEndpointMap != null && webServiceEndpointMap.size() > 0) { 296 return true; 297 } 298 299 return false; 300 } 301 302 public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) { 303 RootInterface root = (RootInterface) ddParent; 306 String version = root.getVersion().toString(); 307 Iterator iter = webServiceEndpointMap.entrySet().iterator(); 308 309 while(iter.hasNext()) { 310 Map.Entry entry = (Map.Entry ) iter.next(); 311 DDBean portComponent = (DDBean ) entry.getKey(); 312 String linkName = getComponentLinkName(portComponent); 313 WebserviceEndpoint endpoint = (WebserviceEndpoint) entry.getValue(); 314 315 if(hasContent(endpoint)) { 317 boolean endpointAdded = false; 318 CommonDDBean [] hosts = helper.getEndpointHosts(root); 319 for(int i = 0; i < hosts.length; i++) { 320 String hostName = (String ) hosts[i].getValue(helper.getHostNameProperty()); 321 if(hostName != null && hostName.equals(linkName)) { 322 hosts[i].addValue(helper.getEndpointProperty(), endpoint.cloneVersion(version)); 323 endpointAdded = true; 324 break; 325 } 326 } 327 328 if(!endpointAdded) { 329 CommonDDBean newBean = helper.createNewHost(); 330 newBean.setValue(helper.getHostNameProperty(), linkName); 331 newBean.addValue(helper.getEndpointProperty(), endpoint.cloneVersion(version)); 332 helper.addEndpointHost(root, newBean); 333 } 334 } 335 } 336 337 return ddParent; 338 } 339 340 public String getPropertyName() { 341 return helper.getEndpointProperty(); 342 } 343 344 private boolean hasContent(WebserviceEndpoint endpoint) { 345 if(Utils.notEmpty(endpoint.getEndpointAddressUri())) { 346 return true; 347 } 348 349 if(Utils.notEmpty(endpoint.getTransportGuarantee())) { 350 return true; 351 } 352 353 if(endpoint.getLoginConfig() != null) { 354 return true; 355 } 356 357 try { 358 if(Utils.notEmpty(endpoint.getDebuggingEnabled())) { 359 return true; 360 } 361 } catch (VersionNotSupportedException ex) { 362 } 364 365 try { 366 if(endpoint.getMessageSecurityBinding() != null) { 367 return true; 368 } 369 } catch(VersionNotSupportedException ex) { 370 } 372 373 return false; 374 } 375 }; 376 377 snippets.add(snipOne); 378 snippets.add(snipTwo); 379 return snippets; 380 } 381 382 protected class WebServiceDescriptorFinder implements ConfigFinder { 383 384 private String wsDescName; 385 386 public WebServiceDescriptorFinder(String beanName) { 387 this.wsDescName = beanName; 388 } 389 390 public Object find(Object obj) { 391 Object result = null; 392 CommonDDBean root = (CommonDDBean) obj; 393 CommonDDBean [] descriptions = helper.getWebServiceDescriptions(root); 394 395 for(int i = 0; i < descriptions.length; i++) { 396 String name = (String ) descriptions[i].getValue(WebserviceDescription.WEBSERVICE_DESCRIPTION_NAME); 397 if(wsDescName.equals(name)) { 398 result = descriptions[i]; 399 break; 400 } 401 } 402 403 return result; 404 } 405 } 406 407 private class RootFinder implements ConfigFinder { 408 public Object find(Object obj) { 409 RootInterface result = null; 410 411 if(obj instanceof SunWebApp || obj instanceof SunEjbJar) { 412 result = (RootInterface) obj; 413 } 414 415 return result; 416 } 417 } 418 419 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 420 String uriText = getUriText(); 421 422 RootInterface root = (RootInterface) config.getBeans(uriText, 423 constructFileName(), getParser(), new RootFinder()); 424 425 WebserviceDescription descGraph = (WebserviceDescription) config.getBeans(uriText, 426 constructFileName(), getParser(), new WebServiceDescriptorFinder(getWebServiceDescriptionName())); 427 428 clearProperties(); 429 430 Map tmpEndpointMap = getEndpointMap(requiresDefaultEndpointUri); 432 433 if(descGraph != null) { 434 wsdlPublishLocation = descGraph.getWsdlPublishLocation(); 435 } 436 437 if(root != null) { 438 CommonDDBean [] hosts = helper.getEndpointHosts(root); 440 if(hosts != null) { 441 for(int i = 0; i < hosts.length; i++) { 442 String hostName = (String ) hosts[i].getValue(helper.getHostNameProperty()); 443 WebserviceEndpoint [] definedEndpoints = (WebserviceEndpoint []) hosts[i].getValues(helper.getEndpointProperty()); 444 445 for(int j = 0; j < definedEndpoints.length; j++) { 446 String portComponentName = definedEndpoints[j].getPortComponentName(); 447 DDBean key = findEndpointInMap(hostName, portComponentName, tmpEndpointMap); 448 if(key != null) { 449 tmpEndpointMap.remove(key); 451 webServiceEndpointMap.put(key, definedEndpoints[j].clone()); 452 453 ((WebServices) getParent()).removeEndpoint(hostName, portComponentName); 456 457 BaseRoot masterRoot = config.getMasterDCBRoot(); 460 masterRoot.removeCachedEndpoint(helper.getHostProperty(), helper.getHostNameProperty(), 461 hostName, helper.getEndpointProperty(), portComponentName); 462 } 463 } 464 } 465 } 466 } 467 468 if(tmpEndpointMap.size() > 0) { 474 Iterator iter = tmpEndpointMap.entrySet().iterator(); 476 while(iter.hasNext()) { 477 Map.Entry entry = (Map.Entry ) iter.next(); 478 webServiceEndpointMap.put(entry.getKey(), entry.getValue()); 479 } 480 481 if(requiresDefaultEndpointUri) { 487 config.getMasterDCBRoot().setDirty(); 488 } 489 } 490 491 494 return (descGraph != null || root != null); 495 } 496 497 502 private DDBean findEndpointInMap(String linkName, String portComponentName, Map endpointMap) { 503 DDBean key = null; 504 505 if(Utils.notEmpty(linkName) && Utils.notEmpty(portComponentName)) { 506 Iterator iter = endpointMap.entrySet().iterator(); 507 while(iter.hasNext()) { 508 Map.Entry entry = (Map.Entry ) iter.next(); 509 DDBean portComponent = (DDBean ) entry.getKey(); 510 511 if(portComponentName.equals(getPortComponentName(portComponent)) && 512 linkName.equals(getComponentLinkName(portComponent))) { 513 key = portComponent; 514 break; 515 } 516 } 517 } 518 519 return key; 520 } 521 522 525 private Map getEndpointMap(boolean requiresDefaultEndpointUri) { 526 HashMap endpointMap = new HashMap (); 527 528 DDBean [] portComponents = getDDBean().getChildBean("port-component"); for(int i = 0; i < portComponents.length; i++) { 531 String portComponentName = getPortComponentName(portComponents[i]); 532 WebserviceEndpoint endpoint = helper.createWebServiceEndpoint(getConfig().getStorageFactory()); 533 534 if(Utils.notEmpty(portComponentName)) { 535 endpoint.setPortComponentName(portComponentName); 536 if(requiresDefaultEndpointUri) { 538 endpoint.setEndpointAddressUri(helper.getUriPrefix() + portComponentName); 539 } 540 } 541 542 endpointMap.put(portComponents[i], endpoint); 543 } 544 545 return endpointMap; 546 } 547 548 private String getPortComponentName(DDBean portComponent) { 549 return getChildBeanText(portComponent, "port-component-name"); 550 } 551 552 private String getComponentLinkName(DDBean portComponent) { 553 return getChildBeanText(portComponent, "service-impl-bean/" + helper.getLinkXpath()); 554 } 555 556 protected String getChildBeanText(DDBean parent, String childXpath) { 557 String childText = null; 558 559 DDBean [] beans = parent.getChildBean(childXpath); 560 DDBean childDD = null; 561 if(beans.length >= 1) { 562 childDD = beans[0]; 564 } 565 566 if(childDD != null) { 567 childText = childDD.getText(); 568 if(childText != null) { 569 childText = childText.trim(); 570 } 571 } 572 573 return childText; 574 } 575 576 protected void clearProperties() { 577 wsdlPublishLocation = null; 578 webServiceEndpointMap = new HashMap (); 579 } 580 581 protected String constructFileName() { 582 return getParent().constructFileName(); 584 } 585 586 589 590 595 public void notifyDDChange(XpathEvent xpathEvent) { 596 super.notifyDDChange(xpathEvent); 597 599 DDBean eventBean = xpathEvent.getBean(); 600 String xpath = eventBean.getXpath(); 601 602 if(eventBean == webServiceDescriptionNameDD) { 603 getPCS().firePropertyChange(WEBSERVICE_DESCRIPTION_NAME, GenericOldValue, getWebServiceDescriptionName()); 605 getPCS().firePropertyChange(DISPLAY_NAME, GenericOldValue, getDisplayName()); 606 607 updateNamedBeanCache(SunWebApp.WEBSERVICE_DESCRIPTION); 608 } else if(xpath.endsWith("port-component-name")) { 609 DDBean [] parents = eventBean.getChildBean(".."); 611 if(parents != null && parents.length == 1) { 612 WebserviceEndpoint endpoint = (WebserviceEndpoint) webServiceEndpointMap.get(parents[0]); 613 if(endpoint != null) { 614 updateEndpoint(endpoint, eventBean); 615 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, GenericOldValue, parents[0]); 616 } 617 } 618 } else if(xpath.endsWith(helper.getLinkXpath())) { 619 DDBean [] parents = eventBean.getChildBean("../.."); 620 if(parents != null && parents.length == 1) { 621 if(webServiceEndpointMap.get(parents[0]) != null) { 622 getPCS().firePropertyChange(COMPONENT_LINK_NAME, GenericOldValue, parents[0]); 623 } 624 } 625 } 626 } 627 628 private void updateEndpoint(WebserviceEndpoint endpoint, DDBean portComponentNameDD) { 629 String oldPortComponentName = endpoint.getPortComponentName(); 630 String newPortComponentName = portComponentNameDD.getText(); 631 if(newPortComponentName != null) { 632 newPortComponentName = newPortComponentName.trim(); 633 } 634 635 endpoint.setPortComponentName(newPortComponentName); 636 637 if(requiresDefaultEndpointUri) { 638 String oldEndpointUri = endpoint.getEndpointAddressUri(); 639 if((oldPortComponentName != null && oldPortComponentName.equals(oldEndpointUri)) || 640 (oldPortComponentName == null && oldEndpointUri == null)) { 641 endpoint.setEndpointAddressUri(newPortComponentName); 642 } 643 } 644 } 645 646 649 public void fireXpathEvent(XpathEvent xpathEvent) { 650 super.fireXpathEvent(xpathEvent); 651 653 DDBean eventBean = xpathEvent.getBean(); 654 String xpath = eventBean.getXpath(); 655 656 if(xpath.endsWith("port-component")) { 657 if(xpathEvent.isAddEvent()) { 658 try { 659 addWebServiceEndpoint(eventBean, true); 660 } catch(java.beans.PropertyVetoException ex) { 661 } 663 } else if(xpathEvent.isRemoveEvent()) { 664 try { 665 removeWebServiceEndpoint(eventBean); 666 } catch(java.beans.PropertyVetoException ex) { 667 } 669 } 670 } else if(xpath.endsWith("port-component-name")) { 671 DDBean [] parents = eventBean.getChildBean(".."); 672 if(parents != null && parents.length == 1) { 673 WebserviceEndpoint endpoint = (WebserviceEndpoint) webServiceEndpointMap.get(parents[0]); 674 if(endpoint != null) { 675 if(xpathEvent.isAddEvent()) { 676 updateEndpoint(endpoint, eventBean); 677 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, GenericOldValue, parents[0]); 678 } else if(xpathEvent.isRemoveEvent()) { 679 endpoint.setPortComponentName(""); 680 endpoint.setEndpointAddressUri(""); 681 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, GenericOldValue, parents[0]); 682 } 683 } 684 } 685 } 686 } 687 688 691 692 695 public String getWsdlPublishLocation() { 696 return this.wsdlPublishLocation; 697 } 698 699 704 public void setWsdlPublishLocation(String newWsdlPublishLocation) throws java.beans.PropertyVetoException { 705 String oldWsdlPublishLocation = this.wsdlPublishLocation; 706 getVCS().fireVetoableChange("wsdlPublishLocation", oldWsdlPublishLocation, newWsdlPublishLocation); 707 this.wsdlPublishLocation = newWsdlPublishLocation; 708 getPCS().firePropertyChange("wsdlPublishLocation", oldWsdlPublishLocation, wsdlPublishLocation); 709 } 710 711 715 public List getWebServiceEndpoints() { 716 List result = new ArrayList (webServiceEndpointMap.size()); 717 Iterator iter = webServiceEndpointMap.entrySet().iterator(); 718 while(iter.hasNext()) { 719 Map.Entry entry = (Map.Entry ) iter.next(); 720 result.add(entry.getValue()); 721 } 722 return result; 723 } 724 725 public WebserviceEndpoint getWebServiceEndpoint(int index) { 726 List endpoints = getWebServiceEndpoints(); 727 return (WebserviceEndpoint) endpoints.get(index); 728 } 729 730 public WebserviceEndpoint getWebServiceEndpoint(String portName) { 731 WebserviceEndpoint result = null; 732 DDBean key = createKey(portName); 733 if(key != null) { 734 result = (WebserviceEndpoint) webServiceEndpointMap.get(key); 735 } 736 return result; 737 } 738 739 745 public void setWebServiceEndpoints(List newWebServiceEndpoints) throws java.beans.PropertyVetoException { 746 Map oldWebServiceEndpointMap = webServiceEndpointMap; 747 getVCS().fireVetoableChange("webServiceEndpointMap", oldWebServiceEndpointMap, newWebServiceEndpoints); webServiceEndpointMap = new HashMap (); 749 if(newWebServiceEndpoints != null) { 750 Iterator iter = newWebServiceEndpoints.iterator(); 751 while(iter.hasNext()) { 752 WebserviceEndpoint endpoint = (WebserviceEndpoint) iter.next(); 753 if(endpoint != null) { 754 DDBean key = createKey(endpoint.getPortComponentName()); 755 if(key != null) { 756 webServiceEndpointMap.put(key, endpoint); 757 } 758 } 759 } 760 } 761 getPCS().firePropertyChange("webServiceEndpointMap", oldWebServiceEndpointMap, webServiceEndpointMap); } 763 764 public void addWebServiceEndpoint(WebserviceEndpoint newWebServiceEndpoint) throws java.beans.PropertyVetoException { 765 getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, null, newWebServiceEndpoint); 766 if(webServiceEndpointMap == null) { 767 webServiceEndpointMap = new HashMap (); 768 } 769 DDBean key = createKey(newWebServiceEndpoint.getPortComponentName()); 770 if(key != null) { 771 webServiceEndpointMap.put(key, newWebServiceEndpoint); 772 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, null, newWebServiceEndpoint ); 773 } 774 } 775 776 public void removeWebServiceEndpoint(WebserviceEndpoint oldWebServiceEndpoint) throws java.beans.PropertyVetoException { 777 getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, oldWebServiceEndpoint, null); 778 DDBean key = createKey(oldWebServiceEndpoint.getPortComponentName()); 779 if(key != null && webServiceEndpointMap.get(key) != null) { 780 webServiceEndpointMap.remove(key); 781 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, oldWebServiceEndpoint, null ); 782 } 783 } 784 785 public void addWebServiceEndpoint(DDBean portComponentDD, boolean load) throws java.beans.PropertyVetoException { 786 WebserviceEndpoint newWebserviceEndpoint = helper.createWebServiceEndpoint(getConfig().getStorageFactory()); 787 String portComponentName = getChildBeanText(portComponentDD, "port-component-name"); newWebserviceEndpoint.setPortComponentName(portComponentName); 789 790 if(load) { 792 Base parent = getParent(); 793 if(parent instanceof WebServices) { 794 WebServices wsParent = (WebServices) parent; 795 String linkName = getChildBeanText(portComponentDD, "service-impl-bean/" + helper.getLinkXpath()); 796 WebserviceEndpoint savedEndpoint = wsParent.removeEndpoint(linkName, portComponentName); 797 798 if(savedEndpoint != null) { 800 newWebserviceEndpoint = (WebserviceEndpoint) savedEndpoint.clone(); 801 } else { 802 load = false; 804 } 805 806 BaseRoot masterRoot = getConfig().getMasterDCBRoot(); 809 masterRoot.removeCachedEndpoint(helper.getHostProperty(), helper.getHostNameProperty(), 810 linkName, helper.getEndpointProperty(), portComponentName); 811 } 812 } 813 814 if(!load && requiresDefaultEndpointUri) { 816 newWebserviceEndpoint.setEndpointAddressUri(portComponentName); 817 getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, null, newWebserviceEndpoint); 818 } 819 820 if(webServiceEndpointMap == null) { 821 webServiceEndpointMap = new HashMap (); 822 } 823 webServiceEndpointMap.put(portComponentDD, newWebserviceEndpoint); 824 825 if(!load && requiresDefaultEndpointUri) { 826 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, null, newWebserviceEndpoint); 827 } 828 } 829 830 public void removeWebServiceEndpoint(DDBean portComponentDD) throws java.beans.PropertyVetoException { 831 WebserviceEndpoint oldWebserviceEndpoint = (WebserviceEndpoint) webServiceEndpointMap.get(portComponentDD); 832 if(oldWebserviceEndpoint != null) { 833 getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, oldWebserviceEndpoint, null); 834 webServiceEndpointMap.remove(portComponentDD); 835 getPCS().firePropertyChange(WEBSERVICE_ENDPOINT, oldWebserviceEndpoint, null ); 836 } 837 } 838 839 844 public void setMessageSecurityBinding(String portName, MessageSecurityBinding newBinding) throws java.beans.PropertyVetoException , VersionNotSupportedException { 845 WebserviceEndpoint endpoint = getWebServiceEndpoint(portName); 846 if(endpoint != null) { 847 MessageSecurityBinding oldBinding = endpoint.getMessageSecurityBinding(); 848 getVCS().fireVetoableChange(ENDPOINT_SECURITY_BINDING, oldBinding, newBinding); 849 endpoint.setMessageSecurityBinding((newBinding != null) ? (MessageSecurityBinding) newBinding.clone() : null); 850 getPCS().firePropertyChange(ENDPOINT_SECURITY_BINDING, oldBinding, newBinding); 851 } else { 852 throw new IllegalArgumentException (MessageFormat.format(bundle.getString("ERR_InvalidPortName"), new Object [] { portName })); 853 } 854 } 855 856 863 private DDBean createKey(String targetPortComponentName) { 864 DDBean key = null; 865 DDBean [] portComponentBeans = getDDBean().getChildBean("port-component"); for(int i = 0; i < portComponentBeans.length; i++) { 867 String portComponentName = getPortComponentName(portComponentBeans[i]); 868 if(Utils.notEmpty(portComponentName) && portComponentName.equals(targetPortComponentName)) { 869 key = portComponentBeans[i]; 870 break; 871 } 872 } 873 874 return key; 875 } 876 877 878 private static final String WEB_URI_PREFIX = ""; private static final String EJB_URI_PREFIX = "webservice/"; 881 private final EndpointHelper servletHelper = new ServletHelper(); 882 private final EndpointHelper ejbHelper = new EjbHelper(); 883 884 private abstract class EndpointHelper { 885 886 private final String linkXpath; 887 private final String hostProperty; 888 private final String hostNameProperty; 889 private final String endpointProperty; 890 private final String blueprintsUriPrefix; 891 892 public EndpointHelper(String xpath, String hp, String hnp, String epp, String uriPrefix) { 893 linkXpath = xpath; 894 hostProperty = hp; 895 hostNameProperty = hnp; 896 endpointProperty = epp; 897 blueprintsUriPrefix = uriPrefix; 898 } 899 900 public String getLinkXpath() { 901 return linkXpath; 902 } 903 904 private String getHostProperty() { 905 return hostProperty; 906 } 907 908 public String getHostNameProperty() { 909 return hostNameProperty; 910 } 911 912 public String getEndpointProperty() { 913 return endpointProperty; 914 } 915 916 public String getUriPrefix() { 917 return blueprintsUriPrefix; 918 } 919 920 public abstract CommonDDBean [] getWebServiceDescriptions(CommonDDBean ddParent); 921 922 public abstract void addWebServiceDescription(CommonDDBean ddParent, CommonDDBean wsDescBean); 923 924 public abstract WebserviceEndpoint createWebServiceEndpoint(StorageBeanFactory factory); 925 926 public abstract CommonDDBean [] getEndpointHosts(RootInterface root); 927 928 public abstract void addEndpointHost(RootInterface root, CommonDDBean bean); 929 930 public abstract CommonDDBean createNewHost(); 931 } 932 933 private class ServletHelper extends EndpointHelper { 934 public ServletHelper() { 935 super("servlet-link", SunWebApp.SERVLET, Servlet.SERVLET_NAME, Servlet.WEBSERVICE_ENDPOINT, WEB_URI_PREFIX); 936 } 937 938 public CommonDDBean [] getWebServiceDescriptions(CommonDDBean ddParent) { 939 CommonDDBean [] result = (CommonDDBean []) ddParent.getValues(SunWebApp.WEBSERVICE_DESCRIPTION); 940 return result; 941 } 942 943 public void addWebServiceDescription(CommonDDBean ddParent, CommonDDBean wsDescBean) { 944 ddParent.addValue(SunWebApp.WEBSERVICE_DESCRIPTION, wsDescBean); 945 } 946 947 public WebserviceEndpoint createWebServiceEndpoint(StorageBeanFactory factory) { 948 return factory.createWebHostedWebserviceEndpoint(); 949 } 950 951 public CommonDDBean [] getEndpointHosts(RootInterface root) { 952 CommonDDBean [] result = (CommonDDBean []) root.getValues(SunWebApp.SERVLET); 953 return result; 954 } 955 956 public void addEndpointHost(RootInterface root, CommonDDBean bean) { 957 root.addValue(SunWebApp.SERVLET, bean); 958 } 959 960 public CommonDDBean createNewHost() { 961 return getConfig().getStorageFactory().createServlet(); 962 } 963 } 964 965 private class EjbHelper extends EndpointHelper { 966 public EjbHelper() { 967 super("ejb-link", EnterpriseBeans.EJB, Ejb.EJB_NAME, Ejb.WEBSERVICE_ENDPOINT, EJB_URI_PREFIX); 968 } 969 970 public CommonDDBean [] getWebServiceDescriptions(CommonDDBean ddParent) { 971 CommonDDBean [] result = null; 972 CommonDDBean enterpriseBeans = (CommonDDBean) ddParent.getValue(SunEjbJar.ENTERPRISE_BEANS); 973 if(enterpriseBeans != null) { 974 result = (CommonDDBean []) enterpriseBeans.getValues(EnterpriseBeans.WEBSERVICE_DESCRIPTION); 975 } 976 return result; 977 } 978 979 public void addWebServiceDescription(CommonDDBean ddParent, CommonDDBean wsDescBean) { 980 CommonDDBean enterpriseBeans = getEnterpriseBeans(ddParent); 981 enterpriseBeans.addValue(EnterpriseBeans.WEBSERVICE_DESCRIPTION, wsDescBean); 982 } 983 984 public WebserviceEndpoint createWebServiceEndpoint(StorageBeanFactory factory) { 985 return factory.createEjbHostedWebserviceEndpoint(); 986 } 987 988 public CommonDDBean [] getEndpointHosts(RootInterface root) { 989 CommonDDBean [] result = null; 990 CommonDDBean enterpriseBeans = (CommonDDBean) root.getValue(SunEjbJar.ENTERPRISE_BEANS); 991 if(enterpriseBeans != null) { 992 result = (CommonDDBean []) enterpriseBeans.getValues(EnterpriseBeans.EJB); 993 } 994 return result; 995 } 996 997 public void addEndpointHost(RootInterface root, CommonDDBean bean) { 998 CommonDDBean enterpriseBeans = getEnterpriseBeans(root); 999 enterpriseBeans.addValue(EnterpriseBeans.EJB, bean); 1000 } 1001 1002 public CommonDDBean createNewHost() { 1003 return getConfig().getStorageFactory().createEjb(); 1004 } 1005 1006 private CommonDDBean getEnterpriseBeans(CommonDDBean ddParent) { 1007 assert ddParent instanceof SunEjbJar; 1008 CommonDDBean enterpriseBeans = (CommonDDBean) ddParent.getValue(SunEjbJar.ENTERPRISE_BEANS); 1009 if(enterpriseBeans == null) { 1010 enterpriseBeans = getConfig().getStorageFactory().createEnterpriseBeans(); 1011 ddParent.addValue(SunEjbJar.ENTERPRISE_BEANS, enterpriseBeans); 1012 } 1013 return enterpriseBeans; 1014 } 1015 } 1016} 1017 | Popular Tags |