| 1 package org.objectweb.celtix.bus.bindings.xml; 2 3 import java.util.Map ; 4 5 import javax.jws.WebParam; 6 import javax.jws.soap.SOAPBinding; 7 import javax.xml.namespace.QName ; 8 import javax.xml.ws.handler.MessageContext; 9 10 import org.w3c.dom.Node ; 11 import org.w3c.dom.NodeList ; 12 13 import org.objectweb.celtix.Bus; 14 import org.objectweb.celtix.bindings.AbstractBindingImpl; 15 import org.objectweb.celtix.bindings.AbstractServerBinding; 16 import org.objectweb.celtix.bindings.DataBindingCallback; 17 import org.objectweb.celtix.bindings.ServerBindingEndpointCallback; 18 import org.objectweb.celtix.helpers.NodeUtils; 19 import org.objectweb.celtix.helpers.WSDLHelper; 20 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 21 22 public class XMLServerBinding extends AbstractServerBinding { 23 protected final XMLBindingImpl xmlBinding; 24 protected final WSDLHelper helper; 25 26 public XMLServerBinding(Bus b, 27 EndpointReferenceType ref, 28 ServerBindingEndpointCallback cbFactory) { 29 super(b, ref, cbFactory); 30 xmlBinding = new XMLBindingImpl(b, ref, true); 31 helper = new WSDLHelper(); 32 } 33 34 public AbstractBindingImpl getBindingImpl() { 35 return xmlBinding; 36 } 37 38 public QName getOperationName(MessageContext ctx) { 39 XMLMessageContext xmlContext = XMLMessageContext.class.cast(ctx); 40 XMLMessage msg = xmlContext.getMessage(); 41 Map <QName , ? extends DataBindingCallback> ops = sbeCallback.getOperations(); 42 43 if (sbeCallback.getStyle() == SOAPBinding.Style.RPC) { 44 throw new XMLBindingException("Can not handle RPC style in xml binding"); 45 } 46 47 NodeList nl = msg.getRoot().getChildNodes(); 48 boolean matchFound = false; 49 50 for (Map.Entry <QName , ? extends DataBindingCallback> entry : ops.entrySet()) { 51 DataBindingCallback callback = entry.getValue(); 52 if (callback.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.BARE) { 53 int nodeIdx = 0; 54 if (callback.getParamsLength() != 1) { 55 Node node = NodeUtils.getChildElementNode(msg.getRoot()); 58 if (callback.getOperationName().equals(node.getLocalName())) { 59 matchFound = true; 60 } else { 61 continue; 62 } 63 } 64 65 for (int x = 0; x < callback.getParamsLength(); x++) { 66 WebParam param = callback.getWebParam(x); 67 if (param.mode() != WebParam.Mode.OUT) { 68 69 Node n = nl.item(nodeIdx); 70 while (n.getNodeType() != Node.ELEMENT_NODE) { 71 n = nl.item(++nodeIdx); 72 } 73 74 if (isMethodMatch(n, param)) { 75 matchFound = true; 76 ++nodeIdx; 77 } else { 78 matchFound = false; 79 break; 80 } 81 } 82 } 83 if (matchFound) { 84 return entry.getKey(); 85 } 86 } else { 87 Node node = NodeUtils.getChildElementNode(msg.getRoot()); 89 QName rw = callback.getRequestWrapperQName(); 90 if (rw != null 95 && rw.getLocalPart().equals(node.getLocalName()) 96 && rw.getNamespaceURI().equals(node.getNamespaceURI()) 97 && callback.getOperationName().equalsIgnoreCase(node.getLocalName())) { 98 return entry.getKey(); 99 } 100 } 101 } 102 103 Node node = NodeUtils.getChildElementNode(msg.getRoot()); 105 QName qn = new QName (node.getNamespaceURI(), node.getNamespaceURI()); 106 if (sbeCallback.getDataBindingCallback(qn, null, 107 sbeCallback.getServiceMode()) != null) { 108 return qn; 109 } 110 111 return null; 112 } 113 114 115 116 private boolean isMethodMatch(Node node, WebParam param) { 117 boolean found = false; 118 String nNS = node.getNamespaceURI(); 119 if (nNS != null) { 120 if (param.name().equals(node.getLocalName()) && nNS.equals(param.targetNamespace())) { 121 found = true; 122 } 123 } else if (param.name().equals(node.getLocalName())) { 124 found = true; 125 } 126 return found; 127 } 128 129 public boolean isBindingCompatible(String address) { 130 return false; 132 } 133 } 134 | Popular Tags |