001: package org.objectweb.celtix.bus.bindings.xml;
002:
003: import java.util.Map;
004:
005: import javax.jws.WebParam;
006: import javax.jws.soap.SOAPBinding;
007: import javax.xml.namespace.QName;
008: import javax.xml.ws.handler.MessageContext;
009:
010: import org.w3c.dom.Node;
011: import org.w3c.dom.NodeList;
012:
013: import org.objectweb.celtix.Bus;
014: import org.objectweb.celtix.bindings.AbstractBindingImpl;
015: import org.objectweb.celtix.bindings.AbstractServerBinding;
016: import org.objectweb.celtix.bindings.DataBindingCallback;
017: import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
018: import org.objectweb.celtix.helpers.NodeUtils;
019: import org.objectweb.celtix.helpers.WSDLHelper;
020: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
021:
022: public class XMLServerBinding extends AbstractServerBinding {
023: protected final XMLBindingImpl xmlBinding;
024: protected final WSDLHelper helper;
025:
026: public XMLServerBinding(Bus b, EndpointReferenceType ref,
027: ServerBindingEndpointCallback cbFactory) {
028: super (b, ref, cbFactory);
029: xmlBinding = new XMLBindingImpl(b, ref, true);
030: helper = new WSDLHelper();
031: }
032:
033: public AbstractBindingImpl getBindingImpl() {
034: return xmlBinding;
035: }
036:
037: public QName getOperationName(MessageContext ctx) {
038: XMLMessageContext xmlContext = XMLMessageContext.class
039: .cast(ctx);
040: XMLMessage msg = xmlContext.getMessage();
041: Map<QName, ? extends DataBindingCallback> ops = sbeCallback
042: .getOperations();
043:
044: if (sbeCallback.getStyle() == SOAPBinding.Style.RPC) {
045: throw new XMLBindingException(
046: "Can not handle RPC style in xml binding");
047: }
048:
049: NodeList nl = msg.getRoot().getChildNodes();
050: boolean matchFound = false;
051:
052: for (Map.Entry<QName, ? extends DataBindingCallback> entry : ops
053: .entrySet()) {
054: DataBindingCallback callback = entry.getValue();
055: if (callback.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
056: int nodeIdx = 0;
057: if (callback.getParamsLength() != 1) {
058: // If the size of part in message is not ONE,
059: // Then there is a root node as the wrapper.
060: Node node = NodeUtils.getChildElementNode(msg
061: .getRoot());
062: if (callback.getOperationName().equals(
063: node.getLocalName())) {
064: matchFound = true;
065: } else {
066: continue;
067: }
068: }
069:
070: for (int x = 0; x < callback.getParamsLength(); x++) {
071: WebParam param = callback.getWebParam(x);
072: if (param.mode() != WebParam.Mode.OUT) {
073:
074: Node n = nl.item(nodeIdx);
075: while (n.getNodeType() != Node.ELEMENT_NODE) {
076: n = nl.item(++nodeIdx);
077: }
078:
079: if (isMethodMatch(n, param)) {
080: matchFound = true;
081: ++nodeIdx;
082: } else {
083: matchFound = false;
084: break;
085: }
086: }
087: }
088: if (matchFound) {
089: return entry.getKey();
090: }
091: } else {
092: //WRAPPED Style
093: Node node = NodeUtils
094: .getChildElementNode(msg.getRoot());
095: QName rw = callback.getRequestWrapperQName();
096: //Check for the RequestWrapper name followed by
097: //Method Name (To avoid asyncronous operations)
098: //The method name check can be removed once JSR181 comes up
099: //with annotations for asynchronous operation. JAX-WS spec 2.3.4
100: if (rw != null
101: && rw.getLocalPart()
102: .equals(node.getLocalName())
103: && rw.getNamespaceURI().equals(
104: node.getNamespaceURI())
105: && callback.getOperationName()
106: .equalsIgnoreCase(node.getLocalName())) {
107: return entry.getKey();
108: }
109: }
110: }
111:
112: //try to see if we CAN get a callback
113: Node node = NodeUtils.getChildElementNode(msg.getRoot());
114: QName qn = new QName(node.getNamespaceURI(), node
115: .getNamespaceURI());
116: if (sbeCallback.getDataBindingCallback(qn, null, sbeCallback
117: .getServiceMode()) != null) {
118: return qn;
119: }
120:
121: return null;
122: }
123:
124: private boolean isMethodMatch(Node node, WebParam param) {
125: boolean found = false;
126: String nNS = node.getNamespaceURI();
127: if (nNS != null) {
128: if (param.name().equals(node.getLocalName())
129: && nNS.equals(param.targetNamespace())) {
130: found = true;
131: }
132: } else if (param.name().equals(node.getLocalName())) {
133: found = true;
134: }
135: return found;
136: }
137:
138: public boolean isBindingCompatible(String address) {
139: // TODO Auto-generated method stub
140: return false;
141: }
142: }
|