1 7 15 16 package javax.rmi.CORBA; 17 18 import java.rmi.RemoteException ; 19 20 import org.omg.CORBA.ORB ; 21 import org.omg.CORBA.INITIALIZE ; 22 import org.omg.CORBA.SystemException ; 23 import org.omg.CORBA.Any ; 24 import org.omg.CORBA.portable.InputStream ; 25 import org.omg.CORBA.portable.OutputStream ; 26 import org.omg.CORBA.portable.ObjectImpl ; 27 28 import javax.rmi.CORBA.Tie ; 29 import java.rmi.Remote ; 30 import java.io.File ; 31 import java.io.FileInputStream ; 32 import java.net.MalformedURLException ; 33 import java.security.AccessController ; 34 import java.security.PrivilegedAction ; 35 import java.util.Properties ; 36 import java.rmi.server.RMIClassLoader ; 37 38 import com.sun.corba.se.impl.orbutil.GetPropertyAction; 39 40 44 public class Util { 45 46 private static javax.rmi.CORBA.UtilDelegate utilDelegate = null; 48 private static final String UtilClassKey = "javax.rmi.CORBA.UtilClass"; 49 private static final String defaultUtilImplName = 50 "com.sun.corba.se.impl.javax.rmi.CORBA.Util"; 51 52 static { 53 utilDelegate = (javax.rmi.CORBA.UtilDelegate ) 54 createDelegateIfSpecified(UtilClassKey, defaultUtilImplName); 55 } 56 57 private Util(){} 58 59 64 public static RemoteException mapSystemException(SystemException ex) { 65 66 if (utilDelegate != null) { 67 return utilDelegate.mapSystemException(ex); 68 } 69 return null; 70 } 71 72 77 public static void writeAny(OutputStream out, Object obj) { 78 79 if (utilDelegate != null) { 80 utilDelegate.writeAny(out, obj); 81 } 82 } 83 84 89 public static Object readAny(InputStream in) { 90 91 if (utilDelegate != null) { 92 return utilDelegate.readAny(in); 93 } 94 return null; 95 } 96 97 107 public static void writeRemoteObject(OutputStream out, 108 java.lang.Object obj) { 109 110 if (utilDelegate != null) { 111 utilDelegate.writeRemoteObject(out, obj); 112 } 113 114 } 115 116 127 public static void writeAbstractObject(OutputStream out, 128 java.lang.Object obj) { 129 130 if (utilDelegate != null) { 131 utilDelegate.writeAbstractObject(out, obj); 132 } 133 } 134 135 141 public static void registerTarget(javax.rmi.CORBA.Tie tie, 142 java.rmi.Remote target) { 143 144 if (utilDelegate != null) { 145 utilDelegate.registerTarget(tie, target); 146 } 147 148 } 149 150 156 public static void unexportObject(java.rmi.Remote target) 157 throws java.rmi.NoSuchObjectException 158 { 159 160 if (utilDelegate != null) { 161 utilDelegate.unexportObject(target); 162 } 163 164 } 165 166 170 public static Tie getTie (Remote target) { 171 172 if (utilDelegate != null) { 173 return utilDelegate.getTie(target); 174 } 175 return null; 176 } 177 178 179 184 public static ValueHandler createValueHandler() { 185 186 if (utilDelegate != null) { 187 return utilDelegate.createValueHandler(); 188 } 189 return null; 190 } 191 192 197 public static String getCodebase(java.lang.Class clz) { 198 if (utilDelegate != null) { 199 return utilDelegate.getCodebase(clz); 200 } 201 return null; 202 } 203 204 230 public static Class loadClass(String className, 231 String remoteCodebase, 232 ClassLoader loader) 233 throws ClassNotFoundException { 234 if (utilDelegate != null) { 235 return utilDelegate.loadClass(className,remoteCodebase,loader); 236 } 237 return null ; 238 } 239 240 241 261 public static boolean isLocal(Stub stub) throws RemoteException { 262 263 if (utilDelegate != null) { 264 return utilDelegate.isLocal(stub); 265 } 266 267 return false; 268 } 269 270 276 public static RemoteException wrapException(Throwable orig) { 277 278 if (utilDelegate != null) { 279 return utilDelegate.wrapException(orig); 280 } 281 282 return null; 283 } 284 285 294 public static Object [] copyObjects (Object [] obj, ORB orb) 295 throws RemoteException { 296 297 if (utilDelegate != null) { 298 return utilDelegate.copyObjects(obj, orb); 299 } 300 301 return null; 302 } 303 304 312 public static Object copyObject (Object obj, ORB orb) 313 throws RemoteException { 314 315 if (utilDelegate != null) { 316 return utilDelegate.copyObject(obj, orb); 317 } 318 return null; 319 } 320 321 private static Object createDelegateIfSpecified(String classKey, 326 String defaultClassName) 327 { 328 String className = (String ) 329 AccessController.doPrivileged(new GetPropertyAction(classKey)); 330 if (className == null) { 331 Properties props = getORBPropertiesFile(); 332 if (props != null) { 333 className = props.getProperty(classKey); 334 } 335 } 336 337 if (className == null) { 338 className = defaultClassName; 339 } 340 341 try { 342 return loadDelegateClass(className).newInstance(); 343 } catch (ClassNotFoundException ex) { 344 INITIALIZE exc = new INITIALIZE ( "Cannot instantiate " + className); 345 exc.initCause( ex ) ; 346 throw exc ; 347 } catch (Exception ex) { 348 INITIALIZE exc = new INITIALIZE ( "Error while instantiating" + className); 349 exc.initCause( ex ) ; 350 throw exc ; 351 } 352 } 353 354 private static Class loadDelegateClass( String className ) throws ClassNotFoundException 355 { 356 try { 357 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 358 return Class.forName(className, false, loader); 359 } catch (ClassNotFoundException e) { 360 } 362 363 try { 364 return RMIClassLoader.loadClass(className); 365 } catch (MalformedURLException e) { 366 String msg = "Could not load " + className + ": " + e.toString(); 367 ClassNotFoundException exc = new ClassNotFoundException ( msg ) ; 368 throw exc ; 369 } 370 } 371 374 private static Properties getORBPropertiesFile () 375 { 376 return (Properties ) AccessController.doPrivileged( 377 new GetORBPropertiesFileAction ()); 378 } 379 380 } 381 | Popular Tags |