1 18 package org.apache.geronimo.interop.adapter; 19 20 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.geronimo.gbean.*; 25 import org.apache.geronimo.interop.naming.NameService; 26 27 import java.util.HashMap ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 31 public class AdapterManager implements ReferenceCollectionListener { 32 33 private final Log log = LogFactory.getLog(AdapterManager.class); 34 private HashMap homeAdapters; 35 private HashMap remoteAdapters; 36 private Collection containers = Collections.EMPTY_SET; 37 private ClassLoader classLoader; 38 39 private NameService nameService = NameService.getInstance(); 40 41 45 public AdapterManager() 46 { 47 this.homeAdapters = null; 48 this.remoteAdapters = null; 49 this.containers = null; 50 this.classLoader = null; 51 } 52 53 public AdapterManager( ClassLoader classLoader) { 55 57 this.classLoader = classLoader; 58 59 69 70 72 registerNameServer(); 73 } 74 75 protected void registerNameServer() 76 { 77 81 String bindNames[] = new String [] { "NameService" }; 82 String remoteClassName = "org.apache.geronimo.interop.rmi.iiop.server.ServerNamingContext"; 83 String remoteInterfaceName = "org.apache.geronimo.interop.CosNaming.NamingContext"; 85 String ids[] = new String [] { "IDL:omg.org/CosNaming/NamingContext:1.0", 86 "IDL:omg.org/CosNaming/NamingContextExt:1.0" }; 87 ClassLoader cl = this.getClass().getClassLoader(); 88 89 CorbaAdapter a = new CorbaAdapter( bindNames, ids, remoteClassName, remoteInterfaceName, cl ); 90 a.start(); 91 registerRemoteAdapter(a); 92 } 93 94 protected Adapter getAdapter( Object adapterID ) { 95 Adapter rc = getRemoteAdapter( adapterID ); 97 if (rc == null) 98 { 99 rc = getHomeAdapter( adapterID ); 100 } 101 return rc; 102 } 103 104 protected Adapter getHomeAdapter( Object adapterID ) 105 { 106 return (Adapter)homeAdapters.get( adapterID ); 107 } 108 109 protected Adapter getRemoteAdapter( Object adapterID ) 110 { 111 return (Adapter)remoteAdapters.get( adapterID ); 112 } 113 114 protected void registerHomeAdapter( Adapter adapter ) 115 { 116 homeAdapters.put( adapter.getAdapterID(), adapter ); 117 } 118 119 protected void registerRemoteAdapter( Adapter adapter ) 120 { 121 remoteAdapters.put( adapter.getAdapterID(), adapter ); 122 } 123 124 protected void unregisterHomeAdapter( Adapter adapter ) 125 { 126 homeAdapters.remove( adapter.getAdapterID() ); 127 } 128 129 protected void unregisterRemoteAdapter( Adapter adapter ) 130 { 131 remoteAdapters.remove( adapter.getAdapterID() ); 132 } 133 134 public void memberAdded(ReferenceCollectionEvent event) { 135 164 } 165 166 public void memberRemoved(ReferenceCollectionEvent event) { 167 181 } 182 183 public static final GBeanInfo GBEAN_INFO; 184 185 static { 186 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(AdapterManager.class); 187 188 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 189 191 infoFactory.setConstructor(new String []{"classLoader"}); 193 194 GBEAN_INFO = infoFactory.getBeanInfo(); 195 } 196 197 public static GBeanInfo getGBeanInfo() { 198 return GBEAN_INFO; 199 } 200 } 201 | Popular Tags |