1 7 8 package com.sun.corba.se.spi.presentation.rmi ; 9 10 import javax.rmi.CORBA.Tie ; 11 12 import org.omg.CORBA.portable.Delegate ; 13 import org.omg.CORBA.portable.ObjectImpl ; 14 import org.omg.CORBA.portable.OutputStream ; 15 16 import org.omg.PortableServer.POA ; 17 import org.omg.PortableServer.POAManager ; 18 import org.omg.PortableServer.Servant ; 19 20 import org.omg.PortableServer.POAPackage.WrongPolicy ; 21 import org.omg.PortableServer.POAPackage.ServantNotActive ; 22 import org.omg.PortableServer.POAManagerPackage.AdapterInactive ; 23 24 import org.omg.CORBA.ORB ; 25 26 import com.sun.corba.se.spi.logging.CORBALogDomains ; 27 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 28 29 import com.sun.corba.se.impl.oa.poa.POAManagerImpl ; 32 33 41 public abstract class StubAdapter 42 { 43 private StubAdapter() {} 44 45 private static ORBUtilSystemException wrapper = 46 ORBUtilSystemException.get( CORBALogDomains.RPC_PRESENTATION ) ; 47 48 public static boolean isStubClass( Class cls ) 49 { 50 return (ObjectImpl .class.isAssignableFrom( cls )) || 51 (DynamicStub.class.isAssignableFrom( cls )) ; 52 } 53 54 public static boolean isStub( Object stub ) 55 { 56 return (stub instanceof DynamicStub) || 57 (stub instanceof ObjectImpl ) ; 58 } 59 60 public static void setDelegate( Object stub, Delegate delegate ) 61 { 62 if (stub instanceof DynamicStub) 63 ((DynamicStub)stub).setDelegate( delegate ) ; 64 else if (stub instanceof ObjectImpl ) 65 ((ObjectImpl )stub)._set_delegate( delegate ) ; 66 else 67 throw wrapper.setDelegateRequiresStub() ; 68 } 69 70 72 public static org.omg.CORBA.Object activateServant( Servant servant ) 73 { 74 POA poa = servant._default_POA() ; 75 org.omg.CORBA.Object ref = null ; 76 77 try { 78 ref = poa.servant_to_reference( servant ) ; 79 } catch (ServantNotActive sna) { 80 throw wrapper.getDelegateServantNotActive( sna ) ; 81 } catch (WrongPolicy wp) { 82 throw wrapper.getDelegateWrongPolicy( wp ) ; 83 } 84 85 POAManager mgr = poa.the_POAManager() ; 88 if (mgr instanceof POAManagerImpl) { 89 POAManagerImpl mgrImpl = (POAManagerImpl)mgr ; 90 mgrImpl.implicitActivation() ; 91 } 92 93 return ref ; 94 } 95 96 99 public static org.omg.CORBA.Object activateTie( Tie tie ) 100 { 101 107 if (tie instanceof ObjectImpl ) { 108 return tie.thisObject() ; 109 } else if (tie instanceof Servant ) { 110 Servant servant = (Servant )tie ; 111 return activateServant( servant ) ; 112 } else { 113 throw wrapper.badActivateTieCall() ; 114 } 115 } 116 117 118 121 public static Delegate getDelegate( Object stub ) 122 { 123 if (stub instanceof DynamicStub) 124 return ((DynamicStub)stub).getDelegate() ; 125 else if (stub instanceof ObjectImpl ) 126 return ((ObjectImpl )stub)._get_delegate() ; 127 else if (stub instanceof Tie ) { 128 Tie tie = (Tie )stub ; 129 org.omg.CORBA.Object ref = activateTie( tie ) ; 130 return getDelegate( ref ) ; 131 } else 132 throw wrapper.getDelegateRequiresStub() ; 133 } 134 135 public static ORB getORB( Object stub ) 136 { 137 if (stub instanceof DynamicStub) 138 return ((DynamicStub)stub).getORB() ; 139 else if (stub instanceof ObjectImpl ) 140 return (ORB )((ObjectImpl )stub)._orb() ; 141 else 142 throw wrapper.getOrbRequiresStub() ; 143 } 144 145 public static String [] getTypeIds( Object stub ) 146 { 147 if (stub instanceof DynamicStub) 148 return ((DynamicStub)stub).getTypeIds() ; 149 else if (stub instanceof ObjectImpl ) 150 return ((ObjectImpl )stub)._ids() ; 151 else 152 throw wrapper.getTypeIdsRequiresStub() ; 153 } 154 155 public static void connect( Object stub, 156 ORB orb ) throws java.rmi.RemoteException 157 { 158 if (stub instanceof DynamicStub) 159 ((DynamicStub)stub).connect( 160 (com.sun.corba.se.spi.orb.ORB)orb ) ; 161 else if (stub instanceof javax.rmi.CORBA.Stub ) 162 ((javax.rmi.CORBA.Stub )stub).connect( orb ) ; 163 else if (stub instanceof ObjectImpl ) 164 orb.connect( (org.omg.CORBA.Object )stub ) ; 165 else 166 throw wrapper.connectRequiresStub() ; 167 } 168 169 public static boolean isLocal( Object stub ) 170 { 171 if (stub instanceof DynamicStub) 172 return ((DynamicStub)stub).isLocal() ; 173 else if (stub instanceof ObjectImpl ) 174 return ((ObjectImpl )stub)._is_local() ; 175 else 176 throw wrapper.isLocalRequiresStub() ; 177 } 178 179 public static OutputStream request( Object stub, 180 String operation, boolean responseExpected ) 181 { 182 if (stub instanceof DynamicStub) 183 return ((DynamicStub)stub).request( operation, 184 responseExpected ) ; 185 else if (stub instanceof ObjectImpl ) 186 return ((ObjectImpl )stub)._request( operation, 187 responseExpected ) ; 188 else 189 throw wrapper.requestRequiresStub() ; 190 } 191 } 192 | Popular Tags |