Coverage Report - org.apache.commons.configuration.tree.ViewNode
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewNode
100%
25/25
100%
12/12
3
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.configuration.tree;
 18  
 
 19  
 
 20  
 /**
 21  
  * <p>
 22  
  * A specialized node implementation to be used in view configurations.
 23  
  * </p>
 24  
  * <p>
 25  
  * Some configurations provide a logical view on the nodes of other
 26  
  * configurations. These configurations construct their own hierarchy of nodes
 27  
  * based on the node trees of their source configurations. This special node
 28  
  * class can be used for this purpose. It allows child nodes and attributes to
 29  
  * be added without changing their parent node. So a node can belong to a
 30  
  * hierarchy of nodes of a source configuration, but be also contained in a view
 31  
  * configuration.
 32  
  * </p>
 33  
  *
 34  
  * @author <a
 35  
  * href="http://commons.apache.org/configuration/team-list.html">Commons
 36  
  * Configuration team</a>
 37  
  * @version $Id: ViewNode.java 1206488 2011-11-26 16:42:41Z oheger $
 38  
  * @since 1.3
 39  
  */
 40  12761
 public class ViewNode extends DefaultConfigurationNode
 41  
 {
 42  
     /**
 43  
      * Adds an attribute to this view node. The new attribute's parent node will
 44  
      * be saved.
 45  
      *
 46  
      * @param attr the attribute node to be added
 47  
      */
 48  
     @Override
 49  
     public void addAttribute(ConfigurationNode attr)
 50  
     {
 51  3667
         ConfigurationNode parent = null;
 52  
 
 53  3666
         if (attr != null)
 54  
         {
 55  3663
             parent = attr.getParentNode();
 56  3661
             super.addAttribute(attr);
 57  3665
             attr.setParentNode(parent);
 58  
         }
 59  
         else
 60  
         {
 61  1
             throw new IllegalArgumentException("Attribute node must not be null!");
 62  
         }
 63  3665
     }
 64  
 
 65  
     /**
 66  
      * Adds a child node to this view node. The new child's parent node will be
 67  
      * saved.
 68  
      *
 69  
      * @param child the child node to be added
 70  
      */
 71  
     @Override
 72  
     public void addChild(ConfigurationNode child)
 73  
     {
 74  27335
         ConfigurationNode parent = null;
 75  
 
 76  27337
         if (child != null)
 77  
         {
 78  27331
             parent = child.getParentNode();
 79  27332
             super.addChild(child);
 80  27336
             child.setParentNode(parent);
 81  
         }
 82  
         else
 83  
         {
 84  1
             throw new IllegalArgumentException("Child node must not be null!");
 85  
         }
 86  27325
     }
 87  
 
 88  
     /**
 89  
      * Adds all attribute nodes of the given source node to this view node.
 90  
      *
 91  
      * @param source the source node
 92  
      */
 93  
     public void appendAttributes(ConfigurationNode source)
 94  
     {
 95  10673
         if (source != null)
 96  
         {
 97  10668
             for (ConfigurationNode attr : source.getAttributes())
 98  
             {
 99  3155
                 addAttribute(attr);
 100  3153
             }
 101  
         }
 102  10663
     }
 103  
 
 104  
     /**
 105  
      * Adds all child nodes of the given source node to this view node.
 106  
      *
 107  
      * @param source the source node
 108  
      */
 109  
     public void appendChildren(ConfigurationNode source)
 110  
     {
 111  4269
         if (source != null)
 112  
         {
 113  4269
             for (ConfigurationNode child : source.getChildren())
 114  
             {
 115  10003
                 addChild(child);
 116  10000
             }
 117  
         }
 118  4271
     }
 119  
 }