1 package org.objectweb.celtix.bus.bindings; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 import java.util.Map ; 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 <String , 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 ("WSDL binding cannot be found for " + port.getName()); 32 } 33 } 34 35 public Definition getDefinition() { 36 return definition; 37 } 38 public String getTargetNamespace() { 39 return binding.getPortType().getQName().getNamespaceURI(); 40 } 41 42 public javax.jws.soap.SOAPBinding.Style getStyle() { 43 44 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 return (style == null) ? javax.jws.soap.SOAPBinding.Style.DOCUMENT : style; 55 } 56 57 public Map <String , WSDLOperationInfo> getAllOperationInfo() { 58 if (allOperationInfo == null) { 59 allOperationInfo = new HashMap <String , WSDLOperationInfo>(); 60 for (Iterator 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 operation) { 72 return getAllOperationInfo().get(operation); 73 } 74 75 76 77 private static <T> T getExtensibilityElement(List elements, Class <T> type) { 78 for (Iterator i = elements.iterator(); i.hasNext();) { 79 Object element = i.next(); 80 if (type.isInstance(element)) { 81 return type.cast(element); 82 } 83 } 84 return null; 85 } 86 87 } 88 | Popular Tags |