| 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.DozerConstants; |
| 20 | |
import org.dozer.util.MappingUtils; |
| 21 | |
|
| 22 | |
import java.util.ArrayList; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.concurrent.CopyOnWriteArrayList; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class PropertyDescriptorFactory { |
| 33 | |
|
| 34 | 1 | private static final List<PropertyDescriptorCreationStrategy> pluggedDescriptorCreationStrategies = |
| 35 | |
new ArrayList<PropertyDescriptorCreationStrategy>(); |
| 36 | |
|
| 37 | 0 | private PropertyDescriptorFactory() { |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
public static DozerPropertyDescriptor getPropertyDescriptor(Class<?> clazz, String theGetMethod, String theSetMethod, |
| 41 | |
String mapGetMethod, String mapSetMethod, boolean isAccessible, boolean isIndexed, int index, String name, String key, |
| 42 | |
boolean isSelfReferencing, String oppositeFieldName, HintContainer srcDeepIndexHintContainer, |
| 43 | |
HintContainer destDeepIndexHintContainer, String beanFactory) { |
| 44 | 58879 | DozerPropertyDescriptor desc = null; |
| 45 | |
|
| 46 | |
|
| 47 | 58879 | boolean isMapProperty = MappingUtils.isSupportedMap(clazz); |
| 48 | 58879 | if (name.equals(DozerConstants.SELF_KEYWORD) && |
| 49 | |
(mapSetMethod != null || mapGetMethod != null || isMapProperty)) { |
| 50 | 1233 | String setMethod = isMapProperty ? "put" : mapSetMethod; |
| 51 | 1233 | String getMethod = isMapProperty ? "get" : mapGetMethod; |
| 52 | |
|
| 53 | 1233 | desc = new MapPropertyDescriptor(clazz, name, isIndexed, index, setMethod, |
| 54 | |
getMethod, key != null ? key : oppositeFieldName, |
| 55 | |
srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | 1233 | } else if (isSelfReferencing) { |
| 60 | 350 | desc = new SelfPropertyDescriptor(clazz); |
| 61 | |
|
| 62 | |
|
| 63 | 57296 | } else if (isAccessible) { |
| 64 | 330 | desc = new FieldPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 65 | |
|
| 66 | |
|
| 67 | 56966 | } else if (theSetMethod != null || theGetMethod != null) { |
| 68 | 2449 | desc = new CustomGetSetPropertyDescriptor(clazz, name, isIndexed, index, theSetMethod, theGetMethod, |
| 69 | |
srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 70 | |
|
| 71 | |
|
| 72 | 54517 | } else if (beanFactory != null && beanFactory.equals(DozerConstants.XML_BEAN_FACTORY)) { |
| 73 | 120 | desc = new XmlBeanPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 74 | |
} |
| 75 | |
|
| 76 | 58879 | if (desc != null) return desc; |
| 77 | |
|
| 78 | |
for (PropertyDescriptorCreationStrategy propertyDescriptorBuilder : |
| 79 | 54397 | new CopyOnWriteArrayList<PropertyDescriptorCreationStrategy>(pluggedDescriptorCreationStrategies)) { |
| 80 | 0 | if (propertyDescriptorBuilder.isApplicable(clazz, name)) { |
| 81 | 0 | desc = propertyDescriptorBuilder.buildFor( |
| 82 | |
clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 83 | 0 | if (desc != null) break; |
| 84 | |
} |
| 85 | 0 | } |
| 86 | |
|
| 87 | 54397 | if (desc == null) { |
| 88 | |
|
| 89 | 54397 | desc = new JavaBeanPropertyDescriptor(clazz, name, isIndexed, index, srcDeepIndexHintContainer, destDeepIndexHintContainer); |
| 90 | |
} |
| 91 | |
|
| 92 | 54397 | return desc; |
| 93 | |
} |
| 94 | |
|
| 95 | |
public static void addPluggedPropertyDescriptorCreationStrategy(PropertyDescriptorCreationStrategy strategy) { |
| 96 | 0 | pluggedDescriptorCreationStrategies.add(strategy); |
| 97 | 0 | } |
| 98 | |
} |