1: 
  37: 
  38: 
  39: package ;
  40: 
  41: import ;
  42: import ;
  43: import ;
  44: import ;
  45: 
  46: import ;
  47: import ;
  48: import ;
  49: import ;
  50: import ;
  51: import ;
  52: import ;
  53: import ;
  54: import ;
  55: import ;
  56: import ;
  57: import ;
  58: import ;
  59: import ;
  60: import ;
  61: import ;
  62: import ;
  63: import ;
  64: import ;
  65: import ;
  66: 
  67: import ;
  68: 
  69: 
  76: public class LocalDelegate
  77:   extends org.omg.CORBA_2_3.portable.Delegate
  78:   implements IorProvider
  79: {
  80:   
  83:   gnuServantObject object;
  84: 
  85:   String operation;
  86: 
  87:   public final gnuPOA poa;
  88: 
  89:   final byte[] Id;
  90: 
  91:   
  95:   public LocalDelegate(gnuServantObject an_object, gnuPOA a_poa, byte[] an_id)
  96:   {
  97:     object = an_object;
  98:     poa = a_poa;
  99:     Id = an_id;
 100:   }
 101: 
 102:   
 105:   public IOR getIor()
 106:   {
 107:     return object.getIor();
 108:   }
 109: 
 110:   public Request request(org.omg.CORBA.Object target, String method)
 111:   {
 112:     operation = method;
 113: 
 114:     LocalRequest rq = new LocalRequest(object, poa, Id);
 115:     rq.setOperation(method);
 116:     rq.setORB(orb(target));
 117:     return rq;
 118:   }
 119: 
 120:   public void release(org.omg.CORBA.Object target)
 121:   {
 122:   }
 123: 
 124:   public boolean is_equivalent(org.omg.CORBA.Object target,
 125:     org.omg.CORBA.Object other)
 126:   {
 127:     if (target == other)
 128:       return true;
 129:     else if (target instanceof ObjectImpl && other instanceof ObjectImpl)
 130:       {
 131:         org.omg.CORBA.portable.Delegate a = null;
 132:         org.omg.CORBA.portable.Delegate b = null;
 133:         try
 134:           {
 135:             a = ((ObjectImpl) target)._get_delegate();
 136:             b = ((ObjectImpl) other)._get_delegate();
 137:           }
 138:         catch (Exception ex)
 139:           {
 140:             
 141:             return false;
 142:           }
 143:         if (a instanceof LocalDelegate && b instanceof LocalDelegate)
 144:           {
 145:             byte[] k1 = ((LocalDelegate) a).Id;
 146:             byte[] k2 = ((LocalDelegate) b).Id;
 147:             return Arrays.equals(k1, k2);
 148:           }
 149:         else
 150:           return false;
 151:       }
 152:     else
 153:       return false;
 154:   }
 155: 
 156:   
 159:   public boolean non_existent(org.omg.CORBA.Object target)
 160:   {
 161:     return false;
 162:   }
 163: 
 164:   
 167:   public int hash(org.omg.CORBA.Object target, int maximum)
 168:   {
 169:     return hashCode() % maximum;
 170:   }
 171: 
 172:   
 179:   public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id)
 180:   {
 181:     String[] maybe = object._ids();
 182:     for (int i = 0; i < maybe.length; i++)
 183:       {
 184:         if (maybe[i].equals(idl_id))
 185:           return true;
 186:       }
 187:     return false;
 188:   }
 189: 
 190:   
 193:   public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target)
 194:   {
 195:     return target;
 196:   }
 197: 
 198:   
 201:   public Request create_request(org.omg.CORBA.Object target, Context context,
 202:     String method, NVList parameters, NamedValue returns,
 203:     ExceptionList exceptions, ContextList ctx_list)
 204:   {
 205:     operation = method;
 206: 
 207:     LocalRequest rq = new LocalRequest(object, poa, Id);
 208:     rq.setOperation(method);
 209:     rq.set_args(parameters);
 210:     rq.set_result(returns);
 211:     rq.set_exceptions(exceptions);
 212:     rq.set_context_list(ctx_list);
 213:     return rq;
 214:   }
 215: 
 216:   
 219:   public Request create_request(org.omg.CORBA.Object target, Context context,
 220:     String method, NVList parameters, NamedValue returns)
 221:   {
 222:     operation = method;
 223: 
 224:     LocalRequest rq = new LocalRequest(object, poa, Id);
 225:     rq.setOperation(method);
 226:     rq.set_args(parameters);
 227:     rq.set_result(returns);
 228:     return rq;
 229:   }
 230: 
 231:   
 234:   public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target)
 235:   {
 236:     throw new NO_IMPLEMENT();
 237:   }
 238: 
 239:   
 248:   public org.omg.CORBA.portable.OutputStream request(
 249:     org.omg.CORBA.Object target, String method, boolean response_expected)
 250:   {
 251:     operation = method;
 252: 
 253:     
 254:     AOM.Obj e = poa.aom.get(Id);
 255:     if (e != null && e.isDeactiveted())
 256:       {
 257:         if (poa.servant_activator != null || poa.servant_locator != null)
 258:           {
 259:             
 260:             object.setServant(null);
 261:             e.setServant(null);
 262:             e.setDeactivated(false);
 263:           }
 264:         else
 265:           throw new OBJECT_NOT_EXIST("Deactivated");
 266:       }
 267: 
 268:     LocalRequest rq = new LocalRequest(object, poa, Id);
 269:     rq.setOperation(method);
 270:     rq.setORB(orb(target));
 271:     return rq.getParameterStream();
 272:   }
 273: 
 274:   
 277:   public InvokeHandler getHandler(String method, CookieHolder cookie)
 278:   {
 279:     return object.getHandler(method, cookie, false);
 280:   }
 281: 
 282:   
 285:   public ORB orb(org.omg.CORBA.Object target)
 286:   {
 287:     return poa.orb();
 288:   }
 289: 
 290:   
 299:   public InputStream invoke(org.omg.CORBA.Object target, OutputStream output)
 300:     throws ApplicationException
 301:   {
 302:     try
 303:       {
 304:         StreamBasedRequest sr = (StreamBasedRequest) output;
 305: 
 306:         LocalRequest lr = (LocalRequest) sr.request;
 307:         InvokeHandler handler = lr.object.getHandler(lr.operation(), lr.cookie,
 308:           false);
 309: 
 310:         if (handler instanceof DynamicImpHandler)
 311:           {
 312:             
 313:             
 314:             lr.invoke();
 315: 
 316:             
 317:             AbstractCdrOutput buf = sr.createEncapsulation();
 318: 
 319:             
 320:             if (lr.env().exception() != null)
 321:               {
 322:                 try
 323:                   {
 324:                     UnknownUserException uex = (UnknownUserException) lr.env().exception();
 325:                     throw new ApplicationException(uex.except.type().id(),
 326:                       uex.except.create_input_stream());
 327:                   }
 328:                 catch (BadKind ex)
 329:                   {
 330:                     InternalError ierr = new InternalError();
 331:                     ierr.initCause(ex);
 332:                     throw ierr;
 333:                   }
 334:               }
 335:             if (lr.return_value() != null)
 336:               lr.return_value().write_value(buf);
 337: 
 338:             NamedValue a;
 339:             try
 340:               {
 341:                 for (int i = 0; i < lr.arguments().count(); i++)
 342:                   {
 343:                     a = lr.arguments().item(i);
 344:                     if (a.flags() == ARG_INOUT.value
 345:                       || a.flags() == ARG_INOUT.value)
 346:                       {
 347:                         a.value().write_value(buf);
 348:                       }
 349:                   }
 350:               }
 351:             catch (Bounds ex)
 352:               {
 353:                 InternalError ierr = new InternalError();
 354:                 ierr.initCause(ex);
 355:                 throw ierr;
 356:               }
 357: 
 358:             return buf.create_input_stream();
 359:           }
 360:         else
 361:           {
 362:             LocalRequest lrq = (LocalRequest) sr.request;
 363:             return lrq.s_invoke(handler);
 364:           }
 365:       }
 366:     catch (gnuForwardRequest f)
 367:       {
 368:         try
 369:           {
 370:             return ((ObjectImpl) f.forward_reference)._invoke(f.forward_reference._request(
 371:               operation, true));
 372:           }
 373:         catch (RemarshalException e)
 374:           {
 375:             
 376:             throw new NO_IMPLEMENT();
 377:           }
 378:       }
 379:   }
 380: 
 381:   public void releaseReply(org.omg.CORBA.Object target, InputStream input)
 382:   {
 383:     release(target);
 384:   }
 385: }