KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > ServiceRefPortInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.List JavaDoc;
26 import java.util.LinkedList JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import java.io.*;
35
36 import java.net.URL JavaDoc;
37 import java.net.MalformedURLException JavaDoc;
38 import javax.xml.namespace.QName JavaDoc;
39 import javax.xml.rpc.Stub JavaDoc;
40         
41 import com.sun.enterprise.deployment.runtime.common.MessageSecurityBindingDescriptor;
42
43 /**
44  * Information about a single WSDL port or port type in a service reference.
45  *
46  * @author Kenneth Saks
47  */

48
49 public class ServiceRefPortInfo extends Descriptor {
50
51     private String JavaDoc serviceEndpointInterface;
52
53     private boolean containerManaged;
54
55     private String JavaDoc portComponentLinkName;
56     private WebServiceEndpoint portComponentLink;
57
58     // Service reference with which this port info is associated.
59
private ServiceReferenceDescriptor serviceRef;
60
61     //
62
// Runtime info
63
//
64

65     private QName JavaDoc wsdlPort;
66
67     // Set of name/value pairs corresponding to JAXRPC Stub properties.
68
private Set JavaDoc stubProperties;
69
70     // Set of name/value pairs corresponding to JAXRPC Call properties.
71
private Set JavaDoc callProperties;
72
73     // Target endpoint address of linked port component. This is derived
74
// and set at runtime. There is no element for it in sun-j2ee-ri.xml
75
private String JavaDoc targetEndpointAddress;
76
77     // message-security-binding
78
private MessageSecurityBindingDescriptor messageSecBindingDesc = null;
79
80     private String JavaDoc mtomEnabled = null;
81     
82     public ServiceRefPortInfo(ServiceRefPortInfo other) {
83     super(other);
84     serviceEndpointInterface = other.serviceEndpointInterface;
85     containerManaged = other.containerManaged;
86     portComponentLinkName = other.portComponentLinkName;
87     portComponentLink = other.portComponentLink; // copy as-is
88
serviceRef = other.serviceRef; // copy as-is
89
wsdlPort = other.wsdlPort; // copy as-is
90
mtomEnabled = other.mtomEnabled;
91
92         stubProperties = new HashSet JavaDoc();
93     for (Iterator JavaDoc i = other.stubProperties.iterator(); i.hasNext();) {
94         stubProperties.add(new NameValuePairDescriptor
95                 ((NameValuePairDescriptor)i.next()));
96     }
97
98         callProperties = new HashSet JavaDoc(); // NameValuePairDescriptor
99
for (Iterator JavaDoc i = other.callProperties.iterator(); i.hasNext();) {
100         callProperties.add(new NameValuePairDescriptor(
101         (NameValuePairDescriptor)i.next()));
102     }
103
104     targetEndpointAddress = other.targetEndpointAddress;
105     }
106
107     public ServiceRefPortInfo() {
108         stubProperties = new HashSet JavaDoc();
109         callProperties = new HashSet JavaDoc();
110         containerManaged = false;
111     }
112
113     public void setServiceReference(ServiceReferenceDescriptor desc) {
114         serviceRef = desc;
115     }
116
117     public ServiceReferenceDescriptor getServiceReference() {
118         return serviceRef;
119     }
120
121     public boolean hasServiceEndpointInterface() {
122         return (serviceEndpointInterface != null);
123     }
124
125     public void setServiceEndpointInterface(String JavaDoc sei) {
126         serviceEndpointInterface = sei;
127     }
128
129     public String JavaDoc getServiceEndpointInterface() {
130         return serviceEndpointInterface;
131     }
132
133     public void setIsContainerManaged(boolean flag) {
134         containerManaged = flag;
135     }
136
137     public boolean isContainerManaged() {
138         return containerManaged;
139     }
140
141     public boolean isClientManaged() {
142         return !containerManaged;
143     }
144
145     /**
146      * Sets the name of the port component to which I refer.
147      * NOTE : Does *NOT* attempt to resolve link name. Use
148      * overloaded version or resolveLink if link resolution
149      * is required.
150      */

151     public void setPortComponentLinkName(String JavaDoc linkName) {
152         setPortComponentLinkName(linkName, false);
153     }
154
155     public WebServiceEndpoint setPortComponentLinkName(String JavaDoc linkName,
156                                                        boolean resolve) {
157         portComponentLinkName = linkName;
158
159         return resolve ? resolveLinkName() : null;
160     }
161     
162     public boolean hasPortComponentLinkName() {
163         return (portComponentLinkName != null);
164     }
165
166     public String JavaDoc getPortComponentLinkName() {
167         return portComponentLinkName;
168     }
169
170     public void setMessageSecurityBinding(
171        MessageSecurityBindingDescriptor messageSecBindingDesc) {
172        this.messageSecBindingDesc = messageSecBindingDesc;
173     }
174
175     public MessageSecurityBindingDescriptor getMessageSecurityBinding() {
176         return messageSecBindingDesc;
177     }
178
179     /**
180      *@return true only if there is a port component link AND it has been
181      * resolved to a valid port component within the application.
182      */

183     public boolean isLinkedToPortComponent() {
184         return (portComponentLinkName != null ) && (portComponentLink != null);
185     }
186
187     /**
188      * Try to resolve the current link name value to a WebServiceEndpoint
189      * object.
190      *
191      * @return WebServiceEndpoint to which link was resolved, or null if
192      * link name resolution failed.
193      */

194     public WebServiceEndpoint resolveLinkName() {
195
196         WebServiceEndpoint port = null;
197         String JavaDoc linkName = portComponentLinkName;
198
199         if( (linkName != null) && (linkName.length() > 0) ) {
200             int hashIndex = linkName.indexOf('#');
201             boolean absoluteLink = (hashIndex != -1);
202
203             BundleDescriptor bundleDescriptor = getBundleDescriptor();
204             Application app = bundleDescriptor.getApplication();
205             BundleDescriptor targetBundle = bundleDescriptor;
206             String JavaDoc portName = linkName;
207             
208             if( (app != null) && absoluteLink ) {
209                 // Resolve <module>#<port-component-name> style link
210
String JavaDoc relativeModuleUri = linkName.substring(0, hashIndex);
211                 portName = linkName.substring(hashIndex + 1);
212                 targetBundle = app.getRelativeBundle(bundleDescriptor,
213                                                      relativeModuleUri);
214             }
215
216             // targetBundle will only be null here if module lookup for
217
// absolute link failed.
218
if( targetBundle != null ) {
219                 LinkedList JavaDoc bundles = new LinkedList JavaDoc();
220                 bundles.addFirst(targetBundle);
221                 if( (app != null) && !absoluteLink ) {
222                     bundles.addAll(app.getBundleDescriptors());
223                 }
224                 for(Iterator JavaDoc iter = bundles.iterator(); iter.hasNext();) {
225                     BundleDescriptor next = (BundleDescriptor) iter.next();
226                     port = next.getWebServiceEndpointByName(portName);
227                     if( port != null ) {
228                         setPortComponentLink(port);
229                         break;
230                     }
231                 }
232             }
233         }
234
235         return port;
236     }
237
238     public WebServiceEndpoint getPortComponentLink() {
239         return portComponentLink;
240     }
241
242     /**
243      * @param portComponenet the port component to which I refer
244      */

245     public void setPortComponentLink(WebServiceEndpoint newPort) {
246         if( newPort != null ) {
247
248             // Keep port component link name in synch with port component
249
// object.
250
BundleDescriptor bundleDescriptor = getBundleDescriptor();
251             BundleDescriptor targetBundleDescriptor =
252                 newPort.getBundleDescriptor();
253             String JavaDoc linkName = newPort.getEndpointName();
254             if( bundleDescriptor != targetBundleDescriptor ) {
255                 Application app = bundleDescriptor.getApplication();
256                 String JavaDoc relativeUri = app.getRelativeUri(bundleDescriptor,
257                                                         targetBundleDescriptor);
258                 linkName = relativeUri + "#" + linkName;
259             }
260             portComponentLinkName = linkName;
261         }
262         portComponentLink = newPort;
263     }
264
265     private BundleDescriptor getBundleDescriptor() {
266         return serviceRef.getBundleDescriptor();
267     }
268
269     //
270
// Runtime info
271
//
272

273     public boolean hasWsdlPort() {
274         return (wsdlPort != null);
275     }
276
277     public void setWsdlPort(QName JavaDoc port) {
278         wsdlPort = port;
279     }
280
281     public QName JavaDoc getWsdlPort() {
282         return wsdlPort;
283     }
284
285     // Set of NameValuePairDescriptor objects for each stub property.
286
public Set JavaDoc getStubProperties() {
287         return stubProperties;
288     }
289
290     public boolean hasStubProperty(String JavaDoc name) {
291         return (getStubPropertyValue(name) != null);
292     }
293
294     public String JavaDoc getStubPropertyValue(String JavaDoc name) {
295         String JavaDoc value = null;
296         for(Iterator JavaDoc iter = stubProperties.iterator(); iter.hasNext();) {
297             NameValuePairDescriptor next = (NameValuePairDescriptor)iter.next();
298             if( next.getName().equals(name) ) {
299                 value = next.getValue();
300                 break;
301             }
302         }
303         return value;
304     }
305
306     public NameValuePairDescriptor getStubPropertyByName(String JavaDoc name) {
307         NameValuePairDescriptor prop = null;
308         for(Iterator JavaDoc iter = stubProperties.iterator(); iter.hasNext();) {
309             NameValuePairDescriptor next = (NameValuePairDescriptor)
310                 iter.next();
311             if( next.getName().equals(name) ) {
312                 prop = next;
313                 break;
314             }
315         }
316         return prop;
317     }
318
319     /**
320      * Add stub property, using property name as a key. This will
321      * replace the property value of any existing stub property with
322      * the same name.
323      */

324     public void addStubProperty(NameValuePairDescriptor property) {
325         NameValuePairDescriptor prop =
326             getStubPropertyByName(property.getName());
327         if( prop != null ) {
328             prop.setValue(property.getValue());
329         } else {
330             stubProperties.add(property);
331         }
332     }
333     
334      /**
335      * Remove stub property, using property name as a key. This will
336      * remove the property value of an existing stub property with
337      * the matching name.
338      */

339     public void removeStubProperty(NameValuePairDescriptor property) {
340         NameValuePairDescriptor prop =
341             getStubPropertyByName(property.getName());
342         if (prop != null) {
343             stubProperties.remove(property);
344         }
345     }
346
347     /**
348      * Add stub property, using property name as a key. This will
349      * replace the property value of any existing stub property with
350      * the same name.
351      */

352     public void addStubProperty(String JavaDoc name, String JavaDoc value) {
353         NameValuePairDescriptor nvPair = new NameValuePairDescriptor();
354         nvPair.setName(name);
355         nvPair.setValue(value);
356         addStubProperty(nvPair);
357     }
358
359     public Set JavaDoc getCallProperties() {
360         return callProperties;
361     }
362
363     public boolean hasCallProperty(String JavaDoc name) {
364         return (getCallPropertyByName(name) != null);
365     }
366
367     public NameValuePairDescriptor getCallPropertyByName(String JavaDoc name) {
368         NameValuePairDescriptor prop = null;
369         for(Iterator JavaDoc iter = callProperties.iterator(); iter.hasNext();) {
370             NameValuePairDescriptor next = (NameValuePairDescriptor)
371                 iter.next();
372             if( next.getName().equals(name) ) {
373                 prop = next;
374                 break;
375             }
376         }
377         return prop;
378     }
379
380     /**
381      * Add call property, using property name as a key. This will
382      * replace the property value of any existing stub property with
383      * the same name.
384      */

385     public void addCallProperty(NameValuePairDescriptor property) {
386         NameValuePairDescriptor prop =
387             getCallPropertyByName(property.getName());
388         if( prop != null ) {
389             prop.setValue(property.getValue());
390         } else {
391             callProperties.add(property);
392         }
393     }
394
395     
396     /**
397      * Remove call property, using property name as a key. This will
398      * remove the property value of an existing stub property with
399      * the matching name.
400      */

401     public void removeCallProperty(NameValuePairDescriptor property) {
402         NameValuePairDescriptor prop =
403             getCallPropertyByName(property.getName());
404         if( prop != null ) {
405             callProperties.remove(property);
406         }
407     }
408
409     public boolean hasTargetEndpointAddress() {
410         return (targetEndpointAddress != null);
411     }
412
413     public void setTargetEndpointAddress(String JavaDoc address) {
414         targetEndpointAddress = address;
415     }
416
417     public String JavaDoc getTargetEndpointAddress() {
418         return targetEndpointAddress;
419     }
420
421     public void setMtomEnabled(String JavaDoc value) {
422         mtomEnabled = value;
423     }
424     
425     public String JavaDoc getMtomEnabled() {
426         return mtomEnabled;
427     }
428 }
429
Popular Tags