Coverage Report - org.simpleframework.xml.stream.OutputNodeMap
 
Classes in this File Line Coverage Branch Coverage Complexity
OutputNodeMap
92%
12/13
50%
1/2
1.143
 
 1  
 /*
 2  
  * OutputNodeMap.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.stream;
 20  
 
 21  
 import java.util.LinkedHashMap;
 22  
 import java.util.Iterator;
 23  
 
 24  
 /**
 25  
  * The <code>OutputNodeMap</code> is used to collect attribute nodes
 26  
  * for an output node. This will create a generic node to add to the
 27  
  * map. The nodes created will be used by the output node to write
 28  
  * attributes for an element.
 29  
  * 
 30  
  * @author Niall Gallagher
 31  
  */ 
 32  385412
 class OutputNodeMap extends LinkedHashMap<String, OutputNode> implements NodeMap<OutputNode> {
 33  
 
 34  
    /**
 35  
     * This is the source node that this node map belongs to.
 36  
     */         
 37  
    private final OutputNode source;
 38  
         
 39  
    /**
 40  
     * Constructor for the <code>OutputNodeMap</code> object. This is
 41  
     * used to create a node map that is used to create and collect
 42  
     * nodes, which will be used as attributes for an output element.
 43  
     */         
 44  586536
    public OutputNodeMap(OutputNode source) {
 45  586536
       this.source = source;           
 46  586536
    }   
 47  
    
 48  
    /**
 49  
     * This is used to acquire the actual node this map represents.
 50  
     * The source node provides further details on the context of
 51  
     * the node, such as the parent name, the namespace, and even
 52  
     * the value in the node. Care should be taken when using this. 
 53  
     * 
 54  
     * @return this returns the node that this map represents
 55  
     */
 56  
    public OutputNode getNode() {
 57  52015
        return source;
 58  
    }
 59  
    
 60  
    /**
 61  
     * This is used to get the name of the element that owns the
 62  
     * nodes for the specified map. This can be used to determine
 63  
     * which element the node map belongs to.
 64  
     * 
 65  
     * @return this returns the name of the owning element
 66  
     */  
 67  
    public String getName() {
 68  0
       return source.getName();           
 69  
    }   
 70  
 
 71  
    /**
 72  
     * This is used to add a new <code>Node</code> to the map. The
 73  
     * node that is created is a simple name value pair. Once the
 74  
     * node is created it can be retrieved by its given name.
 75  
     *
 76  
     * @param name this is the name of the node to be created
 77  
     * @param value this is the value to be given to the node
 78  
     * 
 79  
     * @return this is the node that has been added to the map
 80  
     */    
 81  
    public OutputNode put(String name, String value) {
 82  271292
       OutputNode node = new OutputAttribute(source, name, value);
 83  
       
 84  271292
       if(source != null) {
 85  271292
          put(name, node);
 86  
       }
 87  271292
       return node;
 88  
    }
 89  
    
 90  
    /**
 91  
     * This is used to remove the <code>Node</code> mapped to the
 92  
     * given name.  This returns a name value pair that represents
 93  
     * an attribute. If no node is mapped to the specified name 
 94  
     * then this method will a return null value.
 95  
     *
 96  
     * @param name this is the name of the node to remove
 97  
     * 
 98  
     * @return this will return the node mapped to the given name
 99  
     */    
 100  
    public OutputNode remove(String name) {
 101  220
       return super.remove(name);
 102  
    }
 103  
 
 104  
    /**
 105  
     * This is used to acquire the <code>Node</code> mapped to the
 106  
     * given name. This returns a name value pair that represents
 107  
     * an element. If no node is mapped to the specified name then 
 108  
     * this method will return a null value.
 109  
     *
 110  
     * @param name this is the name of the node to retrieve
 111  
     * 
 112  
     * @return this will return the node mapped to the given name
 113  
     */   
 114  
    public OutputNode get(String name) {
 115  271204
       return super.get(name);
 116  
    }
 117  
 
 118  
    /**
 119  
     * This returns an iterator for the names of all the nodes in
 120  
     * this <code>OutputNodeMap</code>. This allows the names to be 
 121  
     * iterated within a for each loop in order to extract nodes.
 122  
     *
 123  
     * @return this returns the names of the nodes in the map
 124  
     */    
 125  
    public Iterator<String> iterator() {
 126  561691
       return keySet().iterator();           
 127  
    }
 128  
 }