01: package com.sun.xml.ws.server.sei;
02:
03: import com.sun.istack.Nullable;
04: import com.sun.xml.ws.api.WSBinding;
05: import com.sun.xml.ws.api.message.Packet;
06: import com.sun.xml.ws.model.AbstractSEIModelImpl;
07: import com.sun.xml.ws.model.JavaMethodImpl;
08:
09: import javax.xml.namespace.QName;
10: import java.util.HashMap;
11: import java.util.Map;
12:
13: /**
14: * An {@link EndpointMethodDispatcher} that uses SOAPAction as the key for dispatching.
15: * <p/>
16: * A map of all SOAPAction on the port and the corresponding {@link EndpointMethodHandler}
17: * is initialized in the constructor. The SOAPAction from the
18: * request {@link Packet} is used as the key to return the correct handler.
19: *
20: * @author Jitendra Kotamraju
21: */
22: final class SOAPActionBasedDispatcher implements
23: EndpointMethodDispatcher {
24: private final Map<String, EndpointMethodHandler> methodHandlers;
25:
26: public SOAPActionBasedDispatcher(AbstractSEIModelImpl model,
27: WSBinding binding, SEIInvokerTube invokerTube) {
28: // Find if any SOAPAction repeat for operations
29: Map<String, Integer> unique = new HashMap<String, Integer>();
30: for (JavaMethodImpl m : model.getJavaMethods()) {
31: String soapAction = m.getOperation().getSOAPAction();
32: Integer count = unique.get(soapAction);
33: if (count == null) {
34: unique.put(soapAction, 1);
35: } else {
36: unique.put(soapAction, ++count);
37: }
38: }
39: methodHandlers = new HashMap<String, EndpointMethodHandler>();
40: for (JavaMethodImpl m : model.getJavaMethods()) {
41: String soapAction = m.getOperation().getSOAPAction();
42: // Set up method handlers only for unique SOAPAction values so
43: // that dispatching happens consistently for a method
44: if (unique.get(soapAction) == 1) {
45: methodHandlers.put('"' + soapAction + '"',
46: new EndpointMethodHandler(invokerTube, m,
47: binding));
48: }
49: }
50: }
51:
52: public @Nullable
53: EndpointMethodHandler getEndpointMethodHandler(Packet request) {
54: return request.soapAction == null ? null : methodHandlers
55: .get(request.soapAction);
56: }
57:
58: }
|