View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
31  
32      private DocumentDictionaryService documentDictionaryService;
33  
34      /**
35       * @see org.kuali.rice.krad.service.DocumentSerializerService#serializeDocumentToXml(org.kuali.rice.krad.document.Document)
36       */
37      public String serializeBusinessObjectToXml(Object businessObject) {
38          PropertySerializabilityEvaluator propertySerizabilityEvaluator =
39                  getPropertySerizabilityEvaluator(businessObject);
40          evaluators.set(propertySerizabilityEvaluator);
41          SerializationState state = new SerializationState(); //createNewDocumentSerializationState(document);
42          serializationStates.set(state);
43  
44          //Object xmlWrapper = null;//wrapDocumentWithMetadata(document);
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          // TODO: need to determine view properties to serialize
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  }