Coverage Report - org.kuali.rice.kns.util.documentserializer.DocumentSerializationState
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentSerializationState
0%
0/11
N/A
1
DocumentSerializationState$SerializationPropertyElement
0%
0/6
N/A
1
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.util.documentserializer;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.rice.kns.bo.BusinessObject;
 23  
 import org.kuali.rice.kns.service.impl.DocumentSerializerServiceImpl;
 24  
 
 25  
 /**
 26  
  * This object keeps track of most of the open tags while a document is serialized.  Note that instances of this class
 27  
  * may not necessarily hold all open tags of a document while it is being serialized.  For example, tags enclosing list elements
 28  
  * and map entries are not contained within here.  See {@link DocumentSerializerServiceImpl} to determine when this object's state
 29  
  * is modified.
 30  
  * 
 31  
  * This class's manipulators behave much like a stack, but it has random access characteristics like an array. 
 32  
  */
 33  
 public class DocumentSerializationState {
 34  
     protected class SerializationPropertyElement {
 35  
         private String elementName;
 36  
         private PropertyType propertyType;
 37  
         
 38  0
         public SerializationPropertyElement(String elementName, PropertyType propertyType) {
 39  0
             this.elementName = elementName;
 40  0
             this.propertyType = propertyType;
 41  0
         }
 42  
         
 43  
         public String getElementName() {
 44  0
             return this.elementName;
 45  
         }
 46  
         
 47  
         public PropertyType getPropertyType() {
 48  0
             return this.propertyType;
 49  
         }
 50  
     }
 51  
     
 52  
     private List<SerializationPropertyElement> pathElements;
 53  
     
 54  0
     public DocumentSerializationState() {
 55  0
         pathElements = new ArrayList<SerializationPropertyElement>();
 56  0
     }
 57  
     
 58  
     /**
 59  
      * The number of property elements in this state object.
 60  
      * 
 61  
      * @return
 62  
      */
 63  
     public int numPropertyElements() {
 64  0
         return pathElements.size();
 65  
     }
 66  
     
 67  
     /**
 68  
      * Adds an additional state element into this object.
 69  
      * 
 70  
      * @param elementName
 71  
      * @param propertyType the type of the property when it was serialized
 72  
      */
 73  
     public void addSerializedProperty(String elementName, PropertyType propertyType) {
 74  0
         SerializationPropertyElement serializationPropertyElement = new SerializationPropertyElement(elementName, propertyType);
 75  0
         pathElements.add(serializationPropertyElement);
 76  0
     }
 77  
     
 78  
     /**
 79  
      * Removes the last added serialized property
 80  
      * 
 81  
      */
 82  
     public void removeSerializedProperty() {
 83  0
         pathElements.remove(pathElements.size() - 1);
 84  0
     }
 85  
     
 86  
     /**
 87  
      * Retrieves the element name of the state element.  A parameter value of 0 represents the first element that was added
 88  
      * by calling {@link #addSerializedProperty(String, PropertyType)} that hasn't been removed, and a value of 
 89  
      * {@link #numPropertyElements()} - 1 represents the element last added that hasn't been removed. 
 90  
      * 
 91  
      * @param propertyIndex most be between 0 and the value returned by {@link #numPropertyElements()} - 1
 92  
      * @return
 93  
      */
 94  
     public String getElementName(int propertyIndex) {
 95  0
         return pathElements.get(propertyIndex).getElementName();
 96  
     }
 97  
     
 98  
     /**
 99  
      * Retrieves the property type of the state element.  A parameter value of 0 represents the first element that was added
 100  
      * by calling {@link #addSerializedProperty(String, PropertyType)} that hasn't been removed, and a value of 
 101  
      * {@link #numPropertyElements()} - 1 represents the element last added that hasn't been removed.
 102  
      * 
 103  
      * @param propertyIndex most be between 0 and the value returned by {@link #numPropertyElements()} - 1
 104  
      * @return
 105  
      */
 106  
     public PropertyType getPropertyType(int propertyIndex) {
 107  0
         return pathElements.get(propertyIndex).getPropertyType();
 108  
     }
 109  
 }