1 25 package org.objectweb.carol.rmi.multi; 26 27 import java.rmi.NoSuchObjectException ; 28 import java.rmi.Remote ; 29 import java.rmi.RemoteException ; 30 31 import javax.rmi.CORBA.PortableRemoteObjectDelegate ; 32 33 import org.objectweb.carol.util.configuration.TraceCarol; 34 35 36 40 public class JacORBPRODelegate implements PortableRemoteObjectDelegate { 41 42 45 private static final String SUN_JDK14_CLASS = "com.sun.corba.se.internal.javax.rmi.PortableRemoteObject"; 46 47 50 private static final String IBM_JDK14_CLASS = "com.ibm.CORBA.iiop.PortableRemoteObject"; 51 52 55 private static final String SUN_JDK50_CLASS = "com.sun.corba.se.impl.javax.rmi.PortableRemoteObject"; 56 57 60 private static final String DEFAULT_JACORB_CLASS = "org.jacorb.orb.rmi.PortableRemoteObjectDelegateImpl"; 61 62 63 66 private static final String [] DELEGATE_CLASSES = new String [] {SUN_JDK14_CLASS, IBM_JDK14_CLASS, SUN_JDK50_CLASS }; 67 68 69 72 private static PortableRemoteObjectDelegate delegate = null; 73 74 81 public void exportObject(Remote obj) throws RemoteException { 82 getDelegate().exportObject(obj); 83 84 } 85 86 93 public void unexportObject(Remote obj) throws NoSuchObjectException { 94 getDelegate().unexportObject(obj); 95 96 } 97 98 106 public Remote toStub(Remote obj) throws NoSuchObjectException { 107 return getDelegate().toStub(obj); 108 } 109 110 122 public void connect(Remote target, Remote source) throws RemoteException { 123 getDelegate().connect(target, source); 124 125 } 126 127 135 public Object narrow(Object narrowFrom, Class narrowTo) throws ClassCastException { 136 return getDelegate().narrow(narrowFrom, narrowTo); 137 } 138 139 140 146 private PortableRemoteObjectDelegate getDelegate() { 147 if (delegate != null) { 149 return delegate; 150 } 151 152 Class clazz = null; 153 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 155 156 158 boolean classFound = false; 159 int i = 0; 160 while (!classFound && i < DELEGATE_CLASSES.length) { 161 String cls = DELEGATE_CLASSES[i]; 163 164 if (TraceCarol.isDebugCarol()) { 166 TraceCarol.debugCarol("Trying with class '" + cls + "'."); 167 } 168 169 try { 170 clazz = cl.loadClass(cls); 172 if (TraceCarol.isDebugCarol()) { 173 TraceCarol.debugCarol("Class found, Use as prodelegate class : '" + cls + "'."); 174 } 175 classFound = true; 177 } catch (ClassNotFoundException cnfesun) { 178 if (TraceCarol.isDebugCarol()) { 180 TraceCarol.debugCarol("Class '" + cls + "' not available."); 181 } 182 } 183 184 i++; 186 } 187 188 if (!classFound) { 190 try { 191 clazz = cl.loadClass(DEFAULT_JACORB_CLASS); 192 } catch (ClassNotFoundException cnfejacorb) { 193 throw new IllegalArgumentException ("Could not load default class '" + DEFAULT_JACORB_CLASS + "' :" + cnfejacorb.getMessage()); 194 } 195 TraceCarol.infoCarol("Using default Jacorb delegate class and not the JVM class as JVM class was not found. It may fail in some cases."); 196 } 197 198 199 Object o = null; 201 try { 202 o = clazz.newInstance(); 203 } catch (IllegalAccessException iae) { 204 throw new IllegalArgumentException ("Cannot make instance of class : '" + clazz + "' : " + iae.getMessage()); 205 } catch (InstantiationException ie) { 206 throw new IllegalArgumentException ("Cannot make instance of class : '" + clazz + "' : " + ie.getMessage()); 207 } 208 209 if (o instanceof PortableRemoteObjectDelegate ) { 211 delegate = (PortableRemoteObjectDelegate ) o; 212 return delegate; 213 } else { 214 throw new IllegalArgumentException ("Object '" + o + "' is not an instance of PortableRemoteObjectDelegate"); 215 } 216 217 } 218 219 220 } | Popular Tags |