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