예제 #1
0
 /**
  * todo: Move the GenericClass creation into a utility/factory class.
  *
  * @return
  */
 public GenericClass initGenericClass() {
   GenericReflector reflector =
       new GenericReflector(null, Platform4.reflectorForType(GenericObjectsTest.class));
   GenericClass _objectIClass = (GenericClass) reflector.forClass(Object.class);
   GenericClass result = new GenericClass(reflector, null, PERSON_CLASSNAME, _objectIClass);
   result.initFields(fields(result, reflector));
   return result;
 }
예제 #2
0
  /**
   * Search for slot that corresponds to class. <br>
   * If not found add it. <br>
   * Constrain it. <br>
   */
  public Constraint constrain(Object example) {
    synchronized (streamLock()) {
      ReflectClass claxx = reflectClassForClass(example);
      if (claxx != null) {
        return addClassConstraint(claxx);
      }

      QConEvaluation eval = Platform4.evaluationCreate(_trans, example);
      if (eval != null) {
        return addEvaluationToAllConstraints(eval);
      }

      Collection4 constraints = new Collection4();
      addConstraint(constraints, example);
      return toConstraint(constraints);
    }
  }
예제 #3
0
  public boolean isEqual(Object a_compare, Object a_with, String a_path, Stack a_stack) {
    if (a_path == null || a_path.length() < 1) {
      if (a_compare != null) {
        a_path = a_compare.getClass().getName() + ":";
      } else {
        if (a_with != null) {
          a_path = a_with.getClass().getName() + ":";
        }
      }
    }

    String path = a_path;

    if (a_compare == null) {
      return a_with == null;
    }
    if (a_with == null) {
      return false;
    }
    Class clazz = a_compare.getClass();
    if (clazz != a_with.getClass()) {
      return false;
    }

    if (isSimple(clazz)) {
      return a_compare.equals(a_with);
    }

    if (a_stack == null) {
      a_stack = new Stack();
    }

    // takes care of repeating calls to the same object
    if (a_stack.contains(a_compare)) {
      return true;
    }
    a_stack.push(a_compare);

    Field fields[] = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      if (storeableField(clazz, fields[i])) {
        Platform4.setAccessible(fields[i]);
        try {
          path = a_path + fields[i].getName() + ":";
          Object compare = fields[i].get(a_compare);
          Object with = fields[i].get(a_with);
          if (compare == null) {
            if (with != null) {
              return false;
            }
          } else if (with == null) {
            return false;
          } else {
            if (compare.getClass().isArray()) {
              if (!with.getClass().isArray()) {
                return false;
              } else {
                compare = normalizeNArray(compare);
                with = normalizeNArray(with);
                int len = Array.getLength(compare);
                if (len != Array.getLength(with)) {
                  return false;
                } else {
                  for (int j = 0; j < len; j++) {
                    Object elementCompare = Array.get(compare, j);
                    Object elementWith = Array.get(with, j);
                    //										if (l_persistentArray)
                    if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                      return false;
                    } else if (elementCompare == null) {
                      if (elementWith != null) {
                        return false;
                      }
                    } else if (elementWith == null) {
                      return false;
                    } else {
                      Class elementCompareClass = elementCompare.getClass();
                      if (elementCompareClass != elementWith.getClass()) {
                        return false;
                      }
                      if (hasPublicConstructor(elementCompareClass)) {
                        if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                          return false;
                        }
                      } else if (!elementCompare.equals(elementWith)) {
                        return false;
                      }
                    }
                  }
                }
              }
            } else if (hasPublicConstructor(fields[i].getType())) {
              if (!isEqual(compare, with, path, a_stack)) {
                return false;
              }
            } else {
              if (!compare.equals(with)) {
                return false;
              }
            }
          }
        } catch (IllegalAccessException ex) {
          // probably JDK 1
          // never mind this field
          return true;
        } catch (Exception e) {
          System.err.println("STCompare failure executing path:" + path);
          e.printStackTrace();
          return false;
        }
      }
    }
    return true;
  }