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