public static void isValidReplyStatus(int replyStatus) {
   switch (replyStatus) {
     case NO_EXCEPTION:
     case USER_EXCEPTION:
     case SYSTEM_EXCEPTION:
     case LOCATION_FORWARD:
       break;
     default:
       ORBUtilSystemException localWrapper =
           ORBUtilSystemException.get(CORBALogDomains.RPC_PROTOCOL);
       throw localWrapper.illegalReplyStatus(CompletionStatus.COMPLETED_MAYBE);
   }
 }
 public static OutputStream request(Object stub, String operation, boolean responseExpected) {
   if (stub instanceof DynamicStub)
     return ((DynamicStub) stub).request(operation, responseExpected);
   else if (stub instanceof ObjectImpl)
     return ((ObjectImpl) stub)._request(operation, responseExpected);
   else throw wrapper.requestRequiresStub();
 }
 public static void connect(Object stub, ORB orb) throws java.rmi.RemoteException {
   if (stub instanceof DynamicStub)
     ((DynamicStub) stub).connect((org.jboss.com.sun.corba.se.spi.orb.ORB) orb);
   else if (stub instanceof javax.rmi.CORBA.Stub) ((javax.rmi.CORBA.Stub) stub).connect(orb);
   else if (stub instanceof ObjectImpl) orb.connect((org.omg.CORBA.Object) stub);
   else throw wrapper.connectRequiresStub();
 }
  public PresentationManager.StubFactory createStubFactory(
      String className,
      boolean isIDLStub,
      String remoteCodeBase,
      Class expectedClass,
      ClassLoader classLoader) {
    Class cls = null;

    try {
      cls = Util.loadClass(className, remoteCodeBase, classLoader);
    } catch (ClassNotFoundException exc) {
      throw wrapper.classNotFound3(CompletionStatus.COMPLETED_MAYBE, exc, className);
    }

    PresentationManager pm = ORB.getPresentationManager();

    if (IDLEntity.class.isAssignableFrom(cls) && !Remote.class.isAssignableFrom(cls)) {
      // IDL stubs must always use static factories.
      PresentationManager.StubFactoryFactory sff = pm.getStubFactoryFactory(false);
      PresentationManager.StubFactory sf =
          sff.createStubFactory(className, true, remoteCodeBase, expectedClass, classLoader);
      return sf;
    } else {
      PresentationManager.ClassData classData = pm.getClassData(cls);
      return makeDynamicStubFactory(pm, classData, classLoader);
    }
  }
 /** This also gets the delegate from a Servant by using Servant._this_object() */
 public static Delegate getDelegate(Object stub) {
   if (stub instanceof DynamicStub) return ((DynamicStub) stub).getDelegate();
   else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._get_delegate();
   else if (stub instanceof Tie) {
     Tie tie = (Tie) stub;
     org.omg.CORBA.Object ref = activateTie(tie);
     return getDelegate(ref);
   } else throw wrapper.getDelegateRequiresStub();
 }
 ReplyMessage_1_0(
     ORB orb, ServiceContexts _service_contexts, int _request_id, int _reply_status, IOR _ior) {
   super(Message.GIOPBigMagic, false, Message.GIOPReply, 0);
   this.orb = orb;
   this.wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_PROTOCOL);
   service_contexts = _service_contexts;
   request_id = _request_id;
   reply_status = _reply_status;
   ior = _ior;
 }
  /** Use implicit activation to get an object reference for the servant. */
  public static org.omg.CORBA.Object activateServant(Servant servant) {
    POA poa = servant._default_POA();
    org.omg.CORBA.Object ref = null;

    try {
      ref = poa.servant_to_reference(servant);
    } catch (ServantNotActive sna) {
      throw wrapper.getDelegateServantNotActive(sna);
    } catch (WrongPolicy wp) {
      throw wrapper.getDelegateWrongPolicy(wp);
    }

    // Make sure that the POAManager is activated if no other
    // POAManager state management has taken place.
    POAManager mgr = poa.the_POAManager();
    if (mgr instanceof POAManagerImpl) {
      POAManagerImpl mgrImpl = (POAManagerImpl) mgr;
      mgrImpl.implicitActivation();
    }

    return ref;
  }
 /**
  * Given any Tie, return the corresponding object refernce, activating the Servant if necessary.
  */
 public static org.omg.CORBA.Object activateTie(Tie tie) {
   /**
    * Any implementation of Tie should be either a Servant or an ObjectImpl, depending on which
    * style of code generation is used. rmic -iiop by default results in an ObjectImpl-based Tie,
    * while rmic -iiop -poa results in a Servant-based Tie. Dynamic RMI-IIOP also uses
    * Servant-based Ties (see impl.presentation.rmi.ReflectiveTie).
    */
   if (tie instanceof ObjectImpl) {
     return tie.thisObject();
   } else if (tie instanceof Servant) {
     Servant servant = (Servant) tie;
     return activateServant(servant);
   } else {
     throw wrapper.badActivateTieCall();
   }
 }
  public void read(org.omg.CORBA.portable.InputStream istream) {
    super.read(istream);
    this.service_contexts = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
    this.request_id = istream.read_ulong();
    this.reply_status = istream.read_long();
    isValidReplyStatus(this.reply_status); // raises exception on error

    // The code below reads the reply body in some cases
    // SYSTEM_EXCEPTION & LOCATION_FORWARD
    if (this.reply_status == SYSTEM_EXCEPTION) {

      String reposId = istream.read_string();
      this.exClassName = ORBUtility.classNameOf(reposId);
      this.minorCode = istream.read_long();
      int status = istream.read_long();

      switch (status) {
        case CompletionStatus._COMPLETED_YES:
          this.completionStatus = CompletionStatus.COMPLETED_YES;
          break;
        case CompletionStatus._COMPLETED_NO:
          this.completionStatus = CompletionStatus.COMPLETED_NO;
          break;
        case CompletionStatus._COMPLETED_MAYBE:
          this.completionStatus = CompletionStatus.COMPLETED_MAYBE;
          break;
        default:
          throw wrapper.badCompletionStatusInReply(
              CompletionStatus.COMPLETED_MAYBE, new Integer(status));
      }

    } else if (this.reply_status == USER_EXCEPTION) {
      // do nothing. The client stub will read the exception from body.
    } else if (this.reply_status == LOCATION_FORWARD) {
      CDRInputStream cdr = (CDRInputStream) istream;
      this.ior = IORFactories.makeIOR(cdr);
    }
  }
 public static void setDelegate(Object stub, Delegate delegate) {
   if (stub instanceof DynamicStub) ((DynamicStub) stub).setDelegate(delegate);
   else if (stub instanceof ObjectImpl) ((ObjectImpl) stub)._set_delegate(delegate);
   else throw wrapper.setDelegateRequiresStub();
 }
