Esempio n. 1
0
  private void checkExtractBadOperation(int expected) {
    if (!isInitialized) throw wrapper.extractNotInitialized();

    int tc = realType().kind().value();
    if (tc != expected) {
      String tcName = getTCKindName(tc);
      String expectedName = getTCKindName(expected);
      throw wrapper.extractWrongType(expectedName, tcName);
    }
  }
Esempio n. 2
0
 public static void isValidReplyStatus(int replyStatus) {
   switch (replyStatus) {
     case UNKNOWN_OBJECT:
     case OBJECT_HERE:
     case OBJECT_FORWARD:
       break;
     default:
       ORBUtilSystemException localWrapper =
           ORBUtilSystemException.get(CORBALogDomains.RPC_PROTOCOL);
       throw localWrapper.illegalReplyStatus(CompletionStatus.COMPLETED_MAYBE);
   }
 }
Esempio n. 3
0
  private void checkExtractBadOperationList(int[] expected) {
    if (!isInitialized) throw wrapper.extractNotInitialized();

    int tc = realType().kind().value();
    for (int ctr = 0; ctr < expected.length; ctr++) if (tc == expected[ctr]) return;

    List list = new ArrayList();
    for (int ctr = 0; ctr < expected.length; ctr++) list.add(getTCKindName(expected[ctr]));

    String tcName = getTCKindName(tc);
    throw wrapper.extractWrongTypeList(list, tcName);
  }
Esempio n. 4
0
 public void insert_fixed(java.math.BigDecimal value, org.omg.CORBA.TypeCode type) {
   try {
     if (TypeCodeImpl.digits(value) > type.fixed_digits()
         || TypeCodeImpl.scale(value) > type.fixed_scale()) {
       throw wrapper.fixedNotMatch();
     }
   } catch (org.omg.CORBA.TypeCodePackage.BadKind bk) {
     // type isn't even of kind fixed
     throw wrapper.fixedBadTypecode(bk);
   }
   typeCode = TypeCodeImpl.convertToNative(orb, type);
   object = value;
   isInitialized = true;
 }
Esempio n. 5
0
 /** A variant of the insertion operation that takes a typecode argument as well. */
 public void insert_Object(org.omg.CORBA.Object o, TypeCode tc) {
   // debug.log ("insert_Object2");
   try {
     if (tc.id().equals("IDL:omg.org/CORBA/Object:1.0") || o._is_a(tc.id())) {
       typeCode = TypeCodeImpl.convertToNative(orb, tc);
       object = o;
     } else {
       throw wrapper.insertObjectIncompatible();
     }
   } catch (Exception ex) {
     throw wrapper.insertObjectFailed(ex);
   }
   isInitialized = true;
 }
Esempio n. 6
0
  public void registerInterestOps(EventHandler eventHandler) {
    if (orb.transportDebugFlag) {
      dprint(".registerInterestOps:-> " + eventHandler);
    }

    SelectionKey selectionKey = eventHandler.getSelectionKey();
    if (selectionKey.isValid()) {
      int ehOps = eventHandler.getInterestOps();
      SelectionKeyAndOp keyAndOp = new SelectionKeyAndOp(selectionKey, ehOps);
      synchronized (interestOpsList) {
        interestOpsList.add(keyAndOp);
      }
      // tell Selector Thread there's an update to a SelectorKey's Ops
      selector.wakeup();
    } else {
      wrapper.selectionKeyInvalid(eventHandler.toString());
      if (orb.transportDebugFlag) {
        dprint(".registerInterestOps: EventHandler SelectionKey not valid " + eventHandler);
      }
    }

    if (orb.transportDebugFlag) {
      dprint(".registerInterestOps:<- ");
    }
  }
Esempio n. 7
0
 public ObjectAdapter find(ObjectAdapterId oaid) {
   if (oaid.equals(ObjectKeyTemplateBase.JIDL_OAID))
     // Return the dispatch-only TOA, which can dispatch
     // request for objects created by any TOA.
     return getTOA();
   else throw wrapper.badToaOaid();
 }
 public static SystemException extractSystemException(Any any) {
   InputStream in = any.create_input_stream();
   ORB orb = (ORB) (in.orb());
   if (!isSystemExceptionTypeCode(any.type(), orb)) {
     throw wrapper.unknownDsiSysex(CompletionStatus.COMPLETED_MAYBE);
   }
   return ORBUtility.readSystemException(in);
 }
Esempio n. 9
0
  /** See the description of the <a href="#anyOps">general Any operations.</a> */
  public org.omg.CORBA.Object extract_Object() {
    // debug.log ("extract_Object");
    if (!isInitialized) throw wrapper.extractNotInitialized();

    // Check if the object contained here is of the type in typeCode
    org.omg.CORBA.Object obj = null;
    try {
      obj = (org.omg.CORBA.Object) object;
      if (typeCode.id().equals("IDL:omg.org/CORBA/Object:1.0") || obj._is_a(typeCode.id())) {
        return obj;
      } else {
        throw wrapper.extractObjectIncompatible();
      }
    } catch (Exception ex) {
      throw wrapper.extractObjectFailed(ex);
    }
  }
Esempio n. 10
0
 public CacheTable(ORB orb, boolean u) {
   // System.out.println("using new cache table");
   this.orb = orb;
   wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_ENCODING);
   noReverseMap = u;
   size = INITIAL_SIZE;
   entryCount = 0;
   initTables();
 }
 /**
  * Static method for reading a CORBA standard exception from a stream.
  *
  * @param strm The InputStream to use for unmarshaling.
  */
 public static SystemException readSystemException(InputStream strm) {
   try {
     String name = classNameOf(strm.read_string());
     SystemException ex = (SystemException) ORBClassLoader.loadClass(name).newInstance();
     ex.minor = strm.read_long();
     ex.completed = CompletionStatus.from_int(strm.read_long());
     return ex;
   } catch (Exception ex) {
     throw wrapper.unknownSysex(CompletionStatus.COMPLETED_MAYBE, ex);
   }
 }
Esempio n. 12
0
 /*      */ public AnyImpl(ORB paramORB) /*      */ {
   /*  177 */ this.orb = paramORB;
   /*  178 */ this.wrapper = ORBUtilSystemException.get(paramORB, "rpc.presentation");
   /*      */
   /*  181 */ this.typeCode = paramORB.get_primitive_tc(0);
   /*  182 */ this.stream = null;
   /*  183 */ this.object = null;
   /*  184 */ this.value = 0L;
   /*      */
   /*  186 */ this.isInitialized = true;
   /*      */ }
Esempio n. 13
0
 public SelectorImpl(ORB orb) {
   this.orb = orb;
   selector = null;
   selectorStarted = false;
   timeout = 60000;
   deferredRegistrations = new ArrayList();
   interestOpsList = new ArrayList();
   listenerThreads = new HashMap();
   readerThreads = java.util.Collections.synchronizedMap(new HashMap());
   closed = false;
   wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_TRANSPORT);
 }
