Exemple #1
0
  public static void arraycopy(Object src, int srcOfs, Object dest, int destOfs, int len) {
    checkNotNull(src, "src");
    checkNotNull(dest, "dest");

    Class<?> srcType = src.getClass();
    Class<?> destType = dest.getClass();
    checkArrayType(srcType.isArray(), "srcType is not an array");
    checkArrayType(destType.isArray(), "destType is not an array");

    Class<?> srcComp = srcType.getComponentType();
    Class<?> destComp = destType.getComponentType();
    checkArrayType(arrayTypeMatch(srcComp, destComp), "Array types don't match");

    int srclen = ArrayHelper.getLength(src);
    int destlen = ArrayHelper.getLength(dest);
    if (srcOfs < 0 || destOfs < 0 || len < 0 || srcOfs + len > srclen || destOfs + len > destlen) {
      throw new IndexOutOfBoundsException();
    }

    /*
     * If the arrays are not references or if they are exactly the same type, we
     * can copy them in native code for speed. Otherwise, we have to copy them
     * in Java so we get appropriate errors.
     */
    if (isTypeChecked() && !srcComp.isPrimitive() && !srcType.equals(destType)) {
      // copy in Java to make sure we get ArrayStoreExceptions if the values
      // aren't compatible
      Object[] srcArray = (Object[]) src;
      Object[] destArray = (Object[]) dest;
      if (src == dest && srcOfs < destOfs) {
        // TODO(jat): how does backward copies handle failures in the middle?
        // copy backwards to avoid destructive copies
        srcOfs += len;
        for (int destEnd = destOfs + len; destEnd-- > destOfs; ) {
          destArray[destEnd] = srcArray[--srcOfs];
        }
      } else {
        for (int destEnd = destOfs + len; destOfs < destEnd; ) {
          destArray[destOfs++] = srcArray[srcOfs++];
        }
      }
    } else if (len > 0) {
      ArrayHelper.copy(src, srcOfs, dest, destOfs, len);
    }
  }
Exemple #2
0
 private static void appendTypeName(StringBuilder out, Class<?> c) {
   if (c == null) {
     out.append("null");
   } else {
     int dimensions = 0;
     while (c.isArray()) {
       c = c.getComponentType();
       dimensions++;
     }
     out.append(c.getName());
     for (int d = 0; d < dimensions; d++) {
       out.append("[]");
     }
   }
 }
Exemple #3
0
  /**
   * Utility method for insert_Value and Util.writeAny.
   *
   * <p>The ORB passed in should have the desired ORBVersion. It is used to generate the type codes.
   */
  public TypeCode createTypeCodeForClass(java.lang.Class c, ORB tcORB) {
    // Look in the cache first
    TypeCodeImpl classTC = tcORB.getTypeCodeForClass(c);
    if (classTC != null) return classTC;

    // All cases need to be able to create repository IDs.
    //
    // See bug 4391648 for more info about the tcORB in this
    // case.
    RepositoryIdStrings repStrs = RepositoryIdFactory.getRepIdStringsFactory();

    // Assertion: c instanceof Serializable?

    if (c.isArray()) {
      // Arrays - may recurse for multi-dimensional arrays
      Class componentClass = c.getComponentType();
      TypeCode embeddedType;
      if (componentClass.isPrimitive()) {
        embeddedType = getPrimitiveTypeCodeForClass(componentClass, tcORB);
      } else {
        embeddedType = createTypeCodeForClass(componentClass, tcORB);
      }
      TypeCode t = tcORB.create_sequence_tc(0, embeddedType);

      String id = repStrs.createForJavaType(c);

      return tcORB.create_value_box_tc(id, "Sequence", t);
    } else if (c == java.lang.String.class) {
      // Strings
      TypeCode t = tcORB.create_string_tc(0);

      String id = repStrs.createForJavaType(c);

      return tcORB.create_value_box_tc(id, "StringValue", t);
    }

    // Anything else
    // We know that this is a TypeCodeImpl since it is our ORB
    classTC =
        (TypeCodeImpl)
            ValueUtility.createTypeCodeForClass(tcORB, c, ORBUtility.createValueHandler());
    // Intruct classTC to store its buffer
    classTC.setCaching(true);
    // Update the cache
    tcORB.setTypeCodeForClass(c, classTC);
    return classTC;
  }
Exemple #4
0
  private static Object unmarshallMsgData(int formatter, int byteArray, Class msgDataClass)
      throws Exception {
    Object object = null;

    // Throw an exception if class does not match formatter
    formatters.checkDataClass(formatter, msgDataClass);

    if (msgDataClass.isArray()) {
      // Create a top-level fixed-length array, based on the formatter.
      object = formatters.createFixedArray(msgDataClass.getComponentType(), formatter);
    } else {
      // Create an object type that Java IPC can handle
      object = coerceDataClass(msgDataClass).newInstance();
    }
    formatters.unmarshall(formatter, byteArray, object);
    IPC_freeByteArray(byteArray);
    if (formatters.IPCPrim.class.isAssignableFrom(object.getClass())) {
      object = ((formatters.IPCPrim) object).coerce();
    }

    return object;
  }