Coverage Report - org.kuali.rice.kns.service.impl.BusinessObjectSerializerServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectSerializerServiceImpl
0%
0/20
0%
0/4
2.5
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.kns.service.impl;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.rice.kns.bo.BusinessObject;
 21  
 import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
 22  
 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
 23  
 import org.kuali.rice.kns.service.BusinessObjectSerializerService;
 24  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 25  
 import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService;
 26  
 import org.kuali.rice.kns.util.documentserializer.AlwaysTruePropertySerializibilityEvaluator;
 27  
 import org.kuali.rice.kns.util.documentserializer.MaintenanceDocumentPropertySerializibilityEvaluator;
 28  
 import org.kuali.rice.kns.util.documentserializer.PropertySerializabilityEvaluator;
 29  
 import org.kuali.rice.kns.util.documentserializer.SerializationState;
 30  
 
 31  0
 public class BusinessObjectSerializerServiceImpl extends SerializerServiceBase implements BusinessObjectSerializerService {
 32  
 
 33  
     /**
 34  
      * Serializes a document for routing
 35  
      * 
 36  
      * @see org.kuali.rice.kns.service.DocumentSerializerService#serializeDocumentToXml(org.kuali.rice.kns.document.Document)
 37  
      */
 38  
     public String serializeBusinessObjectToXml(BusinessObject businessObject) {
 39  0
         PropertySerializabilityEvaluator propertySerizabilityEvaluator = getPropertySerizabilityEvaluator(businessObject);
 40  0
         evaluators.set(propertySerizabilityEvaluator);
 41  0
         SerializationState state = new SerializationState(); //createNewDocumentSerializationState(document);
 42  0
         serializationStates.set(state);
 43  
         
 44  
         //Object xmlWrapper = null;//wrapDocumentWithMetadata(document);
 45  
         String xml;
 46  0
         if (propertySerizabilityEvaluator instanceof AlwaysTruePropertySerializibilityEvaluator) {
 47  0
             xml = getXmlObjectSerializerService().toXml(businessObject);
 48  
         }
 49  
         else {
 50  0
             xml = xstream.toXML(businessObject);
 51  
         }
 52  
         
 53  0
         evaluators.set(null);
 54  0
         serializationStates.set(null);
 55  0
         return xml;
 56  
     }
 57  
 
 58  
     public PropertySerializabilityEvaluator getPropertySerizabilityEvaluator(BusinessObject businessObject) {
 59  0
         MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = 
 60  
                 KNSServiceLocator.getMaintenanceDocumentDictionaryService();
 61  0
         String docTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(businessObject.getClass());
 62  0
         MaintenanceDocumentEntry maintenanceDocumentEntry = maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(docTypeName);
 63  0
         List<MaintainableSectionDefinition> maintainableSectionDefinitions = maintenanceDocumentEntry.getMaintainableSections();
 64  0
         if (maintainableSectionDefinitions == null) {
 65  0
             return new AlwaysTruePropertySerializibilityEvaluator();
 66  
         }
 67  
         else {
 68  0
             PropertySerializabilityEvaluator evaluator = new MaintenanceDocumentPropertySerializibilityEvaluator();
 69  0
             evaluator.initializeEvaluator(businessObject);
 70  0
             return evaluator;
 71  
         }
 72  
     }
 73  
 }