Esempio n. 14
0
 private TypeCode realType(TypeCode aType) {
   TypeCode realType = aType;
   try {
     // Note: Indirect types are handled in kind() method
     while (realType.kind().value() == TCKind._tk_alias) {
       realType = realType.content_type();
     }
   } catch (BadKind bad) { // impossible
     throw wrapper.badkindCannotOccur(bad);
   }
   return realType;
 }
Esempio n. 15
0
  /** See the description of the <a href="#anyOps">general Any operations.</a> */
  public void insert_wstring(String s) {
    // debug.log ("insert_wstring");
    // Make sure type code information for bounded strings is not erased
    if (typeCode.kind() == TCKind.tk_wstring) {
      int length = 0;
      try {
        length = typeCode.length();
      } catch (BadKind bad) {
        throw wrapper.badkindCannotOccur();
      }

      // Check if bounded strings length is not exceeded
      if (length != 0 && s != null && s.length() > length) {
        throw wrapper.badStringBounds(new Integer(s.length()), new Integer(length));
      }
    } else {
      typeCode = orb.get_primitive_tc(TCKind._tk_wstring);
    }
    object = s;
    isInitialized = true;
  }
Esempio n. 16
0
  /**
   * A constructor that sets the Any to contain a null. It also marks the value as being invalid so
   * that extractions throw an exception until an insertion has been performed.
   */
  public AnyImpl(ORB orb) {
    this.orb = orb;
    wrapper =
        ORBUtilSystemException.get(
            (com.sun.corba.se.spi.orb.ORB) orb, CORBALogDomains.RPC_PRESENTATION);

    typeCode = orb.get_primitive_tc(TCKind._tk_null);
    stream = null;
    object = null;
    value = 0;
    // null is a valid value
    isInitialized = true;
  }
  /**
   * This method obtains an IOR from a CORBA object reference. It will return null if obj is a local
   * object, a null object, or an object implemented by a different ORB. It will throw BAD_OPERATION
   * if obj is an unconnected RMI-IIOP object.
   *
   * @return IOR the IOR that represents this objref. This will never be null.
   * @exception BAD_OPERATION (from oi._get_delegate) if obj is a normal objref, but does not have a
   *     delegate set.
   * @exception BAD_PARAM if obj is a local object, or else was created by a foreign ORB.
   */
  public static IOR getIOR(org.omg.CORBA.Object obj) {
    if (obj == null) throw wrapper.nullObjectReference();

    IOR ior = null;
    if (StubAdapter.isStub(obj)) {
      org.omg.CORBA.portable.Delegate del = StubAdapter.getDelegate(obj);

      if (del instanceof CorbaClientDelegate) {
        CorbaClientDelegate cdel = (CorbaClientDelegate) del;
        ContactInfoList cil = cdel.getContactInfoList();

        if (cil instanceof CorbaContactInfoList) {
          CorbaContactInfoList ccil = (CorbaContactInfoList) cil;
          ior = ccil.getTargetIOR();
          if (ior == null) throw wrapper.nullIor();

          return ior;
        } else {
          // This is our code, but the ContactInfoList is not a
          // CorbaContactInfoList.  This should not happen, because
          // we are in the CORBA application of the DCSA framework.
          // This is a coding error, and thus an INTERNAL exception
          // should be thrown.
          // XXX needs minor code
          throw new INTERNAL();
        }
      }

      // obj is implemented by a foreign ORB, because the Delegate is not a
      // ClientDelegate.
      // XXX this case could be handled by marshalling and
      // unmarshalling.  However, object_to_string cannot be used
      // here, as it is implemented with getIOR.  Note that this
      // will require access to an ORB, so that we can create streams
      // as needed.  The ORB is available simply as io._orb().
      throw wrapper.objrefFromForeignOrb();
    } else throw wrapper.localObjectNotAllowed();
  }
  /** Converts an Ascii Character into Hexadecimal digit */
  public static int hexOf(char x) {
    int val;

    val = x - '0';
    if (val >= 0 && val <= 9) return val;

    val = (x - 'a') + 10;
    if (val >= 10 && val <= 15) return val;

    val = (x - 'A') + 10;
    if (val >= 10 && val <= 15) return val;

    throw wrapper.badHexDigit();
  }