/**
 * Provide access to stub delegate and type id information independent of the stub type. This class
 * exists because ObjectImpl does not have an interface for the 3 delegate and type id methods, so a
 * DynamicStub has a different type. We cannot simply change ObjectImpl as it is a standard API. We
 * also cannot change the code generation of Stubs, as that is also standard. Hence I am left with
 * this ugly class.
 */
public abstract class StubAdapter {
  private StubAdapter() {}

  private static ORBUtilSystemException wrapper =
      ORBUtilSystemException.get(CORBALogDomains.RPC_PRESENTATION);

  public static boolean isStubClass(Class cls) {
    return (ObjectImpl.class.isAssignableFrom(cls)) || (DynamicStub.class.isAssignableFrom(cls));
  }

  public static boolean isStub(Object stub) {
    return (stub instanceof DynamicStub) || (stub instanceof ObjectImpl);
  }

  public static void setDelegate(Object stub, Delegate delegate) {
    if (stub instanceof DynamicStub) ((DynamicStub) stub).setDelegate(delegate);
    else if (stub instanceof ObjectImpl) ((ObjectImpl) stub)._set_delegate(delegate);
    else throw wrapper.setDelegateRequiresStub();
  }

  /** Use implicit activation to get an object reference for the servant. */
  public static org.omg.CORBA.Object activateServant(Servant servant) {
    POA poa = servant._default_POA();
    org.omg.CORBA.Object ref = null;

    try {
      ref = poa.servant_to_reference(servant);
    } catch (ServantNotActive sna) {
      throw wrapper.getDelegateServantNotActive(sna);
    } catch (WrongPolicy wp) {
      throw wrapper.getDelegateWrongPolicy(wp);
    }

    // Make sure that the POAManager is activated if no other
    // POAManager state management has taken place.
    POAManager mgr = poa.the_POAManager();
    if (mgr instanceof POAManagerImpl) {
      POAManagerImpl mgrImpl = (POAManagerImpl) mgr;
      mgrImpl.implicitActivation();
    }

    return ref;
  }

