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