1 package org.jacorb.orb.giop; 2 3 22 23 import java.io.*; 24 import java.net.*; 25 import java.util.*; 26 import java.lang.reflect.Constructor ; 27 28 import org.apache.avalon.framework.logger.Logger; 29 import org.apache.avalon.framework.configuration.*; 30 31 import org.omg.ETF.*; 32 33 import org.jacorb.orb.*; 34 import org.jacorb.orb.factory.*; 35 import org.jacorb.orb.iiop.*; 36 import org.jacorb.util.ObjectUtil; 37 38 45 46 public class TransportManager 47 implements Configurable 48 { 49 private SocketFactory socket_factory = null; 50 private SocketFactory ssl_socket_factory = null; 51 52 private ORB orb = null; 53 54 55 private org.jacorb.config.Configuration configuration = null; 56 57 58 private Logger logger = null; 59 private List factoryClassNames = null; 60 private ProfileSelector profileSelector = null; 61 private SocketFactoryManager socketFactoryManager = null; 62 63 66 private Map factoriesMap = null; 67 68 73 private List factoriesList = null; 74 75 public TransportManager( ORB orb ) 76 { 77 this.orb = orb; 78 socketFactoryManager = new SocketFactoryManager(orb); 79 } 80 81 public void configure(Configuration myConfiguration) 82 throws ConfigurationException 83 { 84 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 85 logger = 86 configuration.getNamedLogger("jacorb.orb.giop"); 87 socketFactoryManager.configure(configuration); 88 89 factoryClassNames = 91 this.configuration.getAttributeList("jacorb.transport.factories"); 92 93 if (factoryClassNames.isEmpty()) 94 factoryClassNames.add("org.jacorb.orb.iiop.IIOPFactories"); 95 96 profileSelector = 98 (ProfileSelector)configuration.getAttributeAsObject("jacorb.transport.client.selector"); 99 100 if (profileSelector == null) 101 { 102 profileSelector = new DefaultProfileSelector(); 103 } 104 105 if( configuration.getAttribute("jacorb.security.support_ssl","off").equals("on")) 106 { 107 String s = configuration.getAttribute("jacorb.ssl.socket_factory", ""); 108 if (s.length() == 0) 109 { 110 throw new RuntimeException ( "SSL support is on, but the property \"jacorb.ssl.socket_factory\" is not set!" ); 111 } 112 113 try 114 { 115 Class ssl = ObjectUtil.classForName(s); 116 117 Constructor constr = 118 ssl.getConstructor( new Class []{ ORB.class }); 119 120 ssl_socket_factory = 121 (SocketFactory)constr.newInstance( new Object []{ orb }); 122 } 123 catch (Exception e) 124 { 125 126 if (logger.isErrorEnabled()) 127 logger.error(e.getMessage()); 128 129 throw new RuntimeException ( "SSL support is on, but the ssl socket factory can't be instantiated ("+ e.getMessage()+")!" ); 130 } 131 } 132 133 socket_factory = socketFactoryManager.getSocketFactory(); 134 } 135 136 public ProfileSelector getProfileSelector() 137 { 138 return profileSelector; 139 } 140 141 public SocketFactoryManager getSocketFactoryManager() 142 { 143 return socketFactoryManager; 144 } 145 146 public SocketFactory getSocketFactory() 147 { 148 return socket_factory; 149 } 150 151 public SocketFactory getSSLSocketFactory() 152 { 153 return ssl_socket_factory; 154 } 155 156 157 161 public org.omg.ETF.Factories getFactories(int tag) 162 { 163 if (factoriesMap == null) 164 { 165 loadFactories(); 166 } 167 return (Factories)factoriesMap.get (new Integer (tag)); 168 } 169 170 175 public List getFactoriesList() 176 { 177 if (factoriesList == null) 178 { 179 loadFactories(); 180 } 181 return Collections.unmodifiableList(factoriesList); 182 } 183 184 187 private void loadFactories() 188 { 189 if (configuration == null ) 190 throw new org.omg.CORBA.BAD_INV_ORDER ("TransportManager not configured!"); 191 192 if (factoryClassNames == null ) 193 throw new org.omg.CORBA.INTERNAL ("factoryClassNames should not be null"); 194 195 factoriesMap = new HashMap(); 196 factoriesList = new ArrayList(); 197 198 for (Iterator i = factoryClassNames.iterator(); i.hasNext();) 199 { 200 String className = (String )i.next(); 201 Factories f = instantiateFactories(className); 202 factoriesMap.put(new Integer (f.profile_tag()), f); 203 factoriesList.add (f); 204 } 205 } 206 207 210 private org.omg.ETF.Factories instantiateFactories (String className) 211 { 212 try 213 { 214 Class c = ObjectUtil.classForName(className); 219 Configurable configurable = (Configurable)c.newInstance(); 220 configurable.configure(configuration); 221 return (Factories)configurable; 222 } 223 catch (Exception e) 224 { 225 throw new RuntimeException 226 ("could not instantiate Factories class " + className 227 + ", exception: " + e); 228 } 229 } 230 231 } 232 | Popular Tags |