1 package org.jacorb.orb; 2 3 22 23 import org.omg.CORBA.ORB ; 24 import org.omg.CORBA.ORBPackage.InvalidName ; 25 import org.omg.CORBA.*; 26 27 import org.omg.PortableServer.*; 28 import org.omg.PortableServer.POAPackage.*; 29 import org.omg.PortableServer.CurrentPackage.NoContext ; 30 31 32 37 38 public class ServantDelegate 39 implements org.omg.PortableServer.portable.Delegate 40 { 41 private transient ORB orb = null; 42 private transient Repository ir = null; 43 private transient org.omg.PortableServer.Current _current = null; 44 private transient POA poa = null; 45 46 ServantDelegate( org.jacorb.orb.ORB orb ) 47 { 48 this.orb = orb; 49 } 50 51 54 55 private final void check() 56 { 57 if (orb == null) 58 { 59 throw new org.omg.CORBA.BAD_INV_ORDER ("The Servant has not been associated with an ORB instance"); 60 } 61 } 62 63 final public org.omg.CORBA.Object this_object (org.omg.PortableServer.Servant self) 64 { 65 check(); 66 try 67 { 68 poa = poa(self); 69 } 70 catch (org.omg.CORBA.OBJ_ADAPTER e) 71 { 72 75 poa = self._default_POA (); 76 } 77 78 if (poa == null) 79 { 80 throw new org.omg.CORBA.OBJ_ADAPTER ("null value returned by _default_POA() on Servant " + self); 81 } 82 83 try 84 { 85 return poa.servant_to_reference(self); 86 } 87 catch(ServantNotActive e) 88 { 89 throw new org.omg.CORBA.OBJ_ADAPTER (e.toString()); 90 } 91 catch(WrongPolicy e) 92 { 93 throw new org.omg.CORBA.OBJ_ADAPTER (e.toString()); 94 } 95 } 96 97 98 final public ORB orb(org.omg.PortableServer.Servant self) 99 { 100 check(); 101 return orb; 102 } 103 104 final public POA poa(org.omg.PortableServer.Servant self) 105 { 106 check(); 107 if (_current == null) 108 { 109 _getPOACurrent(); 110 } 111 try 112 { 113 if( ((org.jacorb.poa.Current)_current).get_servant() != self ) 121 { 122 throw new org.omg.CORBA.OBJ_ADAPTER (); 123 } 124 125 return _current.get_POA(); 126 } 127 catch(NoContext e) 128 { 129 throw new org.omg.CORBA.OBJ_ADAPTER (e.toString()); 130 } 131 } 132 133 final public byte[] object_id(org.omg.PortableServer.Servant self) 134 { 135 check(); 136 if (_current == null) 137 { 138 _getPOACurrent(); 139 } 140 try 141 { 142 return _current.get_object_id(); 143 } 144 catch(NoContext e) 145 { 146 throw new org.omg.CORBA.OBJ_ADAPTER (e.toString()); 147 } 148 } 149 150 private synchronized void _getPOACurrent() 151 { 152 if (_current == null) 153 { 154 try 155 { 156 _current = org.omg.PortableServer.CurrentHelper.narrow(orb.resolve_initial_references("POACurrent")); 157 } 158 catch (Exception e) 159 { 160 throw new org.omg.CORBA.INITIALIZE (e.toString()); 161 } 162 } 163 } 164 165 public POA default_POA(org.omg.PortableServer.Servant self) 166 { 167 check(); 168 try 169 { 170 return POAHelper.narrow(orb(self).resolve_initial_references("RootPOA")); 171 } 172 catch(InvalidName e) 173 { 174 throw new org.omg.CORBA.INITIALIZE (e.toString()); 175 } 176 } 177 178 public boolean non_existent(org.omg.PortableServer.Servant self) 179 { 180 check(); 181 return false; 182 } 183 184 public org.omg.CORBA.Object get_interface_def( org.omg.PortableServer.Servant self) 185 { 186 check(); 187 if ( ir == null) 188 { 189 try 190 { 191 ir = RepositoryHelper.narrow(orb.resolve_initial_references("InterfaceRepository")); 192 } 193 catch (Exception e) 194 { 195 throw new org.omg.CORBA.INITIALIZE (e.toString()); 196 } 197 } 198 return ir.lookup_id( ((org.omg.CORBA.portable.ObjectImpl )self._this_object())._ids()[0] ); 199 } 200 201 public org.omg.CORBA.InterfaceDef get_interface(org.omg.PortableServer.Servant self) 202 { 203 return org.omg.CORBA.InterfaceDefHelper.narrow( get_interface_def( self )); 204 } 205 206 public boolean is_a(org.omg.PortableServer.Servant self, String repid) 207 { 208 String [] intf = self._all_interfaces(poa(self), object_id(self)); 209 210 for( int i = 0; i < intf.length; i++) 211 { 212 if( intf[i].equals(repid)) 213 { 214 return true; 215 } 216 } 217 return repid.equals("IDL:omg.org/CORBA/Object:1.0"); 218 } 219 220 221 224 225 public org.omg.CORBA.Policy _get_policy(org.omg.CORBA.Object self, 226 int policy_type) 227 { 228 229 return poa != null ? ((org.jacorb.poa.POA)poa).getPolicy(policy_type) : null; 230 } 231 232 235 236 public org.omg.CORBA.DomainManager [] _get_domain_managers 237 (org.omg.CORBA.Object self) 238 { 239 return null; 240 } 241 242 247 248 public org.omg.CORBA.portable.OutputStream _invoke(org.omg.PortableServer.Servant self, 249 String method, 250 org.omg.CORBA.portable.InputStream _input, 251 org.omg.CORBA.portable.ResponseHandler handler) 252 throws org.omg.CORBA.SystemException 253 { 254 org.omg.CORBA.portable.OutputStream _out = null; 255 256 if( method.equals("_get_policy")) 257 { 258 _out = handler.createReply(); 259 _out.write_Object(_get_policy(_input.read_Object() , _input.read_long() ) ); 260 } 261 else if( method.equals("_is_a")) 262 { 263 _out = handler.createReply(); 264 _out.write_boolean(self._is_a(_input.read_string() )); 265 } 266 else if( method.equals("_interface")) 267 { 268 _out = handler.createReply(); 269 _out.write_Object(self._get_interface_def() ); 270 } 271 else if( method.equals("_non_existent")) 272 { 273 _out = handler.createReply(); 274 _out.write_boolean(self._non_existent() ); 275 } 276 else 277 throw new BAD_PARAM("Unknown operation: " + method ); 278 279 return _out; 280 } 281 282 283 } 284 | Popular Tags |