1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.kns.bo.BusinessObject; |
21 | |
import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition; |
22 | |
import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry; |
23 | |
import org.kuali.rice.kns.service.BusinessObjectSerializerService; |
24 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
25 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
26 | |
import org.kuali.rice.kns.util.documentserializer.AlwaysTruePropertySerializibilityEvaluator; |
27 | |
import org.kuali.rice.kns.util.documentserializer.MaintenanceDocumentPropertySerializibilityEvaluator; |
28 | |
import org.kuali.rice.kns.util.documentserializer.PropertySerializabilityEvaluator; |
29 | |
import org.kuali.rice.kns.util.documentserializer.SerializationState; |
30 | |
|
31 | 0 | public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService { |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public String serializeBusinessObjectToXml(BusinessObject businessObject) { |
39 | 0 | PropertySerializabilityEvaluator propertySerizabilityEvaluator = getPropertySerizabilityEvaluator(businessObject); |
40 | 0 | evaluators.set(propertySerizabilityEvaluator); |
41 | 0 | SerializationState state = new SerializationState(); |
42 | 0 | serializationStates.set(state); |
43 | |
|
44 | |
|
45 | |
String xml; |
46 | 0 | if (propertySerizabilityEvaluator instanceof AlwaysTruePropertySerializibilityEvaluator) { |
47 | 0 | xml = getXmlObjectSerializerService().toXml(businessObject); |
48 | |
} |
49 | |
else { |
50 | 0 | xml = xstream.toXML(businessObject); |
51 | |
} |
52 | |
|
53 | 0 | evaluators.set(null); |
54 | 0 | serializationStates.set(null); |
55 | 0 | return xml; |
56 | |
} |
57 | |
|
58 | |
public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(BusinessObject businessObject) { |
59 | 0 | MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = |
60 | |
KNSServiceLocator.getMaintenanceDocumentDictionaryService(); |
61 | 0 | String docTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(businessObject.getClass()); |
62 | 0 | MaintenanceDocumentEntry maintenanceDocumentEntry = maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(docTypeName); |
63 | 0 | List<MaintainableSectionDefinition> maintainableSectionDefinitions = maintenanceDocumentEntry.getMaintainableSections(); |
64 | 0 | if (maintainableSectionDefinitions == null) { |
65 | 0 | return new AlwaysTruePropertySerializibilityEvaluator(); |
66 | |
} |
67 | |
else { |
68 | 0 | PropertySerializabilityEvaluator evaluator = new MaintenanceDocumentPropertySerializibilityEvaluator(); |
69 | 0 | evaluator.initializeEvaluator(businessObject); |
70 | 0 | return evaluator; |
71 | |
} |
72 | |
} |
73 | |
} |