| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.dozer.propertydescriptor; |
| 17 | |
|
| 18 | |
import org.dozer.fieldmap.HintContainer; |
| 19 | |
import org.dozer.util.MappingUtils; |
| 20 | |
import org.dozer.util.ReflectionUtils; |
| 21 | |
|
| 22 | |
import java.beans.PropertyDescriptor; |
| 23 | |
import java.lang.reflect.Method; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public class JavaBeanPropertyDescriptor extends GetterSetterPropertyDescriptor { |
| 35 | |
private PropertyDescriptor pd; |
| 36 | |
|
| 37 | |
public JavaBeanPropertyDescriptor(Class<?> clazz, String fieldName, boolean isIndexed, int index, |
| 38 | |
HintContainer srcDeepIndexHintContainer, HintContainer destDeepIndexHintContainer) { |
| 39 | 58018 | super(clazz, fieldName, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 40 | 58018 | } |
| 41 | |
|
| 42 | |
@Override |
| 43 | |
public Method getWriteMethod() throws NoSuchMethodException { |
| 44 | 97817 | Method result = getPropertyDescriptor(destDeepIndexHintContainer).getWriteMethod(); |
| 45 | 97813 | result = result == null ? ReflectionUtils.getNonVoidSetter(clazz, fieldName) : result; |
| 46 | 97813 | if (result == null) { |
| 47 | 378 | throw new NoSuchMethodException("Unable to determine write method for Field: '" + fieldName + "' in Class: " + clazz); |
| 48 | |
} |
| 49 | 97435 | return result; |
| 50 | |
} |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
protected String getSetMethodName() throws NoSuchMethodException { |
| 54 | 0 | return getWriteMethod().getName(); |
| 55 | |
} |
| 56 | |
|
| 57 | |
@Override |
| 58 | |
protected Method getReadMethod() throws NoSuchMethodException { |
| 59 | 323965 | Method result = getPropertyDescriptor(srcDeepIndexHintContainer).getReadMethod(); |
| 60 | 323870 | if (result == null) { |
| 61 | 112 | throw new NoSuchMethodException("Unable to determine read method for Field: '" + fieldName + "' in Class: " + clazz); |
| 62 | |
} |
| 63 | 323758 | return result; |
| 64 | |
} |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
protected boolean isCustomSetMethod() { |
| 68 | 131336 | return false; |
| 69 | |
} |
| 70 | |
|
| 71 | |
private PropertyDescriptor getPropertyDescriptor(HintContainer deepIndexHintContainer) { |
| 72 | 421782 | if (pd == null) { |
| 73 | 57370 | pd = ReflectionUtils.findPropertyDescriptor(clazz, fieldName, deepIndexHintContainer); |
| 74 | 57287 | if (pd == null) { |
| 75 | 16 | MappingUtils.throwMappingException("Property: '" + fieldName + "' not found in Class: " + clazz); |
| 76 | |
} |
| 77 | |
} |
| 78 | 421683 | return pd; |
| 79 | |
} |
| 80 | |
|
| 81 | |
} |