1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.jcr.node2bean;
35
36 import java.beans.PropertyDescriptor;
37 import java.util.Collections;
38 import java.util.HashMap;
39 import java.util.Map;
40
41 import org.apache.commons.beanutils.PropertyUtils;
42
43
44
45
46
47 public class TypeDescriptor {
48
49 private Class<?> type;
50
51 private String itemType;
52
53 private Node2BeanTransformer transformer;
54
55 private boolean isMap;
56
57 private boolean isCollection;
58
59 private boolean isArray;
60
61 private Map<String, PropertyTypeDescriptor> descriptors;
62
63 public String getItemType() {
64 return this.itemType;
65 }
66
67 public void setItemType(String itemType) {
68 this.itemType = itemType;
69 }
70
71 public Class<?> getType() {
72 return this.type;
73 }
74
75 public void setType(Class<?> type) {
76 this.type = type;
77 }
78
79
80 public boolean isCollection() {
81 return this.isCollection;
82 }
83
84
85 public void setCollection(boolean isCollection) {
86 this.isCollection = isCollection;
87 }
88
89
90 public boolean isMap() {
91 return this.isMap;
92 }
93
94
95 public void setMap(boolean isMap) {
96 this.isMap = isMap;
97 }
98
99 public boolean isArray() {
100 return this.isArray;
101 }
102
103 public void setArray(boolean isArray) {
104 this.isArray = isArray;
105 }
106
107 public PropertyTypeDescriptor getPropertyTypeDescriptor(String propertyName, TypeMapping typeMapping) {
108 return getPropertyDescriptors(typeMapping).get(propertyName);
109 }
110
111
112
113
114 public boolean needsDefaultMapping() {
115 return (isMap() || isCollection()) && (getType().isInterface()) || isArray();
116 }
117
118
119
120
121 public Map<String, PropertyTypeDescriptor> getPropertyDescriptors(TypeMapping typeMapping) {
122
123 if(this.descriptors == null){
124
125
126
127 final Map<String, PropertyTypeDescriptor> tmpDescriptors = new HashMap<String, PropertyTypeDescriptor>();
128 PropertyDescriptor[] dscrs = PropertyUtils.getPropertyDescriptors(this.getType());
129 for (int i = 0; i < dscrs.length; i++) {
130 PropertyDescriptor descriptor = dscrs[i];
131 tmpDescriptors.put(descriptor.getName(), typeMapping.getPropertyTypeDescriptor(this.getType(), descriptor.getName()));
132 }
133
134 this.descriptors = Collections.unmodifiableMap(tmpDescriptors);
135 }
136 return this.descriptors;
137 }
138
139
140
141
142 public Node2BeanTransformer getTransformer() {
143 return transformer;
144 }
145
146 public void setTransformer(Node2BeanTransformer transformer) {
147 this.transformer = transformer;
148 }
149
150 }