1 7 8 16 17 package javax.rmi.CORBA; 18 19 import org.omg.CORBA.ORB ; 20 import org.omg.CORBA.INITIALIZE ; 21 import org.omg.CORBA_2_3.portable.ObjectImpl ; 22 23 import java.io.IOException ; 24 import java.rmi.RemoteException ; 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.net.MalformedURLException ; 28 import java.security.AccessController ; 29 import java.security.PrivilegedAction ; 30 import java.util.Properties ; 31 import java.rmi.server.RMIClassLoader ; 32 33 import com.sun.corba.se.impl.orbutil.GetPropertyAction; 34 35 36 39 public abstract class Stub extends ObjectImpl 40 implements java.io.Serializable { 41 42 private static final long serialVersionUID = 1087775603798577179L; 43 44 private transient StubDelegate stubDelegate = null; 46 private static Class stubDelegateClass = null; 47 private static final String StubClassKey = "javax.rmi.CORBA.StubClass"; 48 private static final String defaultStubImplName = "com.sun.corba.se.impl.javax.rmi.CORBA.StubDelegateImpl"; 49 50 static { 51 Object stubDelegateInstance = (Object ) createDelegateIfSpecified(StubClassKey, defaultStubImplName); 52 if (stubDelegateInstance != null) 53 stubDelegateClass = stubDelegateInstance.getClass(); 54 55 } 56 57 58 63 public int hashCode() { 64 65 if (stubDelegate == null) { 66 setDefaultDelegate(); 67 } 68 69 if (stubDelegate != null) { 70 return stubDelegate.hashCode(this); 71 } 72 73 return 0; 74 } 75 76 83 public boolean equals(java.lang.Object obj) { 84 85 if (stubDelegate == null) { 86 setDefaultDelegate(); 87 } 88 89 if (stubDelegate != null) { 90 return stubDelegate.equals(this, obj); 91 } 92 93 return false; 94 } 95 96 101 public String toString() { 102 103 104 if (stubDelegate == null) { 105 setDefaultDelegate(); 106 } 107 108 String ior; 109 if (stubDelegate != null) { 110 ior = stubDelegate.toString(this); 111 if (ior == null) { 112 return super.toString(); 113 } else { 114 return ior; 115 } 116 } 117 return super.toString(); 118 } 119 120 131 public void connect(ORB orb) throws RemoteException { 132 133 if (stubDelegate == null) { 134 setDefaultDelegate(); 135 } 136 137 if (stubDelegate != null) { 138 stubDelegate.connect(this, orb); 139 } 140 141 } 142 143 146 private void readObject(java.io.ObjectInputStream stream) 147 throws IOException , ClassNotFoundException { 148 149 if (stubDelegate == null) { 150 setDefaultDelegate(); 151 } 152 153 if (stubDelegate != null) { 154 stubDelegate.readObject(this, stream); 155 } 156 157 } 158 159 167 private void writeObject(java.io.ObjectOutputStream stream) throws IOException { 168 169 if (stubDelegate == null) { 170 setDefaultDelegate(); 171 } 172 173 if (stubDelegate != null) { 174 stubDelegate.writeObject(this, stream); 175 } 176 } 177 178 private void setDefaultDelegate() { 179 if (stubDelegateClass != null) { 180 try { 181 stubDelegate = (javax.rmi.CORBA.StubDelegate ) stubDelegateClass.newInstance(); 182 } catch (Exception ex) { 183 } 187 } 188 } 189 190 private static Object createDelegateIfSpecified(String classKey, String defaultClassName) { 195 String className = (String ) 196 AccessController.doPrivileged(new GetPropertyAction(classKey)); 197 if (className == null) { 198 Properties props = getORBPropertiesFile(); 199 if (props != null) { 200 className = props.getProperty(classKey); 201 } 202 } 203 204 if (className == null) { 205 className = defaultClassName; 206 } 207 208 try { 209 return loadDelegateClass(className).newInstance(); 210 } catch (ClassNotFoundException ex) { 211 INITIALIZE exc = new INITIALIZE ( "Cannot instantiate " + className); 212 exc.initCause( ex ) ; 213 throw exc ; 214 } catch (Exception ex) { 215 INITIALIZE exc = new INITIALIZE ( "Error while instantiating" + className); 216 exc.initCause( ex ) ; 217 throw exc ; 218 } 219 220 } 221 222 private static Class loadDelegateClass( String className ) throws ClassNotFoundException 223 { 224 try { 225 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 226 return Class.forName(className, false, loader); 227 } catch (ClassNotFoundException e) { 228 } 230 231 try { 232 return RMIClassLoader.loadClass(className); 233 } catch (MalformedURLException e) { 234 String msg = "Could not load " + className + ": " + e.toString(); 235 ClassNotFoundException exc = new ClassNotFoundException ( msg ) ; 236 throw exc ; 237 } 238 } 239 240 243 private static Properties getORBPropertiesFile () { 244 return (Properties ) AccessController.doPrivileged(new GetORBPropertiesFileAction ()); 245 } 246 247 } 248 | Popular Tags |