1 package org.objectweb.celtix.bus.handlers; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.List ; 6 import java.util.Map ; 7 8 import javax.xml.namespace.QName ; 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 PORT_CONFIGURATION_URI = 19 "http://celtix.objectweb.org/bus/jaxws/port-config"; 20 21 private final Map <PortInfo, List <Handler>> handlerMap = new HashMap <PortInfo, List <Handler>>(); 22 private Configuration busConfiguration; 23 private QName service; 24 25 public HandlerResolverImpl(Configuration pBusConfiguration, 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() + "/" + 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 <Handler>(); 63 } 64 return chain; 65 } 66 } 67 | Popular Tags |