View Javadoc

1   /**
2    * Copyright 2005-2013 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  public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
28  
29      private DocumentDictionaryService documentDictionaryService;
30  
31      /**
32       * Serializes a document for routing
33       *
34       * @see org.kuali.rice.krad.service.DocumentSerializerService#serializeDocumentToXml(org.kuali.rice.krad.document.Document)
35       */
36      public String serializeBusinessObjectToXml(Object businessObject) {
37          PropertySerializabilityEvaluator propertySerizabilityEvaluator =
38                  getPropertySerizabilityEvaluator(businessObject);
39          evaluators.set(propertySerizabilityEvaluator);
40          SerializationState state = new SerializationState(); //createNewDocumentSerializationState(document);
41          serializationStates.set(state);
42  
43          //Object xmlWrapper = null;//wrapDocumentWithMetadata(document);
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          // TODO: need to determine view properties to serialize
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  }