1 package org.objectweb.celtix.routing; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.logging.Level ; 6 import java.util.logging.Logger ; 7 8 import javax.wsdl.Definition; 9 import javax.wsdl.Port; 10 import javax.wsdl.Service; 11 import javax.wsdl.extensions.ExtensibilityElement; 12 import javax.wsdl.extensions.ExtensionRegistry; 13 import javax.xml.bind.JAXBException; 14 import javax.xml.ws.WebServiceException; 15 16 import org.objectweb.celtix.Bus; 17 import org.objectweb.celtix.common.logging.LogUtils; 19 import org.objectweb.celtix.routing.configuration.DestinationType; 20 import org.objectweb.celtix.routing.configuration.RouteType; 21 import org.objectweb.celtix.routing.configuration.SourceType; 22 import org.objectweb.celtix.wsdl.JAXBExtensionHelper; 23 24 public class RouterFactory { 25 private static final Logger LOG = LogUtils.getL7dLogger(RouterFactory.class); 26 private RouterManager mgr; 27 private Bus bus; 28 29 30 public RouterFactory(RouterManager rm) { 31 mgr = rm; 32 } 33 34 public void init(Bus b) { 35 bus = b; 36 registerRouterExtension(bus.getWSDLManager().getExtenstionRegistry()); 37 } 38 39 private void registerRouterExtension(ExtensionRegistry registry) { 40 try { 41 JAXBExtensionHelper.addExtensions(registry, 42 Definition.class, 43 RouteType.class); 44 } catch (JAXBException e) { 45 throw new WebServiceException("Adding of routeType extension failed."); 46 } 47 } 48 49 @SuppressWarnings ("unchecked") 50 public List <Router> addRoutes(Definition def) { 51 List <Router> routerList = new ArrayList <Router>(); 52 List <ExtensibilityElement> extList = def.getExtensibilityElements(); 53 for (ExtensibilityElement extEl : extList) { 54 if (extEl instanceof RouteType) { 55 RouteType rt = (RouteType)extEl; 56 if (isValidRoute(def, rt)) { 57 Router router = createRouter(def, rt); 58 router.init(); 59 routerList.add(router); 60 } else { 61 if (LOG.isLoggable(Level.SEVERE)) { 64 LOG.log(Level.SEVERE, "UNSUPPORTED_ROUTE", rt.getName()); 65 } 66 } 67 } 68 } 69 70 return routerList; 71 } 72 73 @SuppressWarnings ("unchecked") 74 private boolean isValidRoute(Definition model, RouteType route) { 75 List <SourceType> source = route.getSource(); 76 List <DestinationType> dest = route.getDestination(); 77 if (source.size() != 1 78 || dest.size() != 1 79 || route.isSetMultiRoute() 80 || route.isSetOperation()) { 81 return false; 82 } 83 84 SourceType st = source.get(0); 86 DestinationType dt = dest.get(0); 87 88 Service sourceService = model.getService(st.getService()); 90 Service destService = model.getService(dt.getService()); 91 if (null == sourceService 92 || null == destService) { 93 return false; 94 } 95 96 Port sourcePort = sourceService.getPort(st.getPort()); 97 Port destPort = destService.getPort(dt.getPort()); 98 99 if (null == sourcePort 100 || null == destPort) { 101 return false; 102 } 103 104 return true; 105 } 106 107 public Router createRouter(Definition model, RouteType route) { 108 return new RouterImpl(mgr.getSEIClassLoader(), model, route); 109 } 110 } 111 | Popular Tags |