示例#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 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 + ".");
 }
示例#3
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
  }
示例#4
0
 public boolean hasProperty(String name) {
   PropertyDescriptor prop = ReflectionUtil.getPropertyDescriptor(type, name);
   return config.isPropertyAccessibleForEncoding(prop);
 }