Esempio n. 19
0
  /** See the description of the <a href="#anyOps">general Any operations.</a> */
  public void insert_Object(org.omg.CORBA.Object o) {
    // debug.log ("insert_Object");
    if (o == null) {
      typeCode = orb.get_primitive_tc(TCKind._tk_objref);
    } else {
      if (StubAdapter.isStub(o)) {
        String[] ids = StubAdapter.getTypeIds(o);
        typeCode = new TypeCodeImpl(orb, TCKind._tk_objref, ids[0], "");
      } else {
        throw wrapper.badInsertobjParam(CompletionStatus.COMPLETED_MAYBE, o.getClass().getName());
      }
    }

    object = o;
    isInitialized = true;
  }
  /**
   * 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;
  }
Esempio n. 21
0
  //
  // If the InputStream is a CDRInputStream then we can copy the bytes
  // since it is in our format and does not have alignment issues.
  //
  public void read_value(org.omg.CORBA.portable.InputStream in, TypeCode tc) {
    // debug.log ("read_value");
    //
    // Assume that someone isn't going to think they can keep reading
    // from this stream after calling us. That would be likely for
    // an IIOPInputStream but if it is an AnyInputStream then they
    // presumably obtained it via our create_output_stream() so they could
    // write the contents of an IDL data type to it and then call
    // create_input_stream() for us to read it. This is how Helper classes
    // typically implement the insert() method.
    // We should probably document this behavior in the 1.1 revision
    // task force.
    //

    typeCode = TypeCodeImpl.convertToNative(orb, tc);
    int kind = realType().kind().value();
    if (kind >= isStreamed.length) {
      throw wrapper.invalidIsstreamedTckind(CompletionStatus.COMPLETED_MAYBE, new Integer(kind));
    }

    if (AnyImpl.isStreamed[kind]) {
      if (in instanceof AnyInputStream) {
        // could only have been created here
        stream = (CDRInputStream) in;
      } else {
        org.omg.CORBA_2_3.portable.OutputStream out =
            (org.omg.CORBA_2_3.portable.OutputStream) orb.create_output_stream();
        typeCode.copy((org.omg.CORBA_2_3.portable.InputStream) in, out);
        stream = (CDRInputStream) out.create_input_stream();
      }
    } else {
      java.lang.Object[] objholder = new java.lang.Object[1];
      objholder[0] = object;
      long[] longholder = new long[1];
      TCUtility.unmarshalIn(in, realType(), longholder, objholder);
      value = longholder[0];
      object = objholder[0];
      stream = null;
    }
    isInitialized = true;
  }
Esempio n. 22
0
 private boolean put_table(java.lang.Object key, int val) {
   int index = hash(key);
   for (Entry e = map[index]; e != null; e = e.next) {
     if (e.key == key) {
       if (e.val != val) {
         throw wrapper.duplicateIndirectionOffset();
       }
       // if we get here we are trying to put in the same key/val pair
       // this is a no-op, so we just return
       return false;
     }
   }
   // this means the key is not present in our table
   // then it shouldnt be present in our reverse table either
   Entry newEntry = new Entry(key, val);
   newEntry.next = map[index];
   map[index] = newEntry;
   if (!noReverseMap) {
     int rindex = hash(val);
     newEntry.rnext = rmap[rindex];
     rmap[rindex] = newEntry;
   }
   return true;
 }
Esempio n. 23
0
 BufferManagerWrite(ORB orb) {
   this.orb = orb;
   this.wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.RPC_ENCODING);
 }
Esempio n. 24
0
  static void unmarshalIn(
      org.omg.CORBA.portable.InputStream s, TypeCode typeCode, long[] la, Object[] oa) {
    int type = typeCode.kind().value();
    long l = 0;
    Object o = oa[0];

    switch (type) {
      case TCKind._tk_null:
      case TCKind._tk_void:
      case TCKind._tk_native:
        // Nothing to read
        break;

      case TCKind._tk_short:
        l = s.read_short() & 0xFFFFL;
        break;

      case TCKind._tk_ushort:
        l = s.read_ushort() & 0xFFFFL;
        break;

      case TCKind._tk_enum:
      case TCKind._tk_long:
        l = s.read_long() & 0xFFFFFFFFL;
        break;

      case TCKind._tk_ulong:
        l = s.read_ulong() & 0xFFFFFFFFL;
        break;

      case TCKind._tk_float:
        l = Float.floatToIntBits(s.read_float()) & 0xFFFFFFFFL;
        break;

      case TCKind._tk_double:
        l = Double.doubleToLongBits(s.read_double());
        break;

      case TCKind._tk_char:
        l = s.read_char() & 0xFFFFL;
        break;

      case TCKind._tk_octet:
        l = s.read_octet() & 0xFFL;
        break;

      case TCKind._tk_boolean:
        if (s.read_boolean()) l = 1;
        else l = 0;
        break;

      case TCKind._tk_any:
        o = s.read_any();
        break;

      case TCKind._tk_TypeCode:
        o = s.read_TypeCode();
        break;

      case TCKind._tk_Principal:
        o = s.read_Principal();
        break;

      case TCKind._tk_objref:
        if (o instanceof Streamable) ((Streamable) o)._read(s);
        else o = s.read_Object();
        break;

      case TCKind._tk_longlong:
        l = s.read_longlong();
        break;

      case TCKind._tk_ulonglong:
        l = s.read_ulonglong();
        break;

      case TCKind._tk_wchar:
        l = s.read_wchar() & 0xFFFFL;
        break;

      case TCKind._tk_string:
        o = s.read_string();
        break;

      case TCKind._tk_wstring:
        o = s.read_wstring();
        break;

      case TCKind._tk_value:
      case TCKind._tk_value_box:
        o = ((org.omg.CORBA_2_3.portable.InputStream) s).read_value();
        break;

      case TCKind._tk_fixed:
        try {
          // _REVISIT_ As soon as the java-rtf adds digits and scale parameters to
          // InputStream, this check will be unnecessary
          if (s instanceof CDRInputStream) {
            o = ((CDRInputStream) s).read_fixed(typeCode.fixed_digits(), typeCode.fixed_scale());
          } else {
            BigDecimal bigDecimal = s.read_fixed();
            o = bigDecimal.movePointLeft((int) typeCode.fixed_scale());
          }
        } catch (BadKind badKind) { // impossible
        }
        break;

      case TCKind._tk_struct:
      case TCKind._tk_union:
      case TCKind._tk_sequence:
      case TCKind._tk_array:
      case TCKind._tk_alias:
      case TCKind._tk_except:
        ((Streamable) o)._read(s);
        break;

      case TCKind._tk_abstract_interface:
        o = ((org.omg.CORBA_2_3.portable.InputStream) s).read_abstract_interface();
        break;

      case TCKind._tk_longdouble:
        // Unspecified for Java
      default:
        ORBUtilSystemException wrapper =
            ORBUtilSystemException.get(
                (com.sun.corba.se.spi.orb.ORB) s.orb(), CORBALogDomains.RPC_PRESENTATION);
        throw wrapper.typecodeNotSupported();
    }

    oa[0] = o;
    la[0] = l;
  }
Esempio n. 25
0
  static void marshalIn(
      org.omg.CORBA.portable.OutputStream s, TypeCode typeCode, long l, Object o) {
    switch (typeCode.kind().value()) {
      case TCKind._tk_null:
      case TCKind._tk_void:
      case TCKind._tk_native:
        // nothing to write
        break;

      case TCKind._tk_short:
        s.write_short((short) (l & 0xFFFFL));
        break;

      case TCKind._tk_ushort:
        s.write_ushort((short) (l & 0xFFFFL));
        break;

      case TCKind._tk_enum:
      case TCKind._tk_long:
        s.write_long((int) (l & 0xFFFFFFFFL));
        break;

      case TCKind._tk_ulong:
        s.write_ulong((int) (l & 0xFFFFFFFFL));
        break;

      case TCKind._tk_float:
        s.write_float(Float.intBitsToFloat((int) (l & 0xFFFFFFFFL)));
        break;

      case TCKind._tk_double:
        s.write_double(Double.longBitsToDouble(l));
        break;

      case TCKind._tk_boolean:
        if (l == 0) s.write_boolean(false);
        else s.write_boolean(true);
        break;

      case TCKind._tk_char:
        s.write_char((char) (l & 0xFFFFL));
        break;

      case TCKind._tk_octet:
        s.write_octet((byte) (l & 0xFFL));
        break;

      case TCKind._tk_any:
        s.write_any((Any) o);
        break;

      case TCKind._tk_TypeCode:
        s.write_TypeCode((TypeCode) o);
        break;

      case TCKind._tk_Principal:
        s.write_Principal((Principal) o);
        break;

      case TCKind._tk_objref:
        s.write_Object((org.omg.CORBA.Object) o);
        break;

      case TCKind._tk_longlong:
        s.write_longlong(l);
        break;

      case TCKind._tk_ulonglong:
        s.write_ulonglong(l);
        break;

      case TCKind._tk_wchar:
        s.write_wchar((char) (l & 0xFFFFL));
        break;

      case TCKind._tk_string:
        s.write_string((String) o);
        break;

      case TCKind._tk_wstring:
        s.write_wstring((String) o);
        break;

      case TCKind._tk_value:
      case TCKind._tk_value_box:
        ((org.omg.CORBA_2_3.portable.OutputStream) s).write_value((Serializable) o);
        break;

      case TCKind._tk_fixed:
        // _REVISIT_ As soon as the java-rtf adds digits and scale parameters to
        // OutputStream, this check will be unnecessary
        if (s instanceof CDROutputStream) {
          try {
            ((CDROutputStream) s)
                .write_fixed((BigDecimal) o, typeCode.fixed_digits(), typeCode.fixed_scale());
          } catch (BadKind badKind) { // impossible
          }
        } else {
          s.write_fixed((BigDecimal) o);
        }
        break;

      case TCKind._tk_struct:
      case TCKind._tk_union:
      case TCKind._tk_sequence:
      case TCKind._tk_array:
      case TCKind._tk_alias:
      case TCKind._tk_except:
        ((Streamable) o)._write(s);
        break;

      case TCKind._tk_abstract_interface:
        ((org.omg.CORBA_2_3.portable.OutputStream) s).write_abstract_interface(o);
        break;

      case TCKind._tk_longdouble:
        // Unspecified for Java
      default:
        ORBUtilSystemException wrapper =
            ORBUtilSystemException.get(
                (com.sun.corba.se.spi.orb.ORB) s.orb(), CORBALogDomains.RPC_PRESENTATION);
        throw wrapper.typecodeNotSupported();
    }
  }
Esempio n. 26
0
  // Needed for equal() in order to achieve linear performance for complex types.
  // Uses up (recursively) copies of the InputStream in both Anys that got created in equal().
  private boolean equalMember(TypeCode memberType, InputStream myStream, InputStream otherStream) {
    // Resolve aliases here
    TypeCode realType = realType(memberType);

    try {
      switch (realType.kind().value()) {
          // handle primitive types
        case TCKind._tk_null:
        case TCKind._tk_void:
          return true;
        case TCKind._tk_short:
          return (myStream.read_short() == otherStream.read_short());
        case TCKind._tk_long:
          return (myStream.read_long() == otherStream.read_long());
        case TCKind._tk_ushort:
          return (myStream.read_ushort() == otherStream.read_ushort());
        case TCKind._tk_ulong:
          return (myStream.read_ulong() == otherStream.read_ulong());
        case TCKind._tk_float:
          return (myStream.read_float() == otherStream.read_float());
        case TCKind._tk_double:
          return (myStream.read_double() == otherStream.read_double());
        case TCKind._tk_boolean:
          return (myStream.read_boolean() == otherStream.read_boolean());
        case TCKind._tk_char:
          return (myStream.read_char() == otherStream.read_char());
        case TCKind._tk_wchar:
          return (myStream.read_wchar() == otherStream.read_wchar());
        case TCKind._tk_octet:
          return (myStream.read_octet() == otherStream.read_octet());
        case TCKind._tk_any:
          return myStream.read_any().equal(otherStream.read_any());
        case TCKind._tk_TypeCode:
          return myStream.read_TypeCode().equal(otherStream.read_TypeCode());
        case TCKind._tk_string:
          return myStream.read_string().equals(otherStream.read_string());
        case TCKind._tk_wstring:
          return (myStream.read_wstring().equals(otherStream.read_wstring()));
        case TCKind._tk_longlong:
          return (myStream.read_longlong() == otherStream.read_longlong());
        case TCKind._tk_ulonglong:
          return (myStream.read_ulonglong() == otherStream.read_ulonglong());

        case TCKind._tk_objref:
          return (myStream.read_Object().equals(otherStream.read_Object()));
        case TCKind._tk_Principal:
          return (myStream.read_Principal().equals(otherStream.read_Principal()));

        case TCKind._tk_enum:
          return (myStream.read_long() == otherStream.read_long());
        case TCKind._tk_fixed:
          return (myStream.read_fixed().compareTo(otherStream.read_fixed()) == 0);
        case TCKind._tk_except:
        case TCKind._tk_struct:
          {
            int length = realType.member_count();
            for (int i = 0; i < length; i++) {
              if (!equalMember(realType.member_type(i), myStream, otherStream)) {
                return false;
              }
            }
            return true;
          }
        case TCKind._tk_union:
          {
            Any myDiscriminator = orb.create_any();
            Any otherDiscriminator = orb.create_any();
            myDiscriminator.read_value(myStream, realType.discriminator_type());
            otherDiscriminator.read_value(otherStream, realType.discriminator_type());

            if (!myDiscriminator.equal(otherDiscriminator)) {
              return false;
            }
            TypeCodeImpl realTypeCodeImpl = TypeCodeImpl.convertToNative(orb, realType);
            int memberIndex = realTypeCodeImpl.currentUnionMemberIndex(myDiscriminator);
            if (memberIndex == -1) throw wrapper.unionDiscriminatorError();

            if (!equalMember(realType.member_type(memberIndex), myStream, otherStream)) {
              return false;
            }
            return true;
          }
        case TCKind._tk_sequence:
          {
            int length = myStream.read_long();
            otherStream.read_long(); // just so that the two stream are in sync
            for (int i = 0; i < length; i++) {
              if (!equalMember(realType.content_type(), myStream, otherStream)) {
                return false;
              }
            }
            return true;
          }
        case TCKind._tk_array:
          {
            int length = realType.member_count();
            for (int i = 0; i < length; i++) {
              if (!equalMember(realType.content_type(), myStream, otherStream)) {
                return false;
              }
            }
            return true;
          }

          // Too complicated to handle value types the way we handle
          // other complex types above. Don't try to decompose it here
          // for faster comparison, just use Object.equals().
        case TCKind._tk_value:
        case TCKind._tk_value_box:
          org.omg.CORBA_2_3.portable.InputStream mine =
              (org.omg.CORBA_2_3.portable.InputStream) myStream;
          org.omg.CORBA_2_3.portable.InputStream other =
              (org.omg.CORBA_2_3.portable.InputStream) otherStream;
          return mine.read_value().equals(other.read_value());

        case TCKind._tk_alias:
          // error resolving alias above
          throw wrapper.errorResolvingAlias();

        case TCKind._tk_longdouble:
          throw wrapper.tkLongDoubleNotSupported();

        default:
          throw wrapper.typecodeNotSupported();
      }
    } catch (BadKind badKind) { // impossible
      throw wrapper.badkindCannotOccur();
    } catch (Bounds bounds) { // impossible
      throw wrapper.boundsCannotOccur();
    }
  }
Esempio n. 27
0
  /**
   * checks for equality between Anys.
   *
   * @param otherAny the Any to be compared with.
   * @result true if the Anys are equal, false otherwise.
   */
  public boolean equal(Any otherAny) {
    // debug.log ("equal");

    if (otherAny == this) return true;

    // first check for typecode equality.
    // note that this will take aliases into account
    if (!typeCode.equal(otherAny.type())) return false;

    // Resolve aliases here
    TypeCode realType = realType();

    // _REVISIT_ Possible optimization for the case where
    // otherAny is a AnyImpl and the endianesses match.
    // Need implementation of CDRInputStream.equals()
    // For now we disable this to encourage testing the generic,
    // unoptimized code below.
    // Unfortunately this generic code needs to copy the whole stream
    // at least once.
    //    if (AnyImpl.isStreamed[realType.kind().value()]) {
    //        if (otherAny instanceof AnyImpl) {
    //            return ((AnyImpl)otherAny).stream.equals(stream);
    //        }
    //    }
    switch (realType.kind().value()) {
        // handle primitive types
      case TCKind._tk_null:
      case TCKind._tk_void:
        return true;
      case TCKind._tk_short:
        return (extract_short() == otherAny.extract_short());
      case TCKind._tk_long:
        return (extract_long() == otherAny.extract_long());
      case TCKind._tk_ushort:
        return (extract_ushort() == otherAny.extract_ushort());
      case TCKind._tk_ulong:
        return (extract_ulong() == otherAny.extract_ulong());
      case TCKind._tk_float:
        return (extract_float() == otherAny.extract_float());
      case TCKind._tk_double:
        return (extract_double() == otherAny.extract_double());
      case TCKind._tk_boolean:
        return (extract_boolean() == otherAny.extract_boolean());
      case TCKind._tk_char:
        return (extract_char() == otherAny.extract_char());
      case TCKind._tk_wchar:
        return (extract_wchar() == otherAny.extract_wchar());
      case TCKind._tk_octet:
        return (extract_octet() == otherAny.extract_octet());
      case TCKind._tk_any:
        return extract_any().equal(otherAny.extract_any());
      case TCKind._tk_TypeCode:
        return extract_TypeCode().equal(otherAny.extract_TypeCode());
      case TCKind._tk_string:
        return extract_string().equals(otherAny.extract_string());
      case TCKind._tk_wstring:
        return (extract_wstring().equals(otherAny.extract_wstring()));
      case TCKind._tk_longlong:
        return (extract_longlong() == otherAny.extract_longlong());
      case TCKind._tk_ulonglong:
        return (extract_ulonglong() == otherAny.extract_ulonglong());

      case TCKind._tk_objref:
        return (extract_Object().equals(otherAny.extract_Object()));
      case TCKind._tk_Principal:
        return (extract_Principal().equals(otherAny.extract_Principal()));

      case TCKind._tk_enum:
        return (extract_long() == otherAny.extract_long());
      case TCKind._tk_fixed:
        return (extract_fixed().compareTo(otherAny.extract_fixed()) == 0);
      case TCKind._tk_except:
      case TCKind._tk_struct:
      case TCKind._tk_union:
      case TCKind._tk_sequence:
      case TCKind._tk_array:
        InputStream copyOfMyStream = this.create_input_stream();
        InputStream copyOfOtherStream = otherAny.create_input_stream();
        return equalMember(realType, copyOfMyStream, copyOfOtherStream);

        // Too complicated to handle value types the way we handle
        // other complex types above. Don't try to decompose it here
        // for faster comparison, just use Object.equals().
      case TCKind._tk_value:
      case TCKind._tk_value_box:
        return extract_Value().equals(otherAny.extract_Value());

      case TCKind._tk_alias:
        throw wrapper.errorResolvingAlias();

      case TCKind._tk_longdouble:
        // Unspecified for Java
        throw wrapper.tkLongDoubleNotSupported();

      default:
        throw wrapper.typecodeNotSupported();
    }
  }
