KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.xml.namespace.QName JavaDoc;
38
39 import com.sun.enterprise.deployment.util.ModuleDescriptor;
40 import com.sun.enterprise.util.FileUtil;
41 import com.sun.enterprise.util.LocalStringManagerImpl;
42 import com.sun.enterprise.deployment.util.DOLUtils;
43 import com.sun.enterprise.deployment.types.HandlerChainContainer;
44
45 /**
46  * Information about a J2EE web service client.
47  *
48  * @author Kenneth Saks
49  */

50
51 public class ServiceReferenceDescriptor extends EnvironmentProperty
52         implements HandlerChainContainer {
53
54     private String JavaDoc serviceInterface;
55
56     private String JavaDoc mappedName;
57     
58     private String JavaDoc wsdlFileUri;
59
60     /**
61      * Derived, non-peristent location of wsdl file.
62      * Only used at deployment/runtime.
63      */

64     private URL JavaDoc wsdlFileUrl;
65
66     private String JavaDoc mappingFileUri;
67
68     /**
69      * Derived, non-peristent location of mapping file.
70      * Only used at deployment/runtime.
71      */

72     private File mappingFile;
73
74     // Optional service name. Only required if service-ref has WSDL and
75
// the WSDL defines multiple services.
76
private String JavaDoc serviceNamespaceUri;
77     private String JavaDoc serviceLocalPart;
78     private String JavaDoc serviceNameNamespacePrefix;
79
80     // settings for both container-managed and client-managed ports
81
private Set JavaDoc portsInfo;
82
83     // module in which this reference is defined.
84
private BundleDescriptor bundleDescriptor;
85
86     // List of handlers associated with this service reference.
87
// Handler order is important and must be preserved.
88
private LinkedList JavaDoc handlers;
89
90     // The handler chains defined for this service ref (JAXWS service-ref)
91
private LinkedList JavaDoc handlerChain;
92     
93     //
94
// Runtime info
95
//
96

97     private Set JavaDoc callProperties;
98
99     // Name of generated service implementation class.
100
private String JavaDoc serviceImplClassName;
101
102     // Optional wsdl to be used at deployment instead of the wsdl packaged
103
// in module and associated with the service-ref.
104
private URL JavaDoc wsdlOverride;
105     
106     // interface name of the expected injection recipient.
107
// because web service reference are a bit specific (you can inject
108
// the Service interface or the Port interface directly), you
109
// may need to disambiguate when loading from XML DDs.
110
private String JavaDoc injectionTargetType=null;
111     
112     public ServiceReferenceDescriptor(ServiceReferenceDescriptor other) {
113         super(other);
114     serviceInterface = other.serviceInterface;
115         mappedName = other.mappedName;
116     wsdlFileUri = other.wsdlFileUri;
117     wsdlFileUrl = other.wsdlFileUrl;
118     mappingFileUri = other.mappingFileUri;
119     mappingFile = other.mappingFile;
120     serviceNamespaceUri = other.serviceNamespaceUri;
121     serviceLocalPart = other.serviceLocalPart;
122     serviceNameNamespacePrefix = other.serviceNameNamespacePrefix;
123     portsInfo = new HashSet JavaDoc(); // ServiceRefPortInfo
124
for (Iterator JavaDoc i = other.portsInfo.iterator(); i.hasNext();) {
125         ServiceRefPortInfo port = new ServiceRefPortInfo(
126         (ServiceRefPortInfo)i.next());
127         port.setServiceReference(this); // reset reference
128
portsInfo.add(port);
129     }
130     handlers = new LinkedList JavaDoc(); // WebServiceHandler
131
for (Iterator JavaDoc i = other.handlers.iterator(); i.hasNext();) {
132         handlers.add(new WebServiceHandler
133                 ((WebServiceHandler)i.next()));
134     }
135     handlerChain = new LinkedList JavaDoc(); // WebServiceHandlerChain
136
for (Iterator JavaDoc i = other.handlerChain.iterator(); i.hasNext();) {
137         handlerChain.add(new WebServiceHandlerChain((WebServiceHandlerChain)i.next()));
138     }
139         callProperties = new HashSet JavaDoc(); // NameValuePairDescriptor
140
for (Iterator JavaDoc i = other.callProperties.iterator(); i.hasNext();) {
141         callProperties.add(new NameValuePairDescriptor(
142         (NameValuePairDescriptor)i.next()));
143     }
144     serviceImplClassName = other.serviceImplClassName;
145     }
146
147     public ServiceReferenceDescriptor(String JavaDoc name, String JavaDoc description,
148                                       String JavaDoc service) {
149         super(name, "", description);
150         handlers = new LinkedList JavaDoc();
151         handlerChain = new LinkedList JavaDoc();
152         portsInfo = new HashSet JavaDoc();
153         callProperties = new HashSet JavaDoc();
154         serviceInterface = service;
155     }
156     
157     public ServiceReferenceDescriptor() {
158         handlers = new LinkedList JavaDoc();
159         handlerChain = new LinkedList JavaDoc();
160         portsInfo = new HashSet JavaDoc();
161         callProperties = new HashSet JavaDoc();
162     }
163
164     public String JavaDoc getMappedName() {
165         return mappedName;
166     }
167     
168     public void setMappedName(String JavaDoc value) {
169         mappedName = value;
170     }
171     
172     public void setBundleDescriptor(BundleDescriptor bundle) {
173         bundleDescriptor = bundle;
174     }
175
176     public BundleDescriptor getBundleDescriptor() {
177         return bundleDescriptor;
178     }
179
180     public boolean hasGenericServiceInterface() {
181         return serviceInterface.equals("javax.xml.rpc.Service");
182     }
183
184     public boolean hasGeneratedServiceInterface() {
185         return !(hasGenericServiceInterface());
186     }
187
188     public void setServiceInterface(String JavaDoc service) {
189         serviceInterface = service;
190         super.changed();
191     }
192
193     public String JavaDoc getServiceInterface() {
194         return serviceInterface;
195     }
196
197     public boolean hasWsdlFile() {
198         return (wsdlFileUri != null);
199     }
200
201     /**
202      * Derived, non-peristent location of wsdl file.
203      * Only used at deployment/runtime.
204      */

205     public void setWsdlFileUrl(URL JavaDoc url) {
206         wsdlFileUrl = url;
207         super.changed();
208     }
209
210     public URL JavaDoc getWsdlFileUrl() {
211         return wsdlFileUrl;
212     }
213
214     public void setWsdlFileUri(String JavaDoc uri) {
215         wsdlFileUri = uri;
216         super.changed();
217     }
218
219     public String JavaDoc getWsdlFileUri() {
220         return wsdlFileUri;
221     }
222
223     public boolean hasMappingFile() {
224         return (mappingFileUri != null);
225     }
226
227     /**
228      * Derived, non-peristent location of mapping file.
229      * Only used at deployment/runtime.
230      */

231     public void setMappingFile(File file) {
232         mappingFile = file;
233         super.changed();
234     }
235
236     public File getMappingFile() {
237         return mappingFile;
238     }
239
240     public void setMappingFileUri(String JavaDoc uri) {
241         mappingFileUri = uri;
242         super.changed();
243     }
244
245     public String JavaDoc getMappingFileUri() {
246         return mappingFileUri;
247     }
248
249     public void setServiceName(QName JavaDoc serviceName) {
250         setServiceName(serviceName, null);
251     }
252
253     public void setServiceName(QName JavaDoc serviceName, String JavaDoc prefix) {
254         serviceNamespaceUri = serviceName.getNamespaceURI();
255         serviceLocalPart = serviceName.getLocalPart();
256         serviceNameNamespacePrefix = prefix;
257         super.changed();
258     }
259
260     public void setServiceNamespaceUri(String JavaDoc uri) {
261         serviceNamespaceUri = uri;
262         serviceNameNamespacePrefix = null;
263         super.changed();
264     }
265
266     public String JavaDoc getServiceNamespaceUri() {
267         return serviceNamespaceUri;
268     }
269
270     public void setServiceLocalPart(String JavaDoc localpart) {
271         serviceLocalPart = localpart;
272         serviceNameNamespacePrefix = null;
273         super.changed();
274     }
275
276     public String JavaDoc getServiceLocalPart() {
277         return serviceLocalPart;
278     }
279
280     public void setServiceNameNamespacePrefix(String JavaDoc prefix) {
281         serviceNameNamespacePrefix = prefix;
282         super.changed();
283     }
284
285     public String JavaDoc getServiceNameNamespacePrefix() {
286         return serviceNameNamespacePrefix;
287     }
288
289     public boolean hasServiceName() {
290         return ( (serviceNamespaceUri != null) && (serviceLocalPart != null) );
291     }
292
293     /**
294      * @return service QName or null if either part of qname is not set
295      */

296     public QName JavaDoc getServiceName() {
297         return ( hasServiceName() ?
298                  new QName JavaDoc(serviceNamespaceUri, serviceLocalPart) : null );
299     }
300
301     public Set JavaDoc getPortsInfo() {
302         return portsInfo;
303     }
304
305     public void addPortInfo(ServiceRefPortInfo portInfo) {
306         portInfo.setServiceReference(this);
307         portsInfo.add(portInfo);
308         super.changed();
309     }
310
311     public void removePortInfo(ServiceRefPortInfo portInfo) {
312         portsInfo.remove(portInfo);
313         super.changed();
314     }
315
316     /**
317      * Special handling of case where runtime port info is added.
318      * Ensures that port info is not duplicated when multiple
319      * runtime info instances are parsed using same standard descriptor.
320      */

321     public void addRuntimePortInfo(ServiceRefPortInfo runtimePortInfo) {
322         ServiceRefPortInfo existing = null;
323
324         if( runtimePortInfo.hasServiceEndpointInterface() ) {
325             existing =
326                 getPortInfoBySEI(runtimePortInfo.getServiceEndpointInterface());
327         }
328         if( (existing == null) && runtimePortInfo.hasWsdlPort() ) {
329             existing = getPortInfoByPort(runtimePortInfo.getWsdlPort());
330         }
331
332         if( existing == null ) {
333             if (portsInfo!=null && portsInfo.size()>0) {
334                 LocalStringManagerImpl localStrings =
335                     new LocalStringManagerImpl(ServiceReferenceDescriptor.class);
336                 DOLUtils.getDefaultLogger().warning(
337                     localStrings.getLocalString("enterprise.deployment.unknownportforruntimeinfo",
338                     "Runtime port info SEI {0} is not declared in standard service-ref " +
339                     "deployment descriptors (under port-component-ref), is this intended ?",
340                     new Object JavaDoc[] {runtimePortInfo.getServiceEndpointInterface()}));
341             }
342             addPortInfo(runtimePortInfo);
343         } else {
344             if( !existing.hasServiceEndpointInterface() ) {
345                 existing.setServiceEndpointInterface
346                     (runtimePortInfo.getServiceEndpointInterface());
347             }
348             if( !existing.hasWsdlPort() ) {
349                 existing.setWsdlPort(runtimePortInfo.getWsdlPort());
350             }
351             for(Iterator JavaDoc iter = runtimePortInfo.
352                     getStubProperties().iterator(); iter.hasNext();) {
353                 NameValuePairDescriptor next =
354                     (NameValuePairDescriptor) iter.next();
355                 // adds using name as key
356
existing.addStubProperty(next);
357             }
358             for(Iterator JavaDoc iter = runtimePortInfo.getCallProperties()
359                     .iterator(); iter.hasNext();) {
360                 NameValuePairDescriptor next =
361                     (NameValuePairDescriptor) iter.next();
362                 // adds using name as key
363
existing.addCallProperty(next);
364             }
365             if (runtimePortInfo.getMessageSecurityBinding() != null) {
366                 existing.setMessageSecurityBinding(
367                     runtimePortInfo.getMessageSecurityBinding());
368             }
369         }
370     }
371
372     public ServiceRefPortInfo addContainerManagedPort
373         (String JavaDoc serviceEndpointInterface) {
374         ServiceRefPortInfo info = new ServiceRefPortInfo();
375         info.setServiceEndpointInterface(serviceEndpointInterface);
376         info.setIsContainerManaged(true);
377         info.setServiceReference(this);
378         portsInfo.add(info);
379         super.changed();
380         return info;
381     }
382
383     public boolean hasContainerManagedPorts() {
384         boolean containerManaged = false;
385         for(Iterator JavaDoc iter = portsInfo.iterator(); iter.hasNext();) {
386             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
387             if( next.isContainerManaged() ) {
388                 containerManaged = true;
389                 break;
390             }
391         }
392         return containerManaged;
393     }
394
395     public boolean hasClientManagedPorts() {
396         boolean clientManaged = false;
397         for(Iterator JavaDoc iter = portsInfo.iterator(); iter.hasNext();) {
398             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
399             if( next.isClientManaged() ) {
400                 clientManaged = true;
401                 break;
402             }
403         }
404         return clientManaged;
405     }
406
407     /**
408      * Lookup port info by service endpoint interface.
409      */

410     public ServiceRefPortInfo getPortInfo(String JavaDoc serviceEndpointInterface) {
411         return getPortInfoBySEI(serviceEndpointInterface);
412     }
413
414     /**
415      * Lookup port info by service endpoint interface.
416      */

417     public ServiceRefPortInfo getPortInfoBySEI(String JavaDoc serviceEndpointInterface)
418     {
419         for(Iterator JavaDoc iter = portsInfo.iterator(); iter.hasNext();) {
420             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
421             if( serviceEndpointInterface.equals
422                 (next.getServiceEndpointInterface()) ) {
423                 return next;
424             }
425         }
426         return null;
427     }
428
429     /**
430      * Lookup port info by wsdl port.
431      */

432     public ServiceRefPortInfo getPortInfoByPort(QName JavaDoc wsdlPort) {
433         for(Iterator JavaDoc iter = portsInfo.iterator(); iter.hasNext();) {
434             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
435             if( next.hasWsdlPort() && wsdlPort.equals(next.getWsdlPort()) ) {
436                 return next;
437             }
438         }
439         return null;
440     }
441
442     /**
443      * Append handler to end of handler chain for this endpoint.
444      */

445     public void addHandler(WebServiceHandler handler) {
446         handlers.addLast(handler);
447         super.changed();
448     }
449
450     public void removeHandler(WebServiceHandler handler) {
451         handlers.remove(handler);
452         super.changed();
453     }
454
455     public void removeHandlerByName(String JavaDoc handlerName) {
456         for(Iterator JavaDoc iter = handlers.iterator(); iter.hasNext();) {
457             WebServiceHandler next = (WebServiceHandler) iter.next();
458             if( next.getHandlerName().equals(handlerName) ) {
459                 iter.remove();
460                 super.changed();
461                 break;
462             }
463         }
464     }
465
466     public boolean hasHandlers() {
467         return (handlers.size() > 0);
468     }
469
470     /**
471      * Get ordered list of WebServiceHandler handlers for this endpoint.
472      */

473     public LinkedList JavaDoc getHandlers() {
474         return handlers;
475     }
476
477     /**
478      * HandlerChain related setters, getters, adders, finders
479      */

480     public void addHandlerChain(WebServiceHandlerChain handler) {
481         handlerChain.addLast(handler);
482         super.changed();
483     }
484
485     public void removeHandlerChain(WebServiceHandlerChain handler) {
486         handlerChain.remove(handler);
487         super.changed();
488     }
489
490     public boolean hasHandlerChain() {
491         return (handlerChain.size() > 0);
492     }
493
494     public LinkedList JavaDoc getHandlerChain() {
495         return handlerChain;
496     }
497
498     /**
499      * Runtime information.
500      */

501
502     public Set JavaDoc getCallProperties() {
503         return callProperties;
504     }
505
506     public NameValuePairDescriptor getCallPropertyByName(String JavaDoc name) {
507         NameValuePairDescriptor prop = null;
508         for(Iterator JavaDoc iter = callProperties.iterator(); iter.hasNext();) {
509             NameValuePairDescriptor next = (NameValuePairDescriptor)
510                 iter.next();
511             if( next.getName().equals(name) ) {
512                 prop = next;
513                 break;
514             }
515         }
516         return prop;
517     }
518
519     /**
520      * Add call property, using property name as a key. This will
521      * replace the property value of any existing stub property with
522      * the same name.
523      */

524     public void addCallProperty(NameValuePairDescriptor property) {
525         NameValuePairDescriptor prop =
526             getCallPropertyByName(property.getName());
527         if( prop != null ) {
528             prop.setValue(property.getValue());
529         } else {
530             callProperties.add(property);
531         }
532     }
533
534     
535     /**
536      * Remove call property, using property name as a key. This will
537      * remove the property value of an existing stub property with
538      * the matching name.
539      */

540     public void removeCallProperty(NameValuePairDescriptor property) {
541         NameValuePairDescriptor prop =
542             getCallPropertyByName(property.getName());
543         if( prop != null ) {
544             callProperties.remove(property);
545         }
546     }
547
548     public boolean hasServiceImplClassName() {
549         return (serviceImplClassName != null);
550     }
551
552     public void setServiceImplClassName(String JavaDoc className) {
553         serviceImplClassName = className;
554     }
555
556     public String JavaDoc getServiceImplClassName() {
557         return serviceImplClassName;
558     }
559
560     public boolean hasWsdlOverride() {
561         return (wsdlOverride != null);
562     }
563
564     public void setWsdlOverride(URL JavaDoc override) {
565         wsdlOverride = override;
566     }
567
568     public URL JavaDoc getWsdlOverride() {
569         return wsdlOverride;
570     }
571     
572     public void setInjectionTargetType(String JavaDoc type) {
573         injectionTargetType = type;
574     }
575     
576     public String JavaDoc getInjectionTargetType() {
577         return injectionTargetType;
578     }
579
580     /* Equality on name. */
581     public boolean equals(Object JavaDoc object) {
582         if (object instanceof ServiceReferenceDescriptor) {
583             ServiceReferenceDescriptor thatReference =
584                 (ServiceReferenceDescriptor) object;
585             return thatReference.getName().equals(this.getName());
586         }
587         return false;
588     }
589
590 }
591
Popular Tags