Coverage Report - org.kuali.rice.kns.util.documentserializer.PropertySerializerTrieNode
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertySerializerTrieNode
0%
0/33
0%
0/16
2.111
 
 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.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 /**
 23  
  * A node in the trie.
 24  
  *
 25  
  */
 26  
 public class PropertySerializerTrieNode implements PropertySerializabilityMetadata {
 27  
     private String pathString;
 28  
     private String propertyNameComponent;
 29  
     private PropertySerializability propertySerializability;
 30  
     
 31  
     private List<PropertySerializerTrieNode> childNodes;
 32  
     
 33  0
     public PropertySerializerTrieNode(String pathString, String propertyNameComponent) {
 34  0
         this.pathString = pathString;
 35  0
         this.propertyNameComponent = propertyNameComponent;
 36  0
         this.childNodes = null;
 37  0
         this.propertySerializability = PropertySerializability.SERIALIZE_OBJECT;
 38  0
     }
 39  
     
 40  
     public void addChildNode(PropertySerializerTrieNode child) {
 41  0
         if (childNodes == null) {
 42  0
             childNodes = new ArrayList<PropertySerializerTrieNode>();
 43  
         }
 44  0
         childNodes.add(child);
 45  0
     }
 46  
     
 47  
     /**
 48  
      * The name of this property, relative to the parent node (i.e. the child node name relative to its parents). 
 49  
      * 
 50  
      * @return
 51  
      */
 52  
     public String getPropertyNameComponent() {
 53  0
         return propertyNameComponent;
 54  
     }
 55  
     
 56  
     /**
 57  
      * Retrieves the child node with the given name
 58  
      * 
 59  
      * @param propertyNameComponent
 60  
      * @return
 61  
      */
 62  
     public PropertySerializerTrieNode getChildNode(String propertyNameComponent) {
 63  0
         if (childNodes == null) {
 64  0
             return null;
 65  
         }
 66  0
         for (int i = 0; i < childNodes.size(); i++) {
 67  0
             PropertySerializerTrieNode childNode = childNodes.get(i);
 68  0
             if (childNode.getPropertyNameComponent().equals(propertyNameComponent)) {
 69  0
                 return childNode;
 70  
             }
 71  
         }
 72  0
         return null;
 73  
     }
 74  
     
 75  
     /**
 76  
      * @see org.kuali.rice.kns.util.documentserializer.PropertySerializabilityMetadata#getSerializableChildProperty(java.lang.String)
 77  
      */
 78  
     public PropertySerializabilityMetadata getSerializableChildProperty(String propertyNameComponent) {
 79  0
         return getChildNode(propertyNameComponent);
 80  
     }
 81  
     
 82  
     /**
 83  
      * @see org.kuali.rice.kns.util.documentserializer.PropertySerializabilityMetadata#getPathString()
 84  
      */
 85  
     public String getPathString() {
 86  0
         return pathString;
 87  
     }
 88  
 
 89  
     /**
 90  
      * @see org.kuali.rice.kns.util.documentserializer.PropertySerializabilityMetadata#getPropertySerializability()
 91  
      */
 92  
     public PropertySerializability getPropertySerializability() {
 93  0
         return propertySerializability;
 94  
     }
 95  
 
 96  
     /**
 97  
      * Marks that all primitives of this object will be serialized.
 98  
      */
 99  
     public void setPropertySerializabilityToObjectAndAllPrimitives() {
 100  0
         this.propertySerializability = PropertySerializability.SERIALIZE_OBJECT_AND_ALL_PRIMITIVES;
 101  0
     }
 102  
 
 103  
     @Override
 104  
     public String toString() {
 105  0
         StringBuilder buf = new StringBuilder();
 106  0
         buf.append("Path String: ").append(pathString).append(" Name component: ").append(propertyNameComponent);
 107  0
         if (childNodes == null || childNodes.isEmpty()) {
 108  0
             buf.append(" No child nodes.");
 109  
         }
 110  
         else {
 111  0
             buf.append(" Child nodes: ");
 112  0
             for (Iterator<PropertySerializerTrieNode> i = childNodes.iterator(); i.hasNext();) {
 113  0
                 buf.append(i.next().getPropertyNameComponent());
 114  0
                 if (i.hasNext()) {
 115  0
                     buf.append(", ");
 116  
                 }
 117  
             }
 118  
         }
 119  0
         return super.toString();
 120  
     }
 121  
 }