01: package org.objectweb.celtix.bus.handlers;
02:
03: import java.util.ArrayList;
04: import java.util.HashMap;
05: import java.util.List;
06: import java.util.Map;
07:
08: import javax.xml.namespace.QName;
09: import javax.xml.ws.handler.Handler;
10: import javax.xml.ws.handler.HandlerResolver;
11: import javax.xml.ws.handler.PortInfo;
12:
13: import org.objectweb.celtix.bus.jaxws.configuration.types.HandlerChainType;
14: import org.objectweb.celtix.configuration.Configuration;
15: import org.objectweb.celtix.handlers.HandlerChainBuilder;
16:
17: public class HandlerResolverImpl implements HandlerResolver {
18: public static final String PORT_CONFIGURATION_URI = "http://celtix.objectweb.org/bus/jaxws/port-config";
19:
20: private final Map<PortInfo, List<Handler>> handlerMap = new HashMap<PortInfo, List<Handler>>();
21: private Configuration busConfiguration;
22: private QName service;
23:
24: public HandlerResolverImpl(Configuration pBusConfiguration,
25: QName pService) {
26: this .busConfiguration = pBusConfiguration;
27: this .service = pService;
28: }
29:
30: public HandlerResolverImpl() {
31: this (null, null);
32: }
33:
34: public List<Handler> getHandlerChain(PortInfo portInfo) {
35:
36: List<Handler> handlerChain = handlerMap.get(portInfo);
37: if (handlerChain == null) {
38: handlerChain = createHandlerChain(portInfo);
39: handlerMap.put(portInfo, handlerChain);
40: }
41: return handlerChain;
42: }
43:
44: private List<Handler> createHandlerChain(PortInfo portInfo) {
45:
46: List<Handler> chain = null;
47: Configuration portConfiguration = null;
48: String id = portInfo.getPortName().getLocalPart();
49: if (service != null) {
50: id = service.toString() + "/"
51: + portInfo.getPortName().getLocalPart();
52: }
53: if (null != busConfiguration) {
54: portConfiguration = busConfiguration.getChild(
55: PORT_CONFIGURATION_URI, id);
56: }
57: if (null != portConfiguration) {
58: HandlerChainBuilder builder = new HandlerChainBuilder();
59: HandlerChainType hc = (HandlerChainType) portConfiguration
60: .getObject("handlerChain");
61: chain = builder.buildHandlerChainFromConfiguration(hc);
62: }
63: if (null == chain) {
64: chain = new ArrayList<Handler>();
65: }
66: return chain;
67: }
68: }
|