コード例 #1
0
 public Class getPropertyType(String name) {
   if (ReflectionUtil.hasProperty(type, name))
     return ReflectionUtil.getPropertyDescriptor(type, name).getPropertyType();
   else {
     try {
       Field field = type.getDeclaredField(name);
       if (ReflectionUtil.isMemberField(field)) {
         field.setAccessible(true);
         return field.getType();
       }
     } catch (Exception e) {
     }
     return null;
   }
 }
コード例 #2
0
  public Collection keys() {
    Object prototype = createPrototype();
    Set<String> set = new HashSet<String>();
    for (PropertyDescriptor prop : ReflectionUtil.getProperties(getType())) {
      if (config.isPropertyAccessibleForEncoding(prop))
        try {
          if (!Utilities.same(
              getProperty(getObject(), prop.getName()), getProperty(prototype, prop.getName())))
            set.add(prop.getName());
        } catch (Exception e) {
        }
    }
    for (Field field : getType().getDeclaredFields())
      if (config.isFieldAccessibleForEncoding(field)) {
        field.setAccessible(true);
        try {
          if (!Utilities.same(field.get(prototype), field.get(getObject())))
            set.add(field.getName());
        } catch (Exception e) {
        }
      }

    // sort the keys alphabetically
    List<String> ret = new ArrayList<String>(set);
    Collections.sort(
        ret,
        new Comparator<String>() {
          public int compare(String o1, String o2) {
            return o1.compareTo(o2);
          }
        });
    return ret;
  }
コード例 #3
0
 public Object getProperty(Object obj, String name) {
   try {
     PropertyDescriptor prop = ReflectionUtil.getPropertyDescriptor(type, name);
     if (config.isPropertyAccessibleForEncoding(prop)) {
       Method rm = prop.getReadMethod();
       rm.setAccessible(true);
       return rm.invoke(obj, null);
     }
   } catch (Exception e) {
   }
   try {
     Field field = type.getDeclaredField(name);
     if (config.isFieldAccessibleForEncoding(field)) {
       field.setAccessible(true);
       return field.get(obj);
     }
   } catch (Exception e) {
   }
   throw new PropertyAccessException("Can't get " + name + " property on type " + type + ".");
 }
コード例 #4
0
  public void setProperty(String name, Object value) throws PropertyAccessException {
    try {
      PropertyDescriptor prop = ReflectionUtil.getPropertyDescriptor(type, name);
      if (config.isPropertyAccessibleForEncoding(prop)) {
        Method wm = prop.getWriteMethod();
        wm.setAccessible(true);
        wm.invoke(getObject(), new Object[] {value});
        return;
      }

    } catch (Exception e) {
    }
    try {
      Field field = type.getDeclaredField(name);
      if (config.isFieldAccessibleForDecoding(field)) {
        field.setAccessible(true);
        field.set(getObject(), value);
      }
      return;
    } catch (Exception e) {
    }
    // ignore this
  }
コード例 #5
0
 public boolean hasProperty(String name) {
   PropertyDescriptor prop = ReflectionUtil.getPropertyDescriptor(type, name);
   return config.isPropertyAccessibleForEncoding(prop);
 }