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 public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
32
33
34
35
36
37
38 public String serializeBusinessObjectToXml(BusinessObject businessObject) {
39 PropertySerializabilityEvaluator propertySerizabilityEvaluator = getPropertySerizabilityEvaluator(businessObject);
40 evaluators.set(propertySerizabilityEvaluator);
41 SerializationState state = new SerializationState();
42 serializationStates.set(state);
43
44
45 String xml;
46 if (propertySerizabilityEvaluator instanceof AlwaysTruePropertySerializibilityEvaluator) {
47 xml = getXmlObjectSerializerService().toXml(businessObject);
48 }
49 else {
50 xml = xstream.toXML(businessObject);
51 }
52
53 evaluators.set(null);
54 serializationStates.set(null);
55 return xml;
56 }
57
58 public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(BusinessObject businessObject) {
59 MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService =
60 KNSServiceLocator.getMaintenanceDocumentDictionaryService();
61 String docTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(businessObject.getClass());
62 MaintenanceDocumentEntry maintenanceDocumentEntry = maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(docTypeName);
63 List<MaintainableSectionDefinition> maintainableSectionDefinitions = maintenanceDocumentEntry.getMaintainableSections();
64 if (maintainableSectionDefinitions == null) {
65 return new AlwaysTruePropertySerializibilityEvaluator();
66 }
67 else {
68 PropertySerializabilityEvaluator evaluator = new MaintenanceDocumentPropertySerializibilityEvaluator();
69 evaluator.initializeEvaluator(businessObject);
70 return evaluator;
71 }
72 }
73 }