1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18
19 import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
20 import org.kuali.rice.krad.service.BusinessObjectSerializerService;
21 import org.kuali.rice.krad.service.DocumentDictionaryService;
22 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23 import org.kuali.rice.krad.util.documentserializer.AlwaysTruePropertySerializibilityEvaluator;
24 import org.kuali.rice.krad.util.documentserializer.PropertySerializabilityEvaluator;
25 import org.kuali.rice.krad.util.documentserializer.SerializationState;
26
27
28
29
30 public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
31
32 private DocumentDictionaryService documentDictionaryService;
33
34
35
36
37 public String serializeBusinessObjectToXml(Object businessObject) {
38 PropertySerializabilityEvaluator propertySerizabilityEvaluator =
39 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 } else {
49 xml = xstream.toXML(businessObject);
50 }
51
52 evaluators.set(null);
53 serializationStates.set(null);
54 return xml;
55 }
56
57 public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(Object businessObject) {
58 PropertySerializabilityEvaluator evaluator = null;
59
60 String docTypeName = getDocumentDictionaryService().getMaintenanceDocumentTypeName(businessObject.getClass());
61 MaintenanceDocumentEntry maintenanceDocumentEntry =
62 getDocumentDictionaryService().getMaintenanceDocumentEntry(docTypeName);
63
64
65 evaluator = new AlwaysTruePropertySerializibilityEvaluator();
66
67 return evaluator;
68 }
69
70 protected DocumentDictionaryService getDocumentDictionaryService() {
71 if (documentDictionaryService == null) {
72 this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
73 }
74 return documentDictionaryService;
75 }
76
77 public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
78 this.documentDictionaryService = documentDictionaryService;
79 }
80 }