KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > WebServiceDescriptor


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 package org.netbeans.modules.j2ee.sun.share.configbean;
20
21 import java.beans.PropertyVetoException JavaDoc;
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
32 import javax.enterprise.deploy.model.DDBean JavaDoc;
33 import javax.enterprise.deploy.model.XpathEvent JavaDoc;
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 /** This DConfigBean is a child of WebServices.
50  *
51  * Property structures from sun-web-app.xml or sun-ejb-jar.xml handled by this bean
52  *
53  * webservice-description : WebserviceDescription
54  * webservice-description-name : String
55  * wsdl-publish-location : String?
56  * webserviceEndpoint <webservice-endpoint> : WebserviceEndpoint[0,n]
57  * portComponentName <port-component-name> : String
58  * endpointAddressUri <endpoint-address-uri> : String[0,1]
59  * (
60  * | loginConfig <login-config> : LoginConfig
61  * | authMethod <auth-method> : String
62  * // *** EJB JAR version has realm field.
63  * | realm <realm> : String[0,1]
64  * |
65  * | messageSecurityBinding <message-security-binding> : MessageSecurityBinding
66  * | [attr: auth-layer ENUM #REQUIRED ( SOAP ) ]
67  * | [attr: provider-id CDATA #IMPLIED ]
68  * | messageSecurity <message-security> : MessageSecurity[0,n]
69  * | message <message> : Message[1,n]
70  * | | javaMethod <java-method> : JavaMethod[0,1]
71  * | | methodName <method-name> : String
72  * | | methodParams <method-params> : MethodParams[0,1]
73  * | | methodParam <method-param> : String[0,n]
74  * | | operationName <operation-name> : String[0,1]
75  * | requestProtection <request-protection> : boolean[0,1]
76  * | [attr: auth-source ENUM #IMPLIED ( sender content ) ]
77  * | [attr: auth-recipient ENUM #IMPLIED ( before-content after-content ) ]
78  * | EMPTY : String
79  * | responseProtection <response-protection> : boolean[0,1]
80  * | [attr: auth-source ENUM #IMPLIED ( sender content ) ]
81  * | [attr: auth-recipient ENUM #IMPLIED ( before-content after-content ) ]
82  * | EMPTY : String
83  * )[0,1]
84  * transportGuarantee <transport-guarantee> : String[0,1]
85  * serviceQname <service-qname> : ServiceQname[0,1] [not used - set by server]
86  * namespaceURI <namespaceURI> : String [not used - set by server]
87  * localpart <localpart> : String [not used - set by server]
88  * tieClass <tie-class> : String[0,1] [not used - set by server]
89  * servletImplClass <servlet-impl-class> : String[0,1] [not used - set by server]
90  * debuggingEnabled <debugging-enabled> : String[0,1]
91  *
92  * // *** WEB APPLICATION version of property field
93  * webProperty <property> : WebProperty[0,n]
94  * [attr: name CDATA #REQUIRED ]
95  * [attr: value CDATA #REQUIRED ]
96  * description <description> : String[0,1]
97  *
98  * // *** EJB JAR version of property field
99  * propertyElement <property> : PropertyElement[0,n]
100  * name <name> : String
101  * value <value> : String
102  *
103  * @author Peter Williams
104  */