Esempio n. 28
0
 public void init(ORB orb) {
   this.orb = orb;
   wrapper = ORBUtilSystemException.get(orb, CORBALogDomains.OA_LIFECYCLE);
   tom = new TransientObjectManager(orb);
   codebaseToTOA = new HashMap();
 }
/** Handy class full of static functions that don't belong in util.Utility for pure ORB reasons. */
public final class ORBUtility {
  private ORBUtility() {}

  private static ORBUtilSystemException wrapper = ORBUtilSystemException.get(CORBALogDomains.UTIL);
  private static OMGSystemException omgWrapper = OMGSystemException.get(CORBALogDomains.UTIL);

  private static StructMember[] members = null;

  private static StructMember[] systemExceptionMembers(ORB orb) {
    if (members == null) {
      members = new StructMember[3];
      members[0] = new StructMember("id", orb.create_string_tc(0), null);
      members[1] = new StructMember("minor", orb.get_primitive_tc(TCKind.tk_long), null);
      members[2] = new StructMember("completed", orb.get_primitive_tc(TCKind.tk_long), null);
    }
    return members;
  }

  private static TypeCode getSystemExceptionTypeCode(ORB orb, String repID, String name) {
    synchronized (TypeCode.class) {
      return orb.create_exception_tc(repID, name, systemExceptionMembers(orb));
    }
  }

