Exemplo n.º 1
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();
    }
  }
Exemplo n.º 2
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();
    }
  }
Exemplo n.º 3
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();
    }
  }
Exemplo n.º 4
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;
  }