105 public class WebServiceDescriptor extends Base {
106
107     /** property event names
108      */

109     public static final String JavaDoc WEBSERVICE_DESCRIPTION_NAME = "webserviceDescriptionName"; // NOI18N
110
public static final String JavaDoc WEBSERVICE_ENDPOINT = "webserviceEndpoint"; // NOI18N
111
public static final String JavaDoc ENDPOINT_SECURITY_BINDING = "endpointSecurityBinding"; // NOI18N
112
public static final String JavaDoc COMPONENT_LINK_NAME = "componentLinkName"; // NOI18N
113

114
115     /** DDBean that refers to "webservice-description-name" child of bound DDBean. */
116     private DDBean JavaDoc webServiceDescriptionNameDD;
117
118     /** Holds value of property wsdlPublishLocation. */
119     private String JavaDoc wsdlPublishLocation;
120
121     /** Hold a map of DDBean [portComponent] -> web service endpoints. */
122     private Map JavaDoc webServiceEndpointMap;
123
124     /** Differentiates Servlet vs Ejb webservice support */
125     private EndpointHelper helper;
126
127     /** EJB modules for J2EE 1.4 and earlier require this field. This boolean
128       * controls whether we provide a default value and keep it up to date as needed.
129       */

130     private boolean requiresDefaultEndpointUri;
131     
132     /** Creates a new instance of WebServiceDescriptor */
133     public WebServiceDescriptor() {
134         setDescriptorElement(bundle.getString("BDN_WebServiceDescriptor")); // NOI18N
135
}
136
137     /** Override init to enable grouping support for this bean and load name
138      * field from related DDBean.
139      * @param dDBean DDBean matching this bean
140      * @param parent Parent DConfigBean in the tree
141      */

142     protected void init(DDBean JavaDoc dDBean, Base parent) throws ConfigurationException JavaDoc {
143         super.init(dDBean, parent);
144
145 // !PW Disable grouping code for now, spec non-compliance.
146
// initGroup(dDBean, parent);
147

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 JavaDoc("Unexpected master DConfigBean type: " + masterRoot); // NOI18N
157
}
158         
159         dDBean.addXpathListener(dDBean.getXpath(), this);
160         webServiceDescriptionNameDD = getNameDD("webservice-description-name"); // NOI18N
161

162         updateNamedBeanCache(SunWebApp.WEBSERVICE_DESCRIPTION);
163
164         loadFromPlanFile(getConfig());
165     }
166
167     protected String JavaDoc getComponentName() {
168         return getWebServiceDescriptionName();
169     }
170     
171     /** -----------------------------------------------------------------------
172      * Validation implementation
173      */

