KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > handlers > HandlerResolverImpl


1 package org.objectweb.celtix.bus.handlers;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import javax.xml.namespace.QName JavaDoc;
9 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 JavaDoc PORT_CONFIGURATION_URI =
19         "http://celtix.objectweb.org/bus/jaxws/port-config";
20
21     private final Map JavaDoc<PortInfo, List JavaDoc<Handler>> handlerMap = new HashMap JavaDoc<PortInfo, List JavaDoc<Handler>>();
22     private Configuration busConfiguration;
23     private QName JavaDoc service;
24
25     public HandlerResolverImpl(Configuration pBusConfiguration, QName JavaDoc pService) {
26         this.busConfiguration = pBusConfiguration;
27         this.service = pService;
28     }
29
30     public HandlerResolverImpl() {
31         this(null, null);
32     }
33
34     public List JavaDoc<Handler> getHandlerChain(PortInfo portInfo) {
35
36         List JavaDoc<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 JavaDoc<Handler> createHandlerChain(PortInfo portInfo) {
45
46         List JavaDoc<Handler> chain = null;
47         Configuration portConfiguration = null;
48         String JavaDoc id = portInfo.getPortName().getLocalPart();
49         if (service != null) {
50             id = service.toString() + "/" + portInfo.getPortName().getLocalPart();
51         }
52         if (null != busConfiguration) {
53             portConfiguration = busConfiguration
54                 .getChild(PORT_CONFIGURATION_URI, id);
55         }
56         if (null != portConfiguration) {
57             HandlerChainBuilder builder = new HandlerChainBuilder();
58             HandlerChainType hc = (HandlerChainType)portConfiguration.getObject("handlerChain");
59             chain = builder.buildHandlerChainFromConfiguration(hc);
60         }
61         if (null == chain) {
62             chain = new ArrayList JavaDoc<Handler>();
63         }
64         return chain;
65     }
66 }
67
Popular Tags