  private static boolean isSystemExceptionTypeCode(TypeCode type, ORB orb) {
    StructMember[] systemExceptionMembers = systemExceptionMembers(orb);
    try {
      return (type.kind().value() == TCKind._tk_except
          && type.member_count() == 3
          && type.member_type(0).equal(systemExceptionMembers[0].type)
          && type.member_type(1).equal(systemExceptionMembers[1].type)
          && type.member_type(2).equal(systemExceptionMembers[2].type));
    } catch (BadKind ex) {
      return false;
    } catch (org.omg.CORBA.TypeCodePackage.Bounds ex) {
      return false;
    }
  }

  /**
   * 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));
  }

  public static SystemException extractSystemException(Any any) {
    InputStream in = any.create_input_stream();
    ORB orb = (ORB) (in.orb());
    if (!isSystemExceptionTypeCode(any.type(), orb)) {
      throw wrapper.unknownDsiSysex(CompletionStatus.COMPLETED_MAYBE);
    }
    return ORBUtility.readSystemException(in);
  }

  /** Return default ValueHandler */
  public static ValueHandler createValueHandler() {
    return Util.createValueHandler();
  }

  /**
   * Returns true if it was accurately determined that the remote ORB is a foreign (non-JavaSoft)
   * ORB. Note: If passed the ORBSingleton, this will return false.
   */
  public static boolean isForeignORB(ORB orb) {
    if (orb == null) return false;

    try {
      return orb.getORBVersion().equals(ORBVersionFactory.getFOREIGN());
    } catch (SecurityException se) {
      return false;
    }
  }

  /**
   * Unmarshal a byte array to an integer. Assume the bytes are in BIGENDIAN order. i.e.
   * array[offset] is the most-significant-byte and array[offset+3] is the least-significant-byte.
   *
   * @param array The array of bytes.
   * @param offset The offset from which to start unmarshalling.
   */
  public static int bytesToInt(byte[] array, int offset) {
    int b1, b2, b3, b4;

    b1 = (array[offset++] << 24) & 0xFF000000;
    b2 = (array[offset++] << 16) & 0x00FF0000;
    b3 = (array[offset++] << 8) & 0x0000FF00;
    b4 = (array[offset++] << 0) & 0x000000FF;

    return (b1 | b2 | b3 | b4);
  }

  /**
   * Marshal an integer to a byte array. The bytes are in BIGENDIAN order. i.e. array[offset] is the
   * most-significant-byte and array[offset+3] is the least-significant-byte.
   *
   * @param array The array of bytes.
   * @param offset The offset from which to start marshalling.
   */
  public static void intToBytes(int value, byte[] array, int offset) {
    array[offset++] = (byte) ((value >>> 24) & 0xFF);
    array[offset++] = (byte) ((value >>> 16) & 0xFF);
    array[offset++] = (byte) ((value >>> 8) & 0xFF);
    array[offset++] = (byte) ((value >>> 0) & 0xFF);
  }

