/**
  * 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;
 }
  private void tstFields() {
    ReflectField surname = _iClass.getDeclaredField("surname");
    ReflectField birthdate = _iClass.getDeclaredField("birthdate");
    ReflectField[] fields = _iClass.getDeclaredFields();
    _assert(fields.length == 3);
    _assert(fields[0] == surname);
    _assert(fields[1] == birthdate);

    Object person = _iClass.newInstance();
    _assert(birthdate.get(person) == null);
    surname.set(person, "Cleese");
    _assert(surname.get(person).equals("Cleese"));
  }
 private Object initGenericObjects() {
   GenericClass personClass = initGenericClass();
   ReflectField surname = personClass.getDeclaredField("surname");
   ReflectField birthdate = personClass.getDeclaredField("birthdate");
   // ReflectField nArray = personClass.getDeclaredField("nArray");
   Object person = personClass.newInstance();
   surname.set(person, "John");
   //		/int[][] arrayData = new int[2][2];
   // todo: FIXME: nArray doesn't work
   // nArray.set(person, arrayData);
   birthdate.set(person, new Date());
   fixture().db().store(person);
   fixture().db().commit();
   return person;
 }
 private GenericClass acmeDataClass() {
   GenericClass result = new GenericClass(_reflector, null, "com.acme.Person", _objectIClass);
   result.initFields(fields(result));
   return result;
 }
  public void test() throws ClassNotFoundException {
    _reflector.register(acmeDataClass());
    _iClass = (GenericClass) _reflector.forName("com.acme.Person");
    _assert(_iClass.getName().equals("com.acme.Person"));
    _assert(_iClass.getSuperclass() == _objectIClass);

    _assert(_iClass.isAssignableFrom(subclass()));
    _assert(!_iClass.isAssignableFrom(otherDataClass()));
    _assert(!_iClass.isAssignableFrom(_objectIClass));

    _assert(_iClass.isInstance(_iClass.newInstance()));
    _assert(_iClass.isInstance(subclass().newInstance()));
    _assert(!_iClass.isInstance(otherDataClass().newInstance()));
    _assert(!_iClass.isInstance("whatever"));

    _assert(_reflector.forObject(_iClass.newInstance()) == _iClass);

    tstFields();
    tstReflectionDelegation();
  }
 public String toString() {
   if (_class == null) {
     return super.toString();
   }
   return _class.toString(this);
 }
 private void ensureValuesInitialized() {
   if (_values == null) {
     _values = new Object[_class.getFieldCount()];
   }
 }