1 7 15 16 package com.sun.corba.se.impl.util; 17 18 import java.rmi.Remote ; 19 import java.rmi.NoSuchObjectException ; 20 import java.rmi.server.RMIClassLoader ; 21 import java.rmi.server.UnicastRemoteObject ; 22 import org.omg.CORBA.BAD_PARAM ; 23 import org.omg.CORBA.CompletionStatus ; 24 import java.util.Properties ; 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.security.AccessController ; 28 import java.security.PrivilegedAction ; 29 import java.net.MalformedURLException ; 30 import com.sun.corba.se.impl.orbutil.GetPropertyAction; 31 32 36 public class JDKBridge { 37 38 42 public static String getLocalCodebase () { 43 return localCodebase; 44 } 45 46 50 public static boolean useCodebaseOnly () { 51 return useCodebaseOnly; 52 } 53 54 64 public static Class loadClass (String className, 65 String remoteCodebase, 66 ClassLoader loader) 67 throws ClassNotFoundException { 68 69 if (loader == null) { 70 return loadClassM(className,remoteCodebase,useCodebaseOnly); 71 } else { 72 try { 73 return loadClassM(className,remoteCodebase,useCodebaseOnly); 74 } catch (ClassNotFoundException e) { 75 return loader.loadClass(className); 76 } 77 } 78 } 79 80 88 public static Class loadClass (String className, 89 String remoteCodebase) 90 throws ClassNotFoundException { 91 return loadClass(className,remoteCodebase,null); 92 } 93 94 100 public static Class loadClass (String className) 101 throws ClassNotFoundException { 102 return loadClass(className,null,null); 103 } 104 105 private static final String LOCAL_CODEBASE_KEY = "java.rmi.server.codebase"; 106 private static final String USE_CODEBASE_ONLY_KEY = "java.rmi.server.useCodebaseOnly"; 107 private static String localCodebase = null; 108 private static boolean useCodebaseOnly; 109 110 static { 111 setCodebaseProperties(); 112 } 113 114 public static final void main (String [] args) { 115 System.out.println("1.2 VM"); 116 117 130 } 131 132 136 public static synchronized void setCodebaseProperties () { 137 String prop = (String )AccessController.doPrivileged( 138 new GetPropertyAction(LOCAL_CODEBASE_KEY) 139 ); 140 if (prop != null && prop.trim().length() > 0) { 141 localCodebase = prop; 142 } 143 144 prop = (String )AccessController.doPrivileged( 145 new GetPropertyAction(USE_CODEBASE_ONLY_KEY) 146 ); 147 if (prop != null && prop.trim().length() > 0) { 148 useCodebaseOnly = Boolean.valueOf(prop).booleanValue(); 149 } 150 } 151 152 156 public static synchronized void setLocalCodebase(String codebase) { 157 localCodebase = codebase; 158 } 159 160 private static Class loadClassM (String className, 161 String remoteCodebase, 162 boolean useCodebaseOnly) 163 throws ClassNotFoundException { 164 165 try { 166 return JDKClassLoader.loadClass(null,className); 167 } catch (ClassNotFoundException e) {} 168 try { 169 if (!useCodebaseOnly && remoteCodebase != null) { 170 return RMIClassLoader.loadClass(remoteCodebase, 171 className); 172 } else { 173 return RMIClassLoader.loadClass(className); 174 } 175 } catch (MalformedURLException e) { 176 className = className + ": " + e.toString(); 177 } 178 179 throw new ClassNotFoundException (className); 180 } 181 } 182 183 | Popular Tags |