KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > WSDLMetaDataCache


1 package org.objectweb.celtix.bus.bindings;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.wsdl.Binding;
9 import javax.wsdl.BindingOperation;
10 import javax.wsdl.Definition;
11 import javax.wsdl.Port;
12 import javax.wsdl.extensions.soap.SOAPBinding;
13
14
15 public class WSDLMetaDataCache {
16     
17     Definition definition;
18     Port port;
19     Binding binding;
20     
21     Map JavaDoc<String JavaDoc, WSDLOperationInfo> allOperationInfo;
22
23     
24     
25     public WSDLMetaDataCache(Definition def, Port p) {
26         definition = def;
27         port = p;
28
29         binding = port.getBinding();
30         if (binding == null) {
31             throw new IllegalArgumentException JavaDoc("WSDL binding cannot be found for " + port.getName());
32         }
33     }
34     
35     public Definition getDefinition() {
36         return definition;
37     }
38     public String JavaDoc getTargetNamespace() {
39         return binding.getPortType().getQName().getNamespaceURI();
40     }
41
42     public javax.jws.soap.SOAPBinding.Style getStyle() {
43
44         // Find the binding style
45
javax.jws.soap.SOAPBinding.Style style = null;
46         if (binding != null) {
47             SOAPBinding soapBinding = getExtensibilityElement(binding.getExtensibilityElements(),
48                                                               SOAPBinding.class);
49             if (soapBinding != null) {
50                 style = javax.jws.soap.SOAPBinding.Style.valueOf(soapBinding.getStyle().toUpperCase());
51             }
52         }
53         // Default to document
54
return (style == null) ? javax.jws.soap.SOAPBinding.Style.DOCUMENT : style;
55     }
56     
57     public Map JavaDoc<String JavaDoc, WSDLOperationInfo> getAllOperationInfo() {
58         if (allOperationInfo == null) {
59             allOperationInfo = new HashMap JavaDoc<String JavaDoc, WSDLOperationInfo>();
60             for (Iterator JavaDoc it = binding.getBindingOperations().iterator(); it.hasNext();) {
61                 final BindingOperation bindingOperation = (BindingOperation)it.next();
62                 if (bindingOperation.getOperation() != null) {
63                     WSDLOperationInfo data = new WSDLOperationInfo(this,
64                                                                    bindingOperation);
65                     allOperationInfo.put(data.getName(), data);
66                 }
67             }
68         }
69         return allOperationInfo;
70     }
71     public WSDLOperationInfo getOperationInfo(String JavaDoc operation) {
72         return getAllOperationInfo().get(operation);
73     }
74
75     
76     
77     private static <T> T getExtensibilityElement(List JavaDoc elements, Class JavaDoc<T> type) {
78         for (Iterator JavaDoc i = elements.iterator(); i.hasNext();) {
79             Object JavaDoc element = i.next();
80             if (type.isInstance(element)) {
81                 return type.cast(element);
82             }
83         }
84         return null;
85     }
86     
87 }
88
Popular Tags