More tweaks to complex/simple type detection, add makeAccessible() call to BasicMappingContext

This commit is contained in:
Jon Brisbin
2011-03-14 10:53:31 -05:00
committed by J. Brisbin
parent e287cd23d6
commit 1f9af56158
3 changed files with 13 additions and 19 deletions

View File

@@ -92,15 +92,15 @@ public class BasicMappingContext implements MappingContext, InitializingBean {
for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
descriptors.put(descriptor.getName(), descriptor);
}
ReflectionUtils.doWithFields(type, new FieldCallback() {
@Override
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
try {
PropertyDescriptor descriptor = descriptors.get(field.getName());
if (builder.isPersistentProperty(field, descriptor)) {
ReflectionUtils.makeAccessible(field);
PersistentProperty<?> property = builder.createPersistentProperty(field, descriptor);
property.setOwner(entity);
entity.addPersistentProperty(property);
@@ -108,7 +108,7 @@ public class BasicMappingContext implements MappingContext, InitializingBean {
Association association = builder.createAssociation(property);
entity.addAssociation(association);
}
if (property.isIdProperty()) {
entity.setIdProperty(property);
}

View File

@@ -129,7 +129,7 @@ public class BasicPersistentProperty<T> implements PersistentProperty<T> {
@Override
public boolean isComplexType() {
if (isCollection() || field.getType().isArray()) {
if (isCollection() || type.isArray()) {
return !MappingBeanHelper.isSimpleType(getComponentType());
} else {
return !MappingBeanHelper.isSimpleType(field.getType());

View File

@@ -150,8 +150,8 @@ public abstract class MappingBeanHelper {
throws IllegalAccessException, InvocationTargetException {
Field field = property.getField();
if (fieldAccessOnly || (null == property.getPropertyDescriptor() || null == property.getPropertyDescriptor().getWriteMethod())) {
field.setAccessible(true);
Method setter = (null != property.getPropertyDescriptor() ? property.getPropertyDescriptor().getWriteMethod() : null);
if (fieldAccessOnly || null == setter) {
if (null != value && value.getClass().isAssignableFrom(field.getType())) {
field.set(on, value);
} else {
@@ -160,7 +160,6 @@ public abstract class MappingBeanHelper {
return;
}
Method setter = property.getPropertyDescriptor().getWriteMethod();
Class<?>[] paramTypes = setter.getParameterTypes();
if (null != value && paramTypes.length > 0 && !value.getClass().isAssignableFrom(paramTypes[0])) {
setter.invoke(on, conversionService.convert(value, paramTypes[0]));
@@ -175,19 +174,14 @@ public abstract class MappingBeanHelper {
Class<T> type,
boolean fieldAccessOnly)
throws IllegalAccessException, InvocationTargetException {
Object obj;
Field field = property.getField();
if (fieldAccessOnly || (null == property.getPropertyDescriptor() || null == property.getPropertyDescriptor().getReadMethod())) {
field.setAccessible(true);
Object obj = field.get(from);
if (null != obj && !obj.getClass().isAssignableFrom(type)) {
return conversionService.convert(obj, type);
} else {
return (T) obj;
}
Method getter = (null != property.getPropertyDescriptor() ? property.getPropertyDescriptor().getReadMethod() : null);
if (fieldAccessOnly || null == getter) {
obj = field.get(from);
} else {
obj = getter.invoke(from);
}
Object obj = property.getPropertyDescriptor().getReadMethod().invoke(from);
if (null != obj && !obj.getClass().isAssignableFrom(type)) {
return conversionService.convert(obj, type);
} else {