1 7 15 16 package com.sun.corba.se.impl.javax.rmi; 17 18 import java.lang.reflect.Method ; 19 20 import javax.rmi.CORBA.Tie ; 21 import javax.rmi.CORBA.Util ; 22 23 import java.rmi.RemoteException ; 24 import java.rmi.NoSuchObjectException ; 25 import java.rmi.Remote ; 26 27 import java.util.Properties ; 28 29 import org.omg.CORBA.ORB ; 30 import org.omg.CORBA.portable.Delegate ; 31 import org.omg.CORBA.SystemException ; 32 33 import java.rmi.server.UnicastRemoteObject ; 34 import java.rmi.server.RemoteStub ; 35 import java.rmi.server.ExportException ; 36 37 import java.net.URL ; 38 39 import com.sun.corba.se.impl.util.JDKBridge; 40 import com.sun.corba.se.impl.util.Utility; 41 import com.sun.corba.se.impl.util.RepositoryId; 42 43 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 44 45 import java.security.AccessController ; 46 import com.sun.corba.se.impl.orbutil.GetPropertyAction; 47 48 62 public class PortableRemoteObject 63 implements javax.rmi.CORBA.PortableRemoteObjectDelegate { 64 65 72 public void exportObject(Remote obj) 73 throws RemoteException { 74 75 if (obj == null) { 76 throw new NullPointerException ("invalid argument"); 77 } 78 79 81 if (Util.getTie(obj) != null) { 82 83 85 throw new ExportException (obj.getClass().getName() + " already exported"); 86 } 87 88 90 Tie theTie = Utility.loadTie(obj); 91 92 if (theTie != null) { 93 94 96 Util.registerTarget(theTie,obj); 97 98 } else { 99 100 103 UnicastRemoteObject.exportObject(obj); 104 } 105 } 106 107 115 public Remote toStub (Remote obj) 116 throws NoSuchObjectException 117 { 118 Remote result = null; 119 if (obj == null) { 120 throw new NullPointerException ("invalid argument"); 121 } 122 123 if (StubAdapter.isStub( obj )) { 125 return obj; 126 } 127 128 if (obj instanceof java.rmi.server.RemoteStub ) { 130 return obj; 131 } 132 133 Tie theTie = Util.getTie(obj); 135 136 if (theTie != null) { 137 result = Utility.loadStub(theTie,null,null,true); 138 } else { 139 if (Utility.loadTie(obj) == null) { 140 result = java.rmi.server.RemoteObject.toStub(obj); 141 } 142 } 143 144 if (result == null) { 145 throw new NoSuchObjectException ("object not exported"); 146 } 147 148 return result; 149 } 150 151 158 public void unexportObject(Remote obj) 159 throws NoSuchObjectException { 160 161 if (obj == null) { 162 throw new NullPointerException ("invalid argument"); 163 } 164 165 if (StubAdapter.isStub(obj) || 166 obj instanceof java.rmi.server.RemoteStub ) { 167 throw new NoSuchObjectException ( 168 "Can only unexport a server object."); 169 } 170 171 Tie theTie = Util.getTie(obj); 172 if (theTie != null) { 173 Util.unexportObject(obj); 174 } else { 175 if (Utility.loadTie(obj) == null) { 176 UnicastRemoteObject.unexportObject(obj,true); 177 } else { 178 throw new NoSuchObjectException ("Object not exported."); 179 } 180 } 181 } 182 183 191 public java.lang.Object narrow ( java.lang.Object narrowFrom, 192 java.lang.Class narrowTo) throws ClassCastException 193 { 194 java.lang.Object result = null; 195 196 if (narrowFrom == null) 197 return null; 198 199 if (narrowTo == null) 200 throw new NullPointerException ("invalid argument"); 201 202 try { 203 if (narrowTo.isAssignableFrom(narrowFrom.getClass())) 204 return narrowFrom; 205 206 if (narrowTo.isInterface() && 209 narrowTo != java.io.Serializable .class && 210 narrowTo != java.io.Externalizable .class) { 211 212 org.omg.CORBA.Object narrowObj 213 = (org.omg.CORBA.Object ) narrowFrom; 214 215 String id = RepositoryId.createForAnyType(narrowTo); 217 218 if (narrowObj._is_a(id)) { 219 return Utility.loadStub(narrowObj,narrowTo); 220 } else { 221 throw new ClassCastException ( "Object is not of remote type " + 222 narrowTo.getName() ) ; 223 } 224 } else { 225 throw new ClassCastException ( "Class " + narrowTo.getName() + 226 " is not a valid remote interface" ) ; 227 } 228 } catch(Exception error) { 229 ClassCastException cce = new ClassCastException () ; 230 cce.initCause( error ) ; 231 throw cce ; 232 } 233 } 234 235 247 public void connect (Remote target, Remote source) 248 throws RemoteException 249 { 250 if (target == null || source == null) { 251 throw new NullPointerException ("invalid argument"); 252 } 253 254 ORB orb = null; 255 try { 256 if (StubAdapter.isStub( source )) { 257 orb = StubAdapter.getORB( source ) ; 258 } else { 259 Tie tie = Util.getTie(source); 261 if (tie == null) { 262 272 } else { 273 orb = tie.orb(); 274 } 275 } 276 } catch (SystemException e) { 277 throw new RemoteException ("'source' object not connected", e ); 278 } 279 280 boolean targetIsIIOP = false ; 281 Tie targetTie = null; 282 if (StubAdapter.isStub(target)) { 283 targetIsIIOP = true; 284 } else { 285 targetTie = Util.getTie(target); 286 if (targetTie != null) { 287 targetIsIIOP = true; 288 } else { 289 294 } 295 } 296 297 if (!targetIsIIOP) { 298 if (orb != null) { 303 throw new RemoteException ( 304 "'source' object exported to IIOP, 'target' is JRMP"); 305 } 306 } else { 307 if (orb == null) { 310 throw new RemoteException ( 311 "'source' object is JRMP, 'target' is IIOP"); 312 } 313 314 try { 316 if (targetTie != null) { 317 try { 319 ORB existingOrb = targetTie.orb(); 320 321 if (existingOrb == orb) { 323 324 return; 326 } else { 327 throw new RemoteException ( 329 "'target' object was already connected"); 330 } 331 } catch (SystemException e) {} 332 333 targetTie.orb(orb); 335 } else { 336 StubAdapter.connect( target, orb ) ; 337 } 338 } catch (SystemException e) { 339 340 throw new RemoteException ( 342 "'target' object was already connected", e ); 343 } 344 } 345 } 346 } 347 | Popular Tags |