1 28 29 package org.objectweb.carol.util.delegate; 30 31 import java.rmi.NoSuchObjectException ; 32 import java.rmi.Remote ; 33 import java.rmi.RemoteException ; 34 import java.util.Arrays ; 35 import java.util.logging.Level ; 36 import java.util.logging.Logger ; 37 38 import javax.rmi.CORBA.Stub ; 39 import javax.rmi.CORBA.Tie ; 40 import javax.rmi.CORBA.UtilDelegate ; 41 import javax.rmi.CORBA.ValueHandler ; 42 43 import org.omg.CORBA.ORB ; 44 import org.omg.CORBA.SystemException ; 45 import org.omg.CORBA.portable.InputStream ; 46 import org.omg.CORBA.portable.OutputStream ; 47 48 49 55 public final class UtilDelegateImpl implements UtilDelegate { 56 57 60 private static Logger logger = Logger.getLogger(UtilDelegateImpl.class.getName()); 61 62 65 private static UtilDelegate proxied = null; 66 67 72 public UtilDelegateImpl() { 73 String [] vendorDelegates = new String [] { 74 "com.sun.corba.se.internal.POA.ShutdownUtilDelegate", "com.sun.corba.se.impl.javax.rmi.CORBA.Util", "com.ibm.CORBA.iiop.UtilDelegateImpl"}; 78 Class clz = null; 79 for (int ii = 0; ii < vendorDelegates.length; ii++) { 80 try { 81 clz = Class.forName(vendorDelegates[ii]); 82 break; 83 } catch (ClassNotFoundException ex) { 84 if (logger.isLoggable(Level.FINEST)) { 85 logger.log(Level.FINEST, "The class '" + vendorDelegates[ii] + "' was not found.", ex); 86 } 87 } 88 } 89 90 if (clz == null) { 91 throw new RuntimeException ("Couldn't load any of these: " + Arrays.asList(vendorDelegates)); 92 } 93 94 try { 95 proxied = (UtilDelegate ) clz.newInstance(); 96 } catch (InstantiationException ex) { 97 throw new RuntimeException (clz.getName(), ex); 98 } catch (IllegalAccessException ex) { 99 throw new RuntimeException (clz.getName() + " does not have a public constructor", ex); 100 } 101 } 102 103 112 public Object copyObject(Object obj, ORB orb) throws RemoteException { 113 return proxied.copyObject(obj, orb); 114 } 115 116 126 public Object [] copyObjects(Object [] objs, ORB orb) throws RemoteException { 127 return proxied.copyObjects(objs, orb); 128 } 129 130 134 public ValueHandler createValueHandler() { 135 return proxied.createValueHandler(); 136 } 137 138 143 public String getCodebase(Class clz) { 144 return proxied.getCodebase(clz); 145 } 146 147 152 public Tie getTie(Remote target) { 153 return proxied.getTie(target); 154 } 155 156 169 public boolean isLocal(Stub stub) throws RemoteException { 170 return proxied.isLocal(stub); 171 } 172 173 188 public Class loadClass(String className, String remoteCodebase, ClassLoader loader) throws ClassNotFoundException { 189 190 final ClassNotFoundException cnfe; 191 try { 192 return proxied.loadClass(className, remoteCodebase, loader); 193 } catch (ClassNotFoundException ex) { 194 cnfe = ex; 195 } 196 197 if (className.endsWith("Tie")) { 198 final String prefix = "org.omg.stub."; 199 final String mangledName; 200 if (className.startsWith(prefix)) { 201 mangledName = className.substring(prefix.length()); 204 } else { 205 mangledName = prefix + className; 209 } 210 return proxied.loadClass(mangledName, remoteCodebase, loader); 211 } 212 throw cnfe; 213 } 214 215 220 public RemoteException mapSystemException(SystemException ex) { 221 return proxied.mapSystemException(ex); 222 } 223 224 229 public Object readAny(InputStream in) { 230 return proxied.readAny(in); 231 } 232 233 239 public void registerTarget(Tie tie, Remote target) { 240 proxied.registerTarget(tie, target); 241 } 242 243 249 public void unexportObject(Remote target) throws NoSuchObjectException { 250 proxied.unexportObject(target); 251 } 252 253 259 public RemoteException wrapException(Throwable orig) { 260 return proxied.wrapException(orig); 261 } 262 263 273 public void writeAbstractObject(OutputStream out, Object obj) { 274 proxied.writeAbstractObject(out, obj); 275 } 276 277 282 public void writeAny(OutputStream out, Object obj) { 283 proxied.writeAny(out, obj); 284 } 285 286 296 public void writeRemoteObject(OutputStream out, Object obj) { 297 proxied.writeRemoteObject(out, obj); 298 } 299 } 300 | Popular Tags |