KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > xml > XMLServerBinding


1 package org.objectweb.celtix.bus.bindings.xml;
2
3 import java.util.Map JavaDoc;
4
5 import javax.jws.WebParam;
6 import javax.jws.soap.SOAPBinding;
7 import javax.xml.namespace.QName JavaDoc;
8 import javax.xml.ws.handler.MessageContext;
9
10 import org.w3c.dom.Node JavaDoc;
11 import org.w3c.dom.NodeList JavaDoc;
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 JavaDoc getOperationName(MessageContext ctx) {
39         XMLMessageContext xmlContext = XMLMessageContext.class.cast(ctx);
40         XMLMessage msg = xmlContext.getMessage();
41         Map JavaDoc<QName JavaDoc, ? 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 JavaDoc nl = msg.getRoot().getChildNodes();
48         boolean matchFound = false;
49         
50         for (Map.Entry JavaDoc<QName JavaDoc, ? 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                     // If the size of part in message is not ONE,
56
// Then there is a root node as the wrapper.
57
Node JavaDoc 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 JavaDoc 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                 //WRAPPED Style
88
Node JavaDoc node = NodeUtils.getChildElementNode(msg.getRoot());
89                 QName JavaDoc rw = callback.getRequestWrapperQName();
90                 //Check for the RequestWrapper name followed by
91
//Method Name (To avoid asyncronous operations)
92
//The method name check can be removed once JSR181 comes up
93
//with annotations for asynchronous operation. JAX-WS spec 2.3.4
94
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         //try to see if we CAN get a callback
104
Node JavaDoc node = NodeUtils.getChildElementNode(msg.getRoot());
105         QName JavaDoc qn = new QName JavaDoc(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 JavaDoc node, WebParam param) {
117         boolean found = false;
118         String JavaDoc 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 JavaDoc address) {
130         // TODO Auto-generated method stub
131
return false;
132     }
133 }
134
Popular Tags