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 public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
28
29 private DocumentDictionaryService documentDictionaryService;
30
31
32
33
34
35
36 public String serializeBusinessObjectToXml(Object businessObject) {
37 PropertySerializabilityEvaluator propertySerizabilityEvaluator =
38 getPropertySerizabilityEvaluator(businessObject);
39 evaluators.set(propertySerizabilityEvaluator);
40 SerializationState state = new SerializationState();
41 serializationStates.set(state);
42
43
44 String xml;
45 if (propertySerizabilityEvaluator instanceof AlwaysTruePropertySerializibilityEvaluator) {
46 xml = getXmlObjectSerializerService().toXml(businessObject);
47 } else {
48 xml = xstream.toXML(businessObject);
49 }
50
51 evaluators.set(null);
52 serializationStates.set(null);
53 return xml;
54 }
55
56 public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(Object businessObject) {
57 PropertySerializabilityEvaluator evaluator = null;
58
59 String docTypeName = getDocumentDictionaryService().getMaintenanceDocumentTypeName(businessObject.getClass());
60 MaintenanceDocumentEntry maintenanceDocumentEntry =
61 getDocumentDictionaryService().getMaintenanceDocumentEntry(docTypeName);
62
63
64 evaluator = new AlwaysTruePropertySerializibilityEvaluator();
65
66 return evaluator;
67 }
68
69 protected DocumentDictionaryService getDocumentDictionaryService() {
70 if (documentDictionaryService == null) {
71 this.documentDictionaryService = KRADServiceLocatorWeb.getDocumentDictionaryService();
72 }
73 return documentDictionaryService;
74 }
75
76 public void setDocumentDictionaryService(DocumentDictionaryService documentDictionaryService) {
77 this.documentDictionaryService = documentDictionaryService;
78 }
79 }