174     
175     // relative xpaths (double as field id's)
176
public static final String JavaDoc 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 JavaDoc fieldId) {
184         ValidationError error = null;
185         
186         // !PW use visitor pattern to get rid of switch/if statement for validation
187
// field -- data member mapping.
188
//
189
if(fieldId.equals(FIELD_WSDL_PUBLISH_LOCATION)) {
190             String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
191             
192             if(Utils.notEmpty(wsdlPublishLocation)) {
193                 try {
194                     URL JavaDoc testUrl = new URL JavaDoc(wsdlPublishLocation);
195                 } catch(MalformedURLException JavaDoc ex) {
196                     Object JavaDoc [] args = new Object JavaDoc[1];
197                     args[0] = wsdlPublishLocation; // NOI18N
198
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_InvalidUrl"), args); // NOI18N
199
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 true if there was no error added
213
return (error == null || !Utils.notEmpty(error.getMessage()));
214     }
215     
216     /** Getter for helpId property
217      * @return Help context ID for this DConfigBean
218      */

219     public String JavaDoc getHelpId() {
220         return "AS_CFG_WebServiceDescriptor";
221     }
222
223     /** Getter for property webservice-description-name.
224      * @return Value of property webservice-description-name.
225      *
226      */

227     public String JavaDoc getWebServiceDescriptionName() {
228         return cleanDDBeanText(webServiceDescriptionNameDD);
229     }
230     
231     /** For the customizer to determine the host type of the endpoint.
232      */

233     public boolean isWarModule() {
234         // FIXME need a better implementation but this will do for now.
235
return helper instanceof ServletHelper;
236     }
237     
238     public boolean isEjbModule() {
239         // FIXME need a better implementation but this will do for now.
240
return helper instanceof EjbHelper;
241     }
242
243     /* ------------------------------------------------------------------------
244      * Persistence support. Loads DConfigBeans from previously saved Deployment
245      * plan file.
246      */

247     Collection JavaDoc getSnippets() {
248         Collection JavaDoc snippets = new ArrayList JavaDoc();
249
250         Snippet snipOne = new DefaultSnippet() {
251             public CommonDDBean getDDSnippet() {
252                 // Add web service description entry.
253
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 JavaDoc 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                 // The contract for getDDSnippet() is to NEVER return null. In this
286
// instance however, a true snippet is not created. Instead, the
287
// implementation of mergeIntoRovingDD() inserts the various endpoint
288
// fragments into the correct places directly. In fact, it is quite
289
// possible this method is never called. The result certainly should
290
// never be used.
291
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                 // For each endpoint, locate the host (servlet or ejb) it is bound
304
// to and add it to that host's endpoint table.
305
RootInterface root = (RootInterface) ddParent;
306                 String JavaDoc version = root.getVersion().toString();
307                 Iterator JavaDoc iter = webServiceEndpointMap.entrySet().iterator();
308
309                 while(iter.hasNext()) {
310                     Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
311                     DDBean JavaDoc portComponent = (DDBean JavaDoc) entry.getKey();
312                     String JavaDoc linkName = getComponentLinkName(portComponent);
313                     WebserviceEndpoint endpoint = (WebserviceEndpoint) entry.getValue();
314
315                     // We only add the endpoint data if there is something to save.
316
if(hasContent(endpoint)) {
317                         boolean endpointAdded = false;
318                         CommonDDBean [] hosts = helper.getEndpointHosts(root);
319                         for(int i = 0; i < hosts.length; i++) {
320                             String JavaDoc hostName = (String JavaDoc) 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 JavaDoc 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                     // ignore.
363
}
364                 
365                 try {
366                     if(endpoint.getMessageSecurityBinding() != null) {
367                         return true;
368                     }
369                 } catch(VersionNotSupportedException ex) {
370                     // ignore.
371
}
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 JavaDoc wsDescName;
385
386         public WebServiceDescriptorFinder(String JavaDoc beanName) {
387             this.wsDescName = beanName;
388         }
389
390         public Object JavaDoc find(Object JavaDoc obj) {
391             Object JavaDoc 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 JavaDoc name = (String JavaDoc) 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 JavaDoc find(Object JavaDoc 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 JavaDoc 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         // Default endpoint URI's are set in this call.
431
Map JavaDoc tmpEndpointMap = getEndpointMap(requiresDefaultEndpointUri);
432
433         if(descGraph != null) {
434             wsdlPublishLocation = descGraph.getWsdlPublishLocation();
435         }
436
437         if(root != null) {
438             // Load all endpoints that already have defined values.
439
CommonDDBean [] hosts = helper.getEndpointHosts(root);
440             if(hosts != null) {
441                 for(int i = 0; i < hosts.length; i++) {
442                     String JavaDoc hostName = (String JavaDoc) 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 JavaDoc portComponentName = definedEndpoints[j].getPortComponentName();
447                         DDBean JavaDoc key = findEndpointInMap(hostName, portComponentName, tmpEndpointMap);
448                         if(key != null) {
449                             // This end point is still valid and has data that has been previously saved.
450
tmpEndpointMap.remove(key);
451                             webServiceEndpointMap.put(key, definedEndpoints[j].clone());
452                             
453                             // Remove this endpoint from the saved endpoint list managed by
454
// the WebServices root DConfigBean.
455
((WebServices) getParent()).removeEndpoint(hostName, portComponentName);
456                             
457                             // If the host data is still cached, remove this endpoint from the cache entry
458
// for the host so that it is not saved twice if modified. See IZ 94865
459
BaseRoot masterRoot = config.getMasterDCBRoot();
460                             masterRoot.removeCachedEndpoint(helper.getHostProperty(), helper.getHostNameProperty(),
461                                     hostName, helper.getEndpointProperty(), portComponentName);
462                         }
463                     }
464                 }
465             }
466         }
467
468         // This is section is the equivalent of setDefaultProperties() in other
469
// DConfigBean implementations.
470
// Default URI's for any new, or otherwise undefined endpoints were initially
471
// set above in getEndpointMap() and are transferred to the storage map here.
472
//
473
if(tmpEndpointMap.size() > 0) {
474             // handle defaults for the remaining tmp endpoints.
475
Iterator JavaDoc iter = tmpEndpointMap.entrySet().iterator();
476             while(iter.hasNext()) {
477                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
478                 webServiceEndpointMap.put(entry.getKey(), entry.getValue());
479             }
480             
481             // Mark master DConfigBean as dirty so we force a save of the new default
482
// values, if any were generated. We can't simply mark this bean dirty
483
// because it is still being constructed and doesn't have any listeners
484
// attached yet.
485
//
486
if(requiresDefaultEndpointUri) {
487                 config.getMasterDCBRoot().setDirty();
488             }
489         }
490         
491         // Do we want to do anything special for default values, or simply fill in
492
// the entries + port component name all the time?
493

494         return (descGraph != null || root != null);
495     }
496
497     /** Finds the first endpoint in the map, if any, with the given port name
498      * and servlet-link or ejb-link and returns the key that will allow this
499      * entry to be retrieved. If this proves to be a performance bottleneck,
500      * we may have to have an additional index into the map.
501      */

502     private DDBean JavaDoc findEndpointInMap(String JavaDoc linkName, String JavaDoc portComponentName, Map JavaDoc endpointMap) {
503         DDBean JavaDoc key = null;
504
505         if(Utils.notEmpty(linkName) && Utils.notEmpty(portComponentName)) {
506             Iterator JavaDoc iter = endpointMap.entrySet().iterator();
507             while(iter.hasNext()) {
508                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
509                 DDBean JavaDoc portComponent = (DDBean JavaDoc) 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     /** Returns a map between servlet/port pairs and endpoints, with the port
523      * name in each endpoint pre-filled.
524      */

525     private Map JavaDoc getEndpointMap(boolean requiresDefaultEndpointUri) {
526         HashMap JavaDoc endpointMap = new HashMap JavaDoc();
527
528         // The list of ports in this service
529
DDBean JavaDoc [] portComponents = getDDBean().getChildBean("port-component"); // NOI18N
530
for(int i = 0; i < portComponents.length; i++) {
531             String JavaDoc portComponentName = getPortComponentName(portComponents[i]);
532             WebserviceEndpoint endpoint = helper.createWebServiceEndpoint(getConfig().getStorageFactory());
533
534             if(Utils.notEmpty(portComponentName)) {
535                 endpoint.setPortComponentName(portComponentName);
536                 // This where default endpoints get set, if required for this service & module type
537
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 JavaDoc getPortComponentName(DDBean JavaDoc portComponent) {
549         return getChildBeanText(portComponent, "port-component-name");
550     }
551
552     private String JavaDoc getComponentLinkName(DDBean JavaDoc portComponent) {
553         return getChildBeanText(portComponent, "service-impl-bean/" + helper.getLinkXpath());
554     }
555
556     protected String JavaDoc getChildBeanText(DDBean JavaDoc parent, String JavaDoc childXpath) {
557         String JavaDoc childText = null;
558
559         DDBean JavaDoc[] beans = parent.getChildBean(childXpath);
560         DDBean JavaDoc childDD = null;
561         if(beans.length >= 1) {
562             // Found the DDBean we want.
563
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 JavaDoc();
579     }
580
581     protected String JavaDoc constructFileName() {
582         // Delegate to parent, which in turn delegates to master DCB root.
583
return getParent().constructFileName();
584     }
585
586     /* ------------------------------------------------------------------------
587      * Event handling support
588      */

589
590     /** The DDBean (or one of it's children) that this DConfigBean is bound to
591      * has changed.
592      *
593      * @param xpathEvent
594      */

595     public void notifyDDChange(XpathEvent JavaDoc xpathEvent) {
596         super.notifyDDChange(xpathEvent);
597 // dumpNotification("notifyDDChange", xpathEvent);
598

599         DDBean JavaDoc eventBean = xpathEvent.getBean();
600         String JavaDoc xpath = eventBean.getXpath();
601
602         if(eventBean == webServiceDescriptionNameDD) {
603             // name changed...
604
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             // port-component-name changed
610
DDBean JavaDoc [] 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 JavaDoc [] 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 JavaDoc portComponentNameDD) {
629         String JavaDoc oldPortComponentName = endpoint.getPortComponentName();
630         String JavaDoc newPortComponentName = portComponentNameDD.getText();
631         if(newPortComponentName != null) {
632             newPortComponentName = newPortComponentName.trim();
633         }
634
635         endpoint.setPortComponentName(newPortComponentName);
636
637         if(requiresDefaultEndpointUri) {
638             String JavaDoc oldEndpointUri = endpoint.getEndpointAddressUri();
639             if((oldPortComponentName != null && oldPortComponentName.equals(oldEndpointUri)) ||
640                     (oldPortComponentName == null && oldEndpointUri == null)) {
641                 endpoint.setEndpointAddressUri(newPortComponentName);
642             }
643         }
644     }
645
646     /** A DDBean has been added or removed (or changed, but we handle change events
647      * in notifyDDChange()).
648      */

649     public void fireXpathEvent(XpathEvent JavaDoc xpathEvent) {
650         super.fireXpathEvent(xpathEvent);
651 // dumpNotification("fireXpathEvent", xpathEvent);
652

653         DDBean JavaDoc eventBean = xpathEvent.getBean();
654         String JavaDoc 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 JavaDoc ex) {
661                     // suppress for now.
662
}
663             } else if(xpathEvent.isRemoveEvent()) {
664                 try {
665                     removeWebServiceEndpoint(eventBean);
666                 } catch(java.beans.PropertyVetoException JavaDoc ex) {
667                     // suppress for now.
668
}
669             }
670         } else if(xpath.endsWith("port-component-name")) {
671             DDBean JavaDoc [] 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     /* ------------------------------------------------------------------------
689      * Property support
690      */

691
692     /** Getter for property wsdlPublishLocation.
693      * @return Value of property wsdlPublishLocation.
694      */

695     public String JavaDoc getWsdlPublishLocation() {
696         return this.wsdlPublishLocation;
697     }
698
699     /** Setter for property wsdlPublishLocation.
700      * @param newWsdlPublishLocation New value of property wsdlPublishLocation.
701      *
702      * @throws PropertyVetoException
703      */

704     public void setWsdlPublishLocation(String JavaDoc newWsdlPublishLocation) throws java.beans.PropertyVetoException JavaDoc {
705         String JavaDoc oldWsdlPublishLocation = this.wsdlPublishLocation;
706         getVCS().fireVetoableChange("wsdlPublishLocation", oldWsdlPublishLocation, newWsdlPublishLocation);
707         this.wsdlPublishLocation = newWsdlPublishLocation;
708         getPCS().firePropertyChange("wsdlPublishLocation", oldWsdlPublishLocation, wsdlPublishLocation);
709     }
710
711     /** Getter for property webServiceEndpoint.
712      * @return Value of property webServiceEndpoint.
713      *
714      */

715     public List JavaDoc getWebServiceEndpoints() {
716         List JavaDoc result = new ArrayList JavaDoc(webServiceEndpointMap.size());
717         Iterator JavaDoc iter = webServiceEndpointMap.entrySet().iterator();
718         while(iter.hasNext()) {
719             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
720             result.add(entry.getValue());
721         }
722         return result;
723     }
724
725     public WebserviceEndpoint getWebServiceEndpoint(int index) {
726         List JavaDoc endpoints = getWebServiceEndpoints();
727         return (WebserviceEndpoint) endpoints.get(index);
728     }
729
730     public WebserviceEndpoint getWebServiceEndpoint(String JavaDoc portName) {
731         WebserviceEndpoint result = null;
732         DDBean JavaDoc key = createKey(portName);
733         if(key != null) {
734             result = (WebserviceEndpoint) webServiceEndpointMap.get(key);
735         }
736         return result;
737     }
738
739     /** Setter for property webServiceEndpoint.
740      * @param webServiceEndpoint New value of property webServiceEndpoint.
741      *
742      * @throws PropertyVetoException
743      *
744      */

745     public void setWebServiceEndpoints(List JavaDoc newWebServiceEndpoints) throws java.beans.PropertyVetoException JavaDoc {
746         Map JavaDoc oldWebServiceEndpointMap = webServiceEndpointMap;
747         getVCS().fireVetoableChange("webServiceEndpointMap", oldWebServiceEndpointMap, newWebServiceEndpoints); // NOI18N
748
webServiceEndpointMap = new HashMap JavaDoc();
749         if(newWebServiceEndpoints != null) {
750             Iterator JavaDoc iter = newWebServiceEndpoints.iterator();
751             while(iter.hasNext()) {
752                 WebserviceEndpoint endpoint = (WebserviceEndpoint) iter.next();
753                 if(endpoint != null) {
754                     DDBean JavaDoc key = createKey(endpoint.getPortComponentName());
755                     if(key != null) {
756                         webServiceEndpointMap.put(key, endpoint);
757                     }
758                 }
759             }
760         }
761         getPCS().firePropertyChange("webServiceEndpointMap", oldWebServiceEndpointMap, webServiceEndpointMap); // NOI18N
762
}
763
764     public void addWebServiceEndpoint(WebserviceEndpoint newWebServiceEndpoint) throws java.beans.PropertyVetoException JavaDoc {
765         getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, null, newWebServiceEndpoint);
766         if(webServiceEndpointMap == null) {
767             webServiceEndpointMap = new HashMap JavaDoc();
768         }
769         DDBean JavaDoc 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 JavaDoc {
777         getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, oldWebServiceEndpoint, null);
778         DDBean JavaDoc 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 JavaDoc portComponentDD, boolean load) throws java.beans.PropertyVetoException JavaDoc {
786         WebserviceEndpoint newWebserviceEndpoint = helper.createWebServiceEndpoint(getConfig().getStorageFactory());
787         String JavaDoc portComponentName = getChildBeanText(portComponentDD, "port-component-name"); // NOI81N
788
newWebserviceEndpoint.setPortComponentName(portComponentName);
789         
790         // If specified, try to load any saved mappings this endpoint might have
791
if(load) {
792             Base parent = getParent();
793             if(parent instanceof WebServices) {
794                 WebServices wsParent = (WebServices) parent;
795                 String JavaDoc linkName = getChildBeanText(portComponentDD, "service-impl-bean/" + helper.getLinkXpath());
796                 WebserviceEndpoint savedEndpoint = wsParent.removeEndpoint(linkName, portComponentName);
797                 
798                 // Clone this data now, before possibly trimming it from the tree, below.
799
if(savedEndpoint != null) {
800                     newWebserviceEndpoint = (WebserviceEndpoint) savedEndpoint.clone();
801                 } else {
802                     // set load to false so that we create a default endpoint uri, if required.
803
load = false;
804                 }
805                 
806                 // If the host data is still cached, remove this endpoint from the cache entry
807
// for the host so that it is not saved twice if modified. See IZ 94865
808
BaseRoot masterRoot = getConfig().getMasterDCBRoot();
809                 masterRoot.removeCachedEndpoint(helper.getHostProperty(), helper.getHostNameProperty(),
810                         linkName, helper.getEndpointProperty(), portComponentName);
811             }
812         }
813         
814         // Only fire vetoable/property changes if we set a default value on this endpoint.
815
if(!load && requiresDefaultEndpointUri) {
816             newWebserviceEndpoint.setEndpointAddressUri(portComponentName);
817             getVCS().fireVetoableChange(WEBSERVICE_ENDPOINT, null, newWebserviceEndpoint);
818         }
819
820         if(webServiceEndpointMap == null) {
821             webServiceEndpointMap = new HashMap JavaDoc();
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 JavaDoc portComponentDD) throws java.beans.PropertyVetoException JavaDoc {
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     /** Setter for message security binding for specific endpoint.
840      *
841      * @param portName port to locate binding for.
842      * @param binding instance of MessageSecurityBinding to set on this port
843      */

844     public void setMessageSecurityBinding(String JavaDoc portName, MessageSecurityBinding newBinding) throws java.beans.PropertyVetoException JavaDoc, 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 JavaDoc(MessageFormat.format(bundle.getString("ERR_InvalidPortName"), new Object JavaDoc [] { portName }));
853         }
854     }
855
856     /** This method is the backbone of an attempt to interface the new Map based storage
857      * for endpoints with the existing List based API, which the existing UI depends
858      * on, even though the List provides less information. This algorithm is dependent
859      * on each port component name specified for a servlet being unique, regardless
860      * of which servlet or ejb implements it. This will generally be true (in fact
861      * it may be required.)
862      */

863     private DDBean JavaDoc createKey(String JavaDoc targetPortComponentName) {
864         DDBean JavaDoc key = null;
865         DDBean JavaDoc [] portComponentBeans = getDDBean().getChildBean("port-component"); // NOI18N
866
for(int i = 0; i < portComponentBeans.length; i++) {
867             String JavaDoc 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 JavaDoc WEB_URI_PREFIX = ""; // NOI18N
879
private static final String JavaDoc EJB_URI_PREFIX = "webservice/"; // NOI18N
880

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 JavaDoc linkXpath;
887         private final String JavaDoc hostProperty;
888         private final String JavaDoc hostNameProperty;
889         private final String JavaDoc endpointProperty;
890         private final String JavaDoc blueprintsUriPrefix;
891
892         public EndpointHelper(String JavaDoc xpath, String JavaDoc hp, String JavaDoc hnp, String JavaDoc epp, String JavaDoc uriPrefix) {
893             linkXpath = xpath;
894             hostProperty = hp;
895             hostNameProperty = hnp;
896             endpointProperty = epp;
897             blueprintsUriPrefix = uriPrefix;
898         }
899
900         public String JavaDoc getLinkXpath() {
901             return linkXpath;
902         }
903
904         private String JavaDoc getHostProperty() {
905             return hostProperty;
906         }
907
908         public String JavaDoc getHostNameProperty() {
909             return hostNameProperty;
910         }
911
912         public String JavaDoc getEndpointProperty() {
913             return endpointProperty;
914         }
915
916         public String JavaDoc 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