1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util.documentserializer;
17
18 import org.kuali.rice.krad.bo.BusinessObject;
19 import org.kuali.rice.krad.document.Document;
20 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityMetadata.PropertySerializability;
21
22 import java.util.Collection;
23 import java.util.Map;
24
25
26
27
28
29
30 public abstract class PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator {
31
32 protected PropertySerializerTrie serializableProperties;
33
34 @Override
35 public void initializeEvaluatorForDocument(Document document){
36
37 }
38
39 @Override
40 public void initializeEvaluatorForDataObject(Object businessObject){
41
42 }
43
44
45
46
47 @Override
48 public PropertyType determinePropertyType(Object propertyValue) {
49 if (propertyValue == null) {
50 return PropertyType.PRIMITIVE;
51 }
52 if (propertyValue instanceof BusinessObject) {
53 return PropertyType.BUSINESS_OBJECT;
54 }
55 if (propertyValue instanceof Collection) {
56 return PropertyType.COLLECTION;
57 }
58 if (propertyValue instanceof Map) {
59 return PropertyType.MAP;
60 }
61 return PropertyType.PRIMITIVE;
62 }
63
64
65
66
67
68
69 @Override
70 public boolean isPropertySerializable(SerializationState state, Object containingObject, String childPropertyName, Object childPropertyValue) {
71 boolean allPropertiesMatched = true;
72
73 PropertySerializabilityMetadata metadata = serializableProperties.getRootPropertySerializibilityMetadata();
74 int i = 0;
75 for (; i < state.numPropertyElements(); i++) {
76 String nextPropertyName = state.getElementName(i);
77 PropertySerializabilityMetadata nextMetadata = metadata.getSerializableChildProperty(nextPropertyName);
78
79 if (nextMetadata == null) {
80 allPropertiesMatched = false;
81 break;
82 }
83 else {
84
85 metadata = nextMetadata;
86 }
87 }
88
89 if (allPropertiesMatched) {
90
91 return evaluateCompleteMatch(state, containingObject, metadata, childPropertyName, childPropertyValue);
92 }
93 else {
94
95
96
97
98
99 return evaluatePartialMatch(state, i, containingObject, metadata, childPropertyName, childPropertyValue);
100 }
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114 protected boolean evaluateCompleteMatch(SerializationState state, Object containingObject, PropertySerializabilityMetadata metadata, String childPropertyName, Object childPropertyValue) {
115 if (metadata.getPropertySerializability().equals(PropertySerializability.SERIALIZE_OBJECT_AND_ALL_PRIMITIVES)) {
116 if (isPrimitiveObject(childPropertyValue)) {
117 return true;
118 }
119 }
120 return metadata.getSerializableChildProperty(childPropertyName) != null;
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135 protected boolean evaluatePartialMatch(SerializationState state, int lastMatchedStateIndex, Object containingObject, PropertySerializabilityMetadata metadata, String childPropertyName, Object childPropertyValue) {
136
137 if (metadata.getPropertySerializability().equals(PropertySerializability.SERIALIZE_OBJECT_AND_ALL_PRIMITIVES)) {
138 return isPrimitiveObject(childPropertyValue);
139 }
140 return false;
141 }
142
143
144
145
146
147
148
149 protected boolean isPrimitiveObject(Object object) {
150 return PropertyType.PRIMITIVE.equals(determinePropertyType(object));
151 }
152
153 }