  /**
   * Given any Tie, return the corresponding object refernce, activating the Servant if necessary.
   */
  public static org.omg.CORBA.Object activateTie(Tie tie) {
    /**
     * Any implementation of Tie should be either a Servant or an ObjectImpl, depending on which
     * style of code generation is used. rmic -iiop by default results in an ObjectImpl-based Tie,
     * while rmic -iiop -poa results in a Servant-based Tie. Dynamic RMI-IIOP also uses
     * Servant-based Ties (see impl.presentation.rmi.ReflectiveTie).
     */
    if (tie instanceof ObjectImpl) {
      return tie.thisObject();
    } else if (tie instanceof Servant) {
      Servant servant = (Servant) tie;
      return activateServant(servant);
    } else {
      throw wrapper.badActivateTieCall();
    }
  }

  /** This also gets the delegate from a Servant by using Servant._this_object() */
  public static Delegate getDelegate(Object stub) {
    if (stub instanceof DynamicStub) return ((DynamicStub) stub).getDelegate();
    else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._get_delegate();
    else if (stub instanceof Tie) {
      Tie tie = (Tie) stub;
      org.omg.CORBA.Object ref = activateTie(tie);
      return getDelegate(ref);
    } else throw wrapper.getDelegateRequiresStub();
  }

  public static ORB getORB(Object stub) {
    if (stub instanceof DynamicStub) return ((DynamicStub) stub).getORB();
    else if (stub instanceof ObjectImpl) return (ORB) ((ObjectImpl) stub)._orb();
    else throw wrapper.getOrbRequiresStub();
  }

  public static String[] getTypeIds(Object stub) {
    if (stub instanceof DynamicStub) return ((DynamicStub) stub).getTypeIds();
    else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._ids();
    else throw wrapper.getTypeIdsRequiresStub();
  }

  public static void connect(Object stub, ORB orb) throws java.rmi.RemoteException {
    if (stub instanceof DynamicStub)
      ((DynamicStub) stub).connect((org.jboss.com.sun.corba.se.spi.orb.ORB) orb);
    else if (stub instanceof javax.rmi.CORBA.Stub) ((javax.rmi.CORBA.Stub) stub).connect(orb);
    else if (stub instanceof ObjectImpl) orb.connect((org.omg.CORBA.Object) stub);
    else throw wrapper.connectRequiresStub();
  }

  public static boolean isLocal(Object stub) {
    if (stub instanceof DynamicStub) return ((DynamicStub) stub).isLocal();
    else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._is_local();
    else throw wrapper.isLocalRequiresStub();
  }

  public static OutputStream request(Object stub, String operation, boolean responseExpected) {
    if (stub instanceof DynamicStub)
      return ((DynamicStub) stub).request(operation, responseExpected);
    else if (stub instanceof ObjectImpl)
      return ((ObjectImpl) stub)._request(operation, responseExpected);
    else throw wrapper.requestRequiresStub();
  }
}
 public static boolean isLocal(Object stub) {
   if (stub instanceof DynamicStub) return ((DynamicStub) stub).isLocal();
   else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._is_local();
   else throw wrapper.isLocalRequiresStub();
 }
 public ByteBufferWithInfo underflow(ByteBufferWithInfo bbwi) {
   throw wrapper.unexpectedEof();
 }
 public static ORB getORB(Object stub) {
   if (stub instanceof DynamicStub) return ((DynamicStub) stub).getORB();
   else if (stub instanceof ObjectImpl) return (ORB) ((ObjectImpl) stub)._orb();
   else throw wrapper.getOrbRequiresStub();
 }
 ReplyMessage_1_0(ORB orb) {
   this.orb = orb;
   this.wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_PROTOCOL);
 }
 public StubFactoryFactoryDynamicBase() {
   wrapper = ORBUtilSystemException.get(CORBALogDomains.RPC_PRESENTATION);
 }
 public static String[] getTypeIds(Object stub) {
   if (stub instanceof DynamicStub) return ((DynamicStub) stub).getTypeIds();
   else if (stub instanceof ObjectImpl) return ((ObjectImpl) stub)._ids();
   else throw wrapper.getTypeIdsRequiresStub();
 }
 BufferManagerReadGrow(ORB orb) {
   this.wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_ENCODING);
 }