use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class DfBeanDescImpl method setupWriteMethod.
protected void setupWriteMethod(Method writeMethod, String propertyName) {
final Class<?> propertyType = writeMethod.getParameterTypes()[0];
final DfPropertyDesc propDesc = getPropertyDescInternally(propertyName);
if (propDesc != null) {
if (!propDesc.getPropertyType().equals(propertyType)) {
_invalidPropertyNames.add(propertyName);
} else {
propDesc.setWriteMethod(writeMethod);
}
} else {
addPropertyDesc(createPropertyDesc(propertyName, propertyType, null, writeMethod, null));
}
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class DfBeanDescImpl method addFields.
protected void addFields(Class<?> clazz) {
final Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
final String fieldName = field.getName();
if (_fieldMap.containsKey(fieldName)) {
// target class's fields have priority
continue;
}
if (isFieldPrivateAccessible()) {
field.setAccessible(true);
}
_fieldMap.put(fieldName, field);
if (DfReflectionUtil.isInstanceVariableField(field)) {
if (hasPropertyDesc(fieldName)) {
final DfPropertyDesc pd = getPropertyDesc(fieldName);
pd.setField(field);
} else if (DfReflectionUtil.isPublicField(field)) {
final DfPropertyDesc pd = createPropertyDesc(fieldName, field.getType(), null, null, field);
_propertyDescMap.put(fieldName, pd);
}
}
}
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class DfBeanDescImpl method setupReadMethod.
protected void setupReadMethod(Method readMethod, String propertyName) {
final Class<?> propertyType = readMethod.getReturnType();
final DfPropertyDesc propDesc = getPropertyDescInternally(propertyName);
if (propDesc != null) {
if (!propDesc.getPropertyType().equals(propertyType)) {
_invalidPropertyNames.add(propertyName);
} else {
propDesc.setReadMethod(readMethod);
}
} else {
addPropertyDesc(createPropertyDesc(propertyName, propertyType, readMethod, null, null));
}
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class DfPropertyDescImplTest method test_getValue_illegalProperty.
public void test_getValue_illegalProperty() throws Exception {
// ## Arrange ##
DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(MockBean.class);
DfPropertyDesc pd = beanDesc.getPropertyDesc("writeOnlyName");
MockBean bean = new MockBean();
bean.setWriteOnlyName("foo");
// ## Act ##
try {
pd.getValue(bean);
// ## Assert ##
fail();
} catch (DfBeanIllegalPropertyException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.
the class DfPropertyDescImplTest method test_setValue_illegalProperty.
public void test_setValue_illegalProperty() throws Exception {
// ## Arrange ##
DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(MockBean.class);
DfPropertyDesc pd = beanDesc.getPropertyDesc("readOnlyName");
MockBean bean = new MockBean();
// ## Act ##
try {
pd.setValue(bean, "foo");
// ## Assert ##
fail();
} catch (DfBeanIllegalPropertyException e) {
// OK
log(e.getMessage());
}
}
Aggregations