  /** Converts an Ascii Character into Hexadecimal digit */
  public static int hexOf(char x) {
    int val;

    val = x - '0';
    if (val >= 0 && val <= 9) return val;

    val = (x - 'a') + 10;
    if (val >= 10 && val <= 15) return val;

    val = (x - 'A') + 10;
    if (val >= 10 && val <= 15) return val;

    throw wrapper.badHexDigit();
  }

  // method moved from util.Utility

  /**
   * 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 reading a CORBA standard exception from a stream.
   *
   * @param strm The InputStream to use for unmarshaling.
   */
  public static SystemException readSystemException(InputStream strm) {
    try {
      String name = classNameOf(strm.read_string());
      SystemException ex = (SystemException) ORBClassLoader.loadClass(name).newInstance();
      ex.minor = strm.read_long();
      ex.completed = CompletionStatus.from_int(strm.read_long());
      return ex;
    } catch (Exception ex) {
      throw wrapper.unknownSysex(CompletionStatus.COMPLETED_MAYBE, ex);
    }
  }

  /**
   * Get the class name corresponding to a particular repository Id. This is used by the system to
   * unmarshal (instantiate) the appropriate exception class for an marshaled as the value of its
   * repository Id.
   *
   * @param repositoryId The repository Id for which we want a class name.
   */
  public static String classNameOf(String repositoryId) {
    String className = null;

    className = (String) exceptionClassNames.get(repositoryId);
    if (className == null) className = "org.omg.CORBA.UNKNOWN";

    return className;
  }

  /**
   * Return true if this repositoryId is a SystemException.
   *
   * @param repositoryId The repository Id to check.
   */
  public static boolean isSystemException(String repositoryId) {
    String className = null;

    className = (String) exceptionClassNames.get(repositoryId);
    if (className == null) return false;
    else return true;
  }

  /** @return the Java serialization encoding version. */
  public static byte getEncodingVersion(ORB orb, IOR ior) {

    // Is Java serialization enabled?
    // Check the JavaSerializationComponent (tagged component)
    // in the IIOPProfile. If present, the peer ORB's GIOP is capable
    // of using Java serialization instead of CDR serialization.
    // In such a case, use Java serialization, iff the java serialization
    // versions match.

    if (orb.getORBData().isJavaSerializationEnabled()) {
      IIOPProfile prof = ior.getProfile();
      IIOPProfileTemplate profTemp = (IIOPProfileTemplate) prof.getTaggedProfileTemplate();
      java.util.Iterator iter = profTemp.iteratorById(ORBConstants.TAG_JAVA_SERIALIZATION_ID);
      if (iter.hasNext()) {
        JavaSerializationComponent jc = (JavaSerializationComponent) iter.next();
        byte jcVersion = jc.javaSerializationVersion();
        if (jcVersion >= Message.JAVA_ENC_VERSION) {
          return Message.JAVA_ENC_VERSION;
        } else if (jcVersion > Message.CDR_ENC_VERSION) {
          return jc.javaSerializationVersion();
        } else {
          // throw error?
          // Since encodingVersion is <= 0 (CDR_ENC_VERSION).
        }
      }
    }
    return Message.CDR_ENC_VERSION; // default
  }

  /**
   * Get the repository id corresponding to a particular class. This is used by the system to write
   * the appropriate repository id for a system exception.
   *
   * @param name The class name of the system exception.
   */
  public static String repositoryIdOf(String name) {
    String id;

    id = (String) exceptionRepositoryIds.get(name);
    if (id == null) id = "IDL:omg.org/CORBA/UNKNOWN:1.0";

    return id;
  }

  private static final Hashtable exceptionClassNames = new Hashtable();
  private static final Hashtable exceptionRepositoryIds = new Hashtable();

  static {

    //
    // construct repositoryId -> className hashtable
    //
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_CONTEXT:1.0", "org.omg.CORBA.BAD_CONTEXT");
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_INV_ORDER:1.0", "org.omg.CORBA.BAD_INV_ORDER");
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_OPERATION:1.0", "org.omg.CORBA.BAD_OPERATION");
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_PARAM:1.0", "org.omg.CORBA.BAD_PARAM");
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_TYPECODE:1.0", "org.omg.CORBA.BAD_TYPECODE");
    exceptionClassNames.put("IDL:omg.org/CORBA/COMM_FAILURE:1.0", "org.omg.CORBA.COMM_FAILURE");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/DATA_CONVERSION:1.0", "org.omg.CORBA.DATA_CONVERSION");
    exceptionClassNames.put("IDL:omg.org/CORBA/IMP_LIMIT:1.0", "org.omg.CORBA.IMP_LIMIT");
    exceptionClassNames.put("IDL:omg.org/CORBA/INTF_REPOS:1.0", "org.omg.CORBA.INTF_REPOS");
    exceptionClassNames.put("IDL:omg.org/CORBA/INTERNAL:1.0", "org.omg.CORBA.INTERNAL");
    exceptionClassNames.put("IDL:omg.org/CORBA/INV_FLAG:1.0", "org.omg.CORBA.INV_FLAG");
    exceptionClassNames.put("IDL:omg.org/CORBA/INV_IDENT:1.0", "org.omg.CORBA.INV_IDENT");
    exceptionClassNames.put("IDL:omg.org/CORBA/INV_OBJREF:1.0", "org.omg.CORBA.INV_OBJREF");
    exceptionClassNames.put("IDL:omg.org/CORBA/MARSHAL:1.0", "org.omg.CORBA.MARSHAL");
    exceptionClassNames.put("IDL:omg.org/CORBA/NO_MEMORY:1.0", "org.omg.CORBA.NO_MEMORY");
    exceptionClassNames.put("IDL:omg.org/CORBA/FREE_MEM:1.0", "org.omg.CORBA.FREE_MEM");
    exceptionClassNames.put("IDL:omg.org/CORBA/NO_IMPLEMENT:1.0", "org.omg.CORBA.NO_IMPLEMENT");
    exceptionClassNames.put("IDL:omg.org/CORBA/NO_PERMISSION:1.0", "org.omg.CORBA.NO_PERMISSION");
    exceptionClassNames.put("IDL:omg.org/CORBA/NO_RESOURCES:1.0", "org.omg.CORBA.NO_RESOURCES");
    exceptionClassNames.put("IDL:omg.org/CORBA/NO_RESPONSE:1.0", "org.omg.CORBA.NO_RESPONSE");
    exceptionClassNames.put("IDL:omg.org/CORBA/OBJ_ADAPTER:1.0", "org.omg.CORBA.OBJ_ADAPTER");
    exceptionClassNames.put("IDL:omg.org/CORBA/INITIALIZE:1.0", "org.omg.CORBA.INITIALIZE");
    exceptionClassNames.put("IDL:omg.org/CORBA/PERSIST_STORE:1.0", "org.omg.CORBA.PERSIST_STORE");
    exceptionClassNames.put("IDL:omg.org/CORBA/TRANSIENT:1.0", "org.omg.CORBA.TRANSIENT");
    exceptionClassNames.put("IDL:omg.org/CORBA/UNKNOWN:1.0", "org.omg.CORBA.UNKNOWN");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/OBJECT_NOT_EXIST:1.0", "org.omg.CORBA.OBJECT_NOT_EXIST");

    // SystemExceptions from OMG Transactions Service Spec
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/INVALID_TRANSACTION:1.0", "org.omg.CORBA.INVALID_TRANSACTION");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/TRANSACTION_REQUIRED:1.0", "org.omg.CORBA.TRANSACTION_REQUIRED");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/TRANSACTION_ROLLEDBACK:1.0", "org.omg.CORBA.TRANSACTION_ROLLEDBACK");

