01: package org.objectweb.celtix.bus.transports;
02:
03: import java.util.List;
04: import java.util.Map;
05: import java.util.concurrent.ConcurrentHashMap;
06:
07: import org.objectweb.celtix.Bus;
08: import org.objectweb.celtix.BusException;
09: import org.objectweb.celtix.configuration.types.ClassNamespaceMappingListType;
10: import org.objectweb.celtix.configuration.types.ClassNamespaceMappingType;
11: import org.objectweb.celtix.transports.TransportFactory;
12: import org.objectweb.celtix.transports.TransportFactoryManager;
13:
14: public final class TransportFactoryManagerImpl implements
15: TransportFactoryManager {
16:
17: final Map<String, TransportFactory> transportFactories;
18: private final Bus bus;
19:
20: public TransportFactoryManagerImpl(Bus b) throws BusException {
21: transportFactories = new ConcurrentHashMap<String, TransportFactory>();
22: bus = b;
23:
24: /*
25: loadTransportFactory("org.objectweb.celtix.bus.transports.http.HTTPTransportFactory",
26: "http://schemas.xmlsoap.org/wsdl/soap/",
27: "http://celtix.objectweb.org/transports/http/configuration");
28: */
29: Object obj = bus.getConfiguration().getObject(
30: "transportFactories");
31:
32: List<ClassNamespaceMappingType> factoryMappings = ((ClassNamespaceMappingListType) obj)
33: .getMap();
34: for (ClassNamespaceMappingType mapping : factoryMappings) {
35: String classname = mapping.getClassname();
36: List<String> namespaceList = mapping.getNamespace();
37: String[] namespaces = new String[namespaceList.size()];
38: namespaceList.toArray(namespaces);
39: loadTransportFactory(classname, namespaces);
40: }
41:
42: }
43:
44: public void loadTransportFactory(String classname,
45: String... namespaces) throws BusException {
46: try {
47: Class<? extends TransportFactory> clazz = Class.forName(
48: classname).asSubclass(TransportFactory.class);
49:
50: TransportFactory factory = clazz.newInstance();
51: factory.init(bus);
52: for (String namespace : namespaces) {
53: registerTransportFactory(namespace, factory);
54: }
55: } catch (ClassNotFoundException e) {
56: throw new BusException(e);
57: } catch (InstantiationException e) {
58: throw new BusException(e);
59: } catch (IllegalAccessException e) {
60: throw new BusException(e);
61: }
62: }
63:
64: /* (non-Javadoc)
65: * @see org.objectweb.celtix.bus.TransportFactoryManager#registerTransportFactory(java.lang.String,
66: * org.objectweb.celtix.transports.TransportFactory)
67: */
68: public void registerTransportFactory(String namespace,
69: TransportFactory factory) throws BusException {
70: transportFactories.put(namespace, factory);
71: }
72:
73: /* (non-Javadoc)
74: * @see org.objectweb.celtix.bus.TransportFactoryManager#deregisterTransportFactory(java.lang.String)
75: */
76: public void deregisterTransportFactory(String namespace)
77: throws BusException {
78: transportFactories.remove(namespace);
79: }
80:
81: /* (non-Javadoc)
82: * @see org.objectweb.celtix.bus.TransportFactoryManager#TransportFactory(java.lang.String)
83: */
84: public TransportFactory getTransportFactory(String namespace)
85: throws BusException {
86: return transportFactories.get(namespace);
87: }
88:
89: public void shutdown() {
90: //nothing to do
91: }
92: }
|