Exemple #1
0
 /**
  * Creates new instance for current property name through its setter. It uses default constructor!
  */
 protected Object createBeanProperty(BeanProperty bp) {
   MethodDescriptor setter = bp.cd.getBeanSetterMethodDescriptor(bp.name, true);
   FieldDescriptor field = null;
   Class type;
   if (setter != null) {
     type = setter.getRawParameterTypes()[0];
   } else {
     field = getField(bp, true);
     if (field == null) {
       return null;
     }
     type = field.getRawType();
   }
   Object newInstance;
   try {
     newInstance = ReflectUtil.newInstance(type);
   } catch (Exception ex) {
     throw new BeanException("Unable to create property: " + bp.name, bp, ex);
   }
   if (setter != null) {
     invokeSetter(bp.bean, setter, newInstance);
   } else {
     setFieldValue(bp.bean, field, newInstance);
   }
   return newInstance;
 }
Exemple #2
0
 /** Return value of a field. */
 protected Object getFieldValue(Object bean, FieldDescriptor fd) {
   try {
     return fd.get(bean);
   } catch (Exception ex) {
     throw new BeanException(
         "Unable to get field " + bean.getClass().getSimpleName() + '#' + fd.getField().getName(),
         ex);
   }
 }
Exemple #3
0
  /** Returns field descriptor. */
  public FieldDescriptor getFieldDescriptor(String name, boolean declared) {
    FieldDescriptor fieldDescriptor = getFields().getFieldDescriptor(name);

    if (fieldDescriptor != null) {
      if (!fieldDescriptor.matchDeclared(declared)) {
        return null;
      }
    }

    return fieldDescriptor;
  }
Exemple #4
0
  /** Sets field value. */
  protected void setFieldValue(Object bean, FieldDescriptor fd, Object value) {
    try {
      Class type = fd.getRawType();

      value = convertType(value, type);

      fd.set(bean, value);
    } catch (Exception ex) {
      throw new BeanException(
          "Unable to set field: " + bean.getClass().getSimpleName() + '#' + fd.getField().getName(),
          ex);
    }
  }