/**
   * Static method for writing a CORBA standard exception to a stream.
   *
   * @param strm The OutputStream to use for marshaling.
   */
  public static void writeSystemException(SystemException ex, OutputStream strm) {
    String s;

    s = repositoryIdOf(ex.getClass().getName());
    strm.write_string(s);
    strm.write_long(ex.minor);
    strm.write_long(ex.completed.value());
  }
 /**
  * Static method for writing a CORBA standard exception to an Any.
  *
  * @param any The Any to write the SystemException into.
  */
 public static void insertSystemException(SystemException ex, Any any) {
   OutputStream out = any.create_output_stream();
   ORB orb = (ORB) (out.orb());
   String name = ex.getClass().getName();
   String repID = ORBUtility.repositoryIdOf(name);
   out.write_string(repID);
   out.write_long(ex.minor);
   out.write_long(ex.completed.value());
   any.read_value(out.create_input_stream(), getSystemExceptionTypeCode(orb, repID, name));
 }
Example #3
0
  /**
   * Maps a SystemException to a RemoteException.
   *
   * @param ex the SystemException to map.
   * @return the mapped exception.
   */
  public RemoteException mapSystemException(SystemException ex) {
    if (ex instanceof UnknownException) {
      Throwable orig = ((UnknownException) ex).originalEx;
      if (orig instanceof Error) {
        return new ServerError("Error occurred in server thread", (Error) orig);
      } else if (orig instanceof RemoteException) {
        return new ServerException("RemoteException occurred in server thread", (Exception) orig);
      } else if (orig instanceof RuntimeException) {
        throw (RuntimeException) orig;
      }
    }

    // Build the message string...
    String name = ex.getClass().getName();
    String corbaName = name.substring(name.lastIndexOf('.') + 1);
    String status;
    switch (ex.completed.value()) {
      case CompletionStatus._COMPLETED_YES:
        status = "Yes";
        break;
      case CompletionStatus._COMPLETED_NO:
        status = "No";
        break;
      case CompletionStatus._COMPLETED_MAYBE:
      default:
        status = "Maybe";
        break;
    }

    String message = "CORBA " + corbaName + " " + ex.minor + " " + status;

    // Now map to the correct RemoteException type...
    if (ex instanceof COMM_FAILURE) {
      return new MarshalException(message, ex);
    } else if (ex instanceof INV_OBJREF) {
      RemoteException newEx = new NoSuchObjectException(message);
      newEx.detail = ex;
      return newEx;
    } else if (ex instanceof NO_PERMISSION) {
      return new AccessException(message, ex);
    } else if (ex instanceof MARSHAL) {
      return new MarshalException(message, ex);
    } else if (ex instanceof OBJECT_NOT_EXIST) {
      RemoteException newEx = new NoSuchObjectException(message);
      newEx.detail = ex;
      return newEx;
    } else if (ex instanceof TRANSACTION_REQUIRED) {
      RemoteException newEx = new TransactionRequiredException(message);
      newEx.detail = ex;
      return newEx;
    } else if (ex instanceof TRANSACTION_ROLLEDBACK) {
      RemoteException newEx = new TransactionRolledbackException(message);
      newEx.detail = ex;
      return newEx;
    } else if (ex instanceof INVALID_TRANSACTION) {
      RemoteException newEx = new InvalidTransactionException(message);
      newEx.detail = ex;
      return newEx;
    } else if (ex instanceof BAD_PARAM) {
      Exception inner = ex;

      // Pre-Merlin Sun ORBs used the incorrect minor code for
      // this case.  See Java to IDL ptc-00-01-08 1.4.8.
      if (ex.minor == ORBConstants.LEGACY_SUN_NOT_SERIALIZABLE
          || ex.minor == OMGSystemException.NOT_SERIALIZABLE) {

        if (ex.getMessage() != null) inner = new NotSerializableException(ex.getMessage());
        else inner = new NotSerializableException();

        inner.initCause(ex);
      }

      return new MarshalException(message, inner);
    } else if (ex instanceof ACTIVITY_REQUIRED) {
      try {
        Class<?> cl =
            SharedSecrets.getJavaCorbaAccess()
                .loadClass("javax.activity.ActivityRequiredException");
        Class[] params = new Class[2];
        params[0] = java.lang.String.class;
        params[1] = java.lang.Throwable.class;
        Constructor cr = cl.getConstructor(params);
        Object[] args = new Object[2];
        args[0] = message;
        args[1] = ex;
        return (RemoteException) cr.newInstance(args);
      } catch (Throwable e) {
        utilWrapper.classNotFound(e, "javax.activity.ActivityRequiredException");
      }
    } else if (ex instanceof ACTIVITY_COMPLETED) {
      try {
        Class<?> cl =
            SharedSecrets.getJavaCorbaAccess()
                .loadClass("javax.activity.ActivityCompletedException");
        Class[] params = new Class[2];
        params[0] = java.lang.String.class;
        params[1] = java.lang.Throwable.class;
        Constructor cr = cl.getConstructor(params);
        Object[] args = new Object[2];
        args[0] = message;
        args[1] = ex;
        return (RemoteException) cr.newInstance(args);
      } catch (Throwable e) {
        utilWrapper.classNotFound(e, "javax.activity.ActivityCompletedException");
      }
    } else if (ex instanceof INVALID_ACTIVITY) {
      try {
        Class<?> cl =
            SharedSecrets.getJavaCorbaAccess().loadClass("javax.activity.InvalidActivityException");
        Class[] params = new Class[2];
        params[0] = java.lang.String.class;
        params[1] = java.lang.Throwable.class;
        Constructor cr = cl.getConstructor(params);
        Object[] args = new Object[2];
        args[0] = message;
        args[1] = ex;
        return (RemoteException) cr.newInstance(args);
      } catch (Throwable e) {
        utilWrapper.classNotFound(e, "javax.activity.InvalidActivityException");
      }
    }

    // Just map to a generic RemoteException...
    return new RemoteException(message, ex);
  }