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
 /*      */ private boolean equalMember(
     TypeCode paramTypeCode,
     org.omg.CORBA.portable.InputStream paramInputStream1,
     org.omg.CORBA.portable.InputStream paramInputStream2)
       /*      */ {
   /*  369 */ TypeCode localTypeCode = realType(paramTypeCode);
   /*      */ try
   /*      */ {
     /*      */ int j;
     /*      */ int m;
     /*  372 */ switch (localTypeCode.kind().value())
     /*      */ {
         /*      */ case 0:
         /*      */ case 1:
         /*  376 */ return true;
         /*      */ case 2:
         /*  378 */ return paramInputStream1.read_short() == paramInputStream2.read_short();
         /*      */ case 3:
         /*  380 */ return paramInputStream1.read_long() == paramInputStream2.read_long();
         /*      */ case 4:
         /*  382 */ return paramInputStream1.read_ushort() == paramInputStream2.read_ushort();
         /*      */ case 5:
         /*  384 */ return paramInputStream1.read_ulong() == paramInputStream2.read_ulong();
         /*      */ case 6:
         /*  386 */ return paramInputStream1.read_float() == paramInputStream2.read_float();
         /*      */ case 7:
         /*  388 */ return paramInputStream1.read_double() == paramInputStream2.read_double();
         /*      */ case 8:
         /*  390 */ return paramInputStream1.read_boolean() == paramInputStream2.read_boolean();
         /*      */ case 9:
         /*  392 */ return paramInputStream1.read_char() == paramInputStream2.read_char();
         /*      */ case 26:
         /*  394 */ return paramInputStream1.read_wchar() == paramInputStream2.read_wchar();
         /*      */ case 10:
         /*  396 */ return paramInputStream1.read_octet() == paramInputStream2.read_octet();
         /*      */ case 11:
         /*  398 */ return paramInputStream1.read_any().equal(paramInputStream2.read_any());
         /*      */ case 12:
         /*  400 */ return paramInputStream1
             .read_TypeCode()
             .equal(paramInputStream2.read_TypeCode());
         /*      */ case 18:
         /*  402 */ return paramInputStream1.read_string().equals(paramInputStream2.read_string());
         /*      */ case 27:
         /*  404 */ return paramInputStream1
             .read_wstring()
             .equals(paramInputStream2.read_wstring());
         /*      */ case 23:
         /*  406 */ return paramInputStream1.read_longlong() == paramInputStream2.read_longlong();
         /*      */ case 24:
         /*  408 */ return paramInputStream1.read_ulonglong()
             == paramInputStream2.read_ulonglong();
         /*      */ case 14:
         /*  411 */ return paramInputStream1.read_Object().equals(paramInputStream2.read_Object());
         /*      */ case 13:
         /*  413 */ return paramInputStream1
             .read_Principal()
             .equals(paramInputStream2.read_Principal());
         /*      */ case 17:
         /*  416 */ return paramInputStream1.read_long() == paramInputStream2.read_long();
         /*      */ case 28:
         /*  418 */ return paramInputStream1.read_fixed().compareTo(paramInputStream2.read_fixed())
             == 0;
         /*      */ case 15:
         /*      */ case 22:
         /*  421 */ int i = localTypeCode.member_count();
         /*  422 */ for (int k = 0; k < i; k++) {
           /*  423 */ if (!equalMember(
               localTypeCode.member_type(k), paramInputStream1, paramInputStream2)) {
             /*  424 */ return false;
             /*      */ }
           /*      */ }
         /*  427 */ return true;
         /*      */ case 16:
         /*  430 */ Any localAny1 = this.orb.create_any();
         /*  431 */ Any localAny2 = this.orb.create_any();
         /*  432 */ localAny1.read_value(paramInputStream1, localTypeCode.discriminator_type());
         /*  433 */ localAny2.read_value(paramInputStream2, localTypeCode.discriminator_type());
         /*      */
         /*  435 */ if (!localAny1.equal(localAny2)) {
           /*  436 */ return false;
           /*      */ }
         /*  438 */ TypeCodeImpl localTypeCodeImpl =
             TypeCodeImpl.convertToNative(this.orb, localTypeCode);
         /*  439 */ int n = localTypeCodeImpl.currentUnionMemberIndex(localAny1);
         /*  440 */ if (n == -1) {
           /*  441 */ throw this.wrapper.unionDiscriminatorError();
           /*      */ }
         /*  443 */ if (!equalMember(
             localTypeCode.member_type(n), paramInputStream1, paramInputStream2)) {
           /*  444 */ return false;
           /*      */ }
         /*  446 */ return true;
         /*      */ case 19:
         /*  449 */ j = paramInputStream1.read_long();
         /*  450 */ paramInputStream2.read_long();
         /*  451 */ for (m = 0; m < j; m++) {
           /*  452 */ if (!equalMember(
               localTypeCode.content_type(), paramInputStream1, paramInputStream2)) {
             /*  453 */ return false;
             /*      */ }
           /*      */ }
         /*  456 */ return true;
         /*      */ case 20:
         /*  459 */ j = localTypeCode.member_count();
         /*  460 */ for (m = 0; m < j; m++) {
           /*  461 */ if (!equalMember(
               localTypeCode.content_type(), paramInputStream1, paramInputStream2)) {
             /*  462 */ return false;
             /*      */ }
           /*      */ }
         /*  465 */ return true;
         /*      */ case 29:
         /*      */ case 30:
         /*  473 */ org.omg.CORBA_2_3.portable.InputStream localInputStream1 =
             (org.omg.CORBA_2_3.portable.InputStream) paramInputStream1;
         /*      */
         /*  475 */ org.omg.CORBA_2_3.portable.InputStream localInputStream2 =
             (org.omg.CORBA_2_3.portable.InputStream) paramInputStream2;
         /*      */
         /*  477 */ return localInputStream1.read_value().equals(localInputStream2.read_value());
         /*      */ case 21:
         /*  481 */ throw this.wrapper.errorResolvingAlias();
         /*      */ case 25:
         /*  484 */ throw this.wrapper.tkLongDoubleNotSupported();
         /*      */ }
     /*      */
     /*  487 */ throw this.wrapper.typecodeNotSupported();
     /*      */ }
   /*      */ catch (BadKind localBadKind) {
     /*  490 */ throw this.wrapper.badkindCannotOccur();
   } catch (Bounds localBounds) {
     /*      */ }
   /*  492 */ throw this.wrapper.boundsCannotOccur();
   /*      */ }