/**
   * Obtains an IOR for the object reference obj, first connecting it to the ORB if necessary.
   *
   * @return IOR the IOR that represents this objref. This will never be null.
   * @exception BAD_OPERATION if the object could not be connected, if a connection attempt was
   *     needed.
   * @exception BAD_PARAM if obj is a local object, or else was created by a foreign ORB.
   */
  public static IOR connectAndGetIOR(ORB orb, org.omg.CORBA.Object obj) {
    IOR result;
    try {
      result = getIOR(obj);
    } catch (BAD_OPERATION bop) {
      if (StubAdapter.isStub(obj)) {
        try {
          StubAdapter.connect(obj, orb);
        } catch (java.rmi.RemoteException exc) {
          throw wrapper.connectingServant(exc);
        }
      } else {
        orb.connect(obj);
      }

      result = getIOR(obj);
    }

    return result;
  }