    // from portability RTF 98-07-01.txt
    exceptionClassNames.put("IDL:omg.org/CORBA/INV_POLICY:1.0", "org.omg.CORBA.INV_POLICY");

    // from orbrev/00-09-01 (CORBA 2.4 Draft Specification)
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/TRANSACTION_UNAVAILABLE:1.0", "org.omg.CORBA.TRANSACTION_UNAVAILABLE");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/TRANSACTION_MODE:1.0", "org.omg.CORBA.TRANSACTION_MODE");

    // Exception types introduced between CORBA 2.4 and 3.0
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/CODESET_INCOMPATIBLE:1.0", "org.omg.CORBA.CODESET_INCOMPATIBLE");
    exceptionClassNames.put("IDL:omg.org/CORBA/REBIND:1.0", "org.omg.CORBA.REBIND");
    exceptionClassNames.put("IDL:omg.org/CORBA/TIMEOUT:1.0", "org.omg.CORBA.TIMEOUT");
    exceptionClassNames.put("IDL:omg.org/CORBA/BAD_QOS:1.0", "org.omg.CORBA.BAD_QOS");

    // Exception types introduced in CORBA 3.0
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/INVALID_ACTIVITY:1.0", "org.omg.CORBA.INVALID_ACTIVITY");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/ACTIVITY_COMPLETED:1.0", "org.omg.CORBA.ACTIVITY_COMPLETED");
    exceptionClassNames.put(
        "IDL:omg.org/CORBA/ACTIVITY_REQUIRED:1.0", "org.omg.CORBA.ACTIVITY_REQUIRED");

    //
    // construct className -> repositoryId hashtable
    //
    Enumeration keys = exceptionClassNames.keys();
    java.lang.Object s;
    String rId;
    String cName;

    try {
      while (keys.hasMoreElements()) {
        s = keys.nextElement();
        rId = (String) s;
        cName = (String) exceptionClassNames.get(rId);
        exceptionRepositoryIds.put(cName, rId);
      }
    } catch (NoSuchElementException e) {
    }
  }

  /**
   * Parse a version string such as "1.1.6" or "jdk1.2fcs" into a version array of integers {1, 1,
   * 6} or {1, 2}. A string of "n." or "n..m" is equivalent to "n.0" or "n.0.m" respectively.
   */
  public static int[] parseVersion(String version) {
    if (version == null) return new int[0];
    char[] s = version.toCharArray();
    // find the maximum span of the string "n.n.n..." where n is an integer
    int start = 0;
    for (; start < s.length && (s[start] < '0' || s[start] > '9'); ++start)
      if (start == s.length) // no digit found
      return new int[0];
    int end = start + 1;
    int size = 1;
    for (; end < s.length; ++end)
      if (s[end] == '.') ++size;
      else if (s[end] < '0' || s[end] > '9') break;
    int[] val = new int[size];
    for (int i = 0; i < size; ++i) {
      int dot = version.indexOf('.', start);
      if (dot == -1 || dot > end) dot = end;
      if (start >= dot) // cases like "n." or "n..m"
      val[i] = 0; // convert equivalent to "n.0" or "n.0.m"
      else val[i] = Integer.parseInt(version.substring(start, dot));
      start = dot + 1;
    }
    return val;
  }

  /**
   * Compare two version arrays. Return 1, 0 or -1 if v1 is greater than, equal to, or less than v2.
   */
  public static int compareVersion(int[] v1, int[] v2) {
    if (v1 == null) v1 = new int[0];
    if (v2 == null) v2 = new int[0];
    for (int i = 0; i < v1.length; ++i) {
      if (i >= v2.length || v1[i] > v2[i]) // v1 is longer or greater than v2
      return 1;
      if (v1[i] < v2[i]) return -1;
    }
    return v1.length == v2.length ? 0 : -1;
  }

  /**
   * Compare two version strings. Return 1, 0 or -1 if v1 is greater than, equal to, or less than
   * v2.
   */
  public static synchronized int compareVersion(String v1, String v2) {
    return compareVersion(parseVersion(v1), parseVersion(v2));
  }

  private static String compressClassName(String name) {
    // Note that this must end in . in order to be renamed correctly.
    String prefix = "com.sun.corba.se.";
    if (name.startsWith(prefix)) {
      return "(ORB)." + name.substring(prefix.length());
    } else return name;
  }

  // Return a compressed representation of the thread name.  This is particularly
  // useful on the server side, where there are many SelectReaderThreads, and
  // we need a short unambiguous name for such threads.
  public static String getThreadName(Thread thr) {
    if (thr == null) return "null";

    // This depends on the formatting in SelectReaderThread and CorbaConnectionImpl.
    // Pattern for SelectReaderThreads:
    // SelectReaderThread CorbaConnectionImpl[ <host> <post> <state>]
    // Any other pattern in the Thread's name is just returned.
    String name = thr.getName();
    StringTokenizer st = new StringTokenizer(name);
    int numTokens = st.countTokens();
    if (numTokens != 5) return name;

    String[] tokens = new String[numTokens];
    for (int ctr = 0; ctr < numTokens; ctr++) tokens[ctr] = st.nextToken();

    if (!tokens[0].equals("SelectReaderThread")) return name;

    return "SelectReaderThread[" + tokens[2] + ":" + tokens[3] + "]";
  }

  private static String formatStackTraceElement(StackTraceElement ste) {
    return compressClassName(ste.getClassName())
        + "."
        + ste.getMethodName()
        + (ste.isNativeMethod()
            ? "(Native Method)"
            : (ste.getFileName() != null && ste.getLineNumber() >= 0
                ? "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")"
                : (ste.getFileName() != null
                    ? "(" + ste.getFileName() + ")"
                    : "(Unknown Source)")));
  }

  private static void printStackTrace(StackTraceElement[] trace) {
    System.out.println("    Stack Trace:");
    // print the stack trace, ommitting the zeroth element, which is
    // always this method.
    for (int ctr = 1; ctr < trace.length; ctr++) {
      System.out.print("        >");
      System.out.println(formatStackTraceElement(trace[ctr]));
    }
  }

  //
  // Implements all dprint calls in this package.
  //
  public static synchronized void dprint(java.lang.Object obj, String msg) {
    System.out.println(
        compressClassName(obj.getClass().getName())
            + "("
            + getThreadName(Thread.currentThread())
            + "): "
            + msg);
  }

  public static synchronized void dprint(String className, String msg) {
    System.out.println(
        compressClassName(className) + "(" + getThreadName(Thread.currentThread()) + "): " + msg);
  }

  public synchronized void dprint(String msg) {
    ORBUtility.dprint(this, msg);
  }

  public static synchronized void dprintTrace(Object obj, String msg) {
    ORBUtility.dprint(obj, msg);

    Throwable thr = new Throwable();
    printStackTrace(thr.getStackTrace());
  }

  public static synchronized void dprint(java.lang.Object caller, String msg, Throwable t) {
    System.out.println(
        compressClassName(caller.getClass().getName())
            + '('
            + Thread.currentThread()
            + "): "
            + msg);

    if (t != null) printStackTrace(t.getStackTrace());
  }

  public static String[] concatenateStringArrays(String[] arr1, String[] arr2) {
    String[] result = new String[arr1.length + arr2.length];

    for (int ctr = 0; ctr < arr1.length; ctr++) result[ctr] = arr1[ctr];

    for (int ctr = 0; ctr < arr2.length; ctr++) result[ctr + arr1.length] = arr2[ctr];

    return result;
  }

  /**
   * Throws the CORBA equivalent of a java.io.NotSerializableException
   *
   * <p>Duplicated from util/Utility for Pure ORB reasons. There are two reasons for this:
   *
   * <p>1) We can't introduce dependencies on the util version from outside of the io/util packages
   * since it will not exist in the pure ORB build running on JDK 1.3.x.
   *
   * <p>2) We need to pick up the correct minor code from OMGSystemException.
   */
  public static void throwNotSerializableForCorba(String className) {
    throw omgWrapper.notSerializable(CompletionStatus.COMPLETED_MAYBE, className);
  }

  /** Returns the maximum stream format version supported by our ValueHandler. */
  public static byte getMaxStreamFormatVersion() {
    ValueHandler vh = Util.createValueHandler();

    if (!(vh instanceof javax.rmi.CORBA.ValueHandlerMultiFormat))
      return ORBConstants.STREAM_FORMAT_VERSION_1;
    else return ((ValueHandlerMultiFormat) vh).getMaximumStreamFormatVersion();
  }

  public static CorbaClientDelegate makeClientDelegate(IOR ior) {
    ORB orb = ior.getORB();
    CorbaContactInfoList ccil = orb.getCorbaContactInfoListFactory().create(ior);
    CorbaClientDelegate del = orb.getClientDelegateFactory().create(ccil);
    return del;
  }

  /** This method is used to create untyped object references. */
  public static org.omg.CORBA.Object makeObjectReference(IOR ior) {
    CorbaClientDelegate del = makeClientDelegate(ior);
    org.omg.CORBA.Object objectImpl = new CORBAObjectImpl();
    StubAdapter.setDelegate(objectImpl, del);
    return objectImpl;
  }

  /**
   * This method obtains an IOR from a CORBA object reference. It will return null if obj is a local
   * object, a null object, or an object implemented by a different ORB. It will throw BAD_OPERATION
   * if obj is an unconnected RMI-IIOP object.
   *
   * @return IOR the IOR that represents this objref. This will never be null.
   * @exception BAD_OPERATION (from oi._get_delegate) if obj is a normal objref, but does not have a
   *     delegate set.
   * @exception BAD_PARAM if obj is a local object, or else was created by a foreign ORB.
   */
  public static IOR getIOR(org.omg.CORBA.Object obj) {
    if (obj == null) throw wrapper.nullObjectReference();

    IOR ior = null;
    if (StubAdapter.isStub(obj)) {
      org.omg.CORBA.portable.Delegate del = StubAdapter.getDelegate(obj);

      if (del instanceof CorbaClientDelegate) {
        CorbaClientDelegate cdel = (CorbaClientDelegate) del;
        ContactInfoList cil = cdel.getContactInfoList();

        if (cil instanceof CorbaContactInfoList) {
          CorbaContactInfoList ccil = (CorbaContactInfoList) cil;
          ior = ccil.getTargetIOR();
          if (ior == null) throw wrapper.nullIor();

          return ior;
        } else {
          // This is our code, but the ContactInfoList is not a
          // CorbaContactInfoList.  This should not happen, because
          // we are in the CORBA application of the DCSA framework.
          // This is a coding error, and thus an INTERNAL exception
          // should be thrown.
          // XXX needs minor code
          throw new INTERNAL();
        }
      }

      // obj is implemented by a foreign ORB, because the Delegate is not a
      // ClientDelegate.
      // XXX this case could be handled by marshalling and
      // unmarshalling.  However, object_to_string cannot be used
      // here, as it is implemented with getIOR.  Note that this
      // will require access to an ORB, so that we can create streams
      // as needed.  The ORB is available simply as io._orb().
      throw wrapper.objrefFromForeignOrb();
    } else throw wrapper.localObjectNotAllowed();
  }

  /**
   * 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;
  }

  public static String operationNameAndRequestId(CorbaMessageMediator m) {
    return "op/" + m.getOperationName() + " id/" + m.getRequestId();
  }

  public static boolean isPrintable(char c) {
    if (Character.isJavaIdentifierStart(c)) {
      // Letters and $ _
      return true;
    }
    if (Character.isDigit(c)) {
      return true;
    }
    switch (Character.getType(c)) {
      case Character.MODIFIER_SYMBOL:
        return true; // ` ^
      case Character.DASH_PUNCTUATION:
        return true; // -
      case Character.MATH_SYMBOL:
        return true; // = ~ + | < >
      case Character.OTHER_PUNCTUATION:
        return true; // !@#%&*;':",./?
      case Character.START_PUNCTUATION:
        return true; // ( [ {
      case Character.END_PUNCTUATION:
        return true; // ) ] }
    }
    return false;
  }

  public static String getClassSecurityInfo(final Class cl) {
    // Returns a String which looks similar to:
    // PermissionCollection java.security.Permissions@1053693 ...
    // (java.io.FilePermission <<ALL FILES>> ....)
    // (java.io.FilePermission /export0/sunwappserv/lib/- ...)
    // ... other permissions ...
    // Domain ProtectionDomain  (file:/export0/sunwappserv/lib-)
    // java.security.Permissions@141fedb (
    // (java.io.FilePermission <<ALL FILES>> ...)
    // (java.io.FilePermission /var/tmp//- ...)

    String result =
        (String)
            AccessController.doPrivileged(
                new PrivilegedAction() {
                  public java.lang.Object run() {
                    StringBuffer sb = new StringBuffer(500);
                    ProtectionDomain pd = cl.getProtectionDomain();
                    Policy policy = Policy.getPolicy();
                    PermissionCollection pc = policy.getPermissions(pd);
                    sb.append("\nPermissionCollection ");
                    sb.append(pc.toString());
                    // Don't need to add 'Protection Domain' string, it's
                    // in ProtectionDomain.toString() already.
                    sb.append(pd.toString());
                    return sb.toString();
                  }
                });
    return result;
  }
}