Example #1
0
  /**
   * Writes any java.lang.Object as a CORBA any.
   *
   * @param out the stream in which to write the any.
   * @param obj the object to write as an any.
   */
  public void writeAny(org.omg.CORBA.portable.OutputStream out, java.lang.Object obj) {
    org.omg.CORBA.ORB orb = out.orb();

    // Create Any
    Any any = orb.create_any();

    // Make sure we have a connected object...
    java.lang.Object newObj = Utility.autoConnect(obj, orb, false);

    if (newObj instanceof org.omg.CORBA.Object) {
      any.insert_Object((org.omg.CORBA.Object) newObj);
    } else {
      if (newObj == null) {
        // Handle the null case, including backwards
        // compatibility issues
        any.insert_Value(null, createTypeCodeForNull(orb));
      } else {
        if (newObj instanceof Serializable) {
          // If they're our Any and ORB implementations,
          // we may want to do type code related versioning.
          TypeCode tc = createTypeCode((Serializable) newObj, any, orb);
          if (tc == null) any.insert_Value((Serializable) newObj);
          else any.insert_Value((Serializable) newObj, tc);
        } else if (newObj instanceof Remote) {
          ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
        } else {
          ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
        }
      }
    }

    out.write_any(any);
  }