Coverage Report - org.simpleframework.xml.stream.InputAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
InputAttribute
44%
11/25
N/A
1
 
 1  
 /*
 2  
  * InputAttribute.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * This library is free software; you can redistribute it and/or
 7  
  * modify it under the terms of the GNU Lesser General Public
 8  
  * License as published by the Free Software Foundation.
 9  
  *
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  
  * GNU Lesser General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU Lesser General 
 16  
  * Public License along with this library; if not, write to the 
 17  
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 18  
  * Boston, MA  02111-1307  USA
 19  
  */
 20  
 
 21  
 package org.simpleframework.xml.stream;
 22  
 
 23  
 import javax.xml.stream.events.Attribute;
 24  
 import javax.xml.namespace.QName;
 25  
 
 26  
 /**
 27  
  * The <code>InputAttribute</code> is used to represent an attribute
 28  
  * within an element. Rather than representing an attribute as a
 29  
  * name value pair of strings, an attribute is instead represented
 30  
  * as an input node, in the same manner as an element. The reason
 31  
  * for representing an attribute in this way is such that a uniform
 32  
  * means of extracting and parsing values can be used for inputs.
 33  
  *
 34  
  * @author Niall Gallagher
 35  
  */ 
 36  0
 class InputAttribute implements InputNode {
 37  
         
 38  
    /**
 39  
     * This is the parent node to this attribute instance.
 40  
     */
 41  
    private InputNode parent;
 42  
            
 43  
    /**
 44  
     * Represents the source attribute if one was specified.
 45  
     */         
 46  
    private Attribute source;
 47  
         
 48  
    /**
 49  
     * Represents the name of this input attribute instance.
 50  
     */         
 51  
    private String name;
 52  
 
 53  
    /**
 54  
     * Represents the value for this input attribute instance.
 55  
     */ 
 56  
    private String value;  
 57  
         
 58  
    /**
 59  
     * Constructor for the <code>InputAttribute</code> object. This
 60  
     * is used to wrap a an attribute as an input node object. The
 61  
     * attribute can then be used in a similar manner to elements.
 62  
     *
 63  
     * @param parent this is the parent node to this attribute
 64  
     * @param source this is the attribute that this will wrap
 65  
     */   
 66  
    public InputAttribute(InputNode parent, Attribute source) {
 67  350198
       this(parent, source, source.getName());
 68  350198
    }        
 69  
 
 70  
    /**
 71  
     * Constructor for the <code>InputAttribute</code> object. This
 72  
     * is used to wrap a an attribute as an input node object. The
 73  
     * attribute can then be used in a similar manner to elements.
 74  
     *
 75  
     * @param parent this is the parent node to this attribute
 76  
     * @param source this is the attribute that this will wrap
 77  
     * @param name this is the name of the XML attribute
 78  
     */   
 79  350198
    private InputAttribute(InputNode parent, Attribute source, QName name) {
 80  350198
       this.name = name.getLocalPart();
 81  350198
       this.value = source.getValue();
 82  350198
       this.source = source;      
 83  350198
    }
 84  
 
 85  
    /**
 86  
     * Constructor for the <code>InputAttribute</code> object. This
 87  
     * is used to create an input attribute using the provided name
 88  
     * and value, all other values for this input node will be null.
 89  
     * 
 90  
     * @param parent this is the parent node to this attribute
 91  
     * @param name this is the name for this attribute object
 92  
     * @param value this is the value for this attribute object
 93  
     */     
 94  0
    public InputAttribute(InputNode parent, String name, String value) {
 95  0
           this.parent = parent;
 96  0
       this.value = value;
 97  0
       this.name = name;           
 98  0
    }
 99  
    
 100  
    /**
 101  
     * This is used to acquire the <code>Node</code> that is the
 102  
     * parent of this node. This will return the node that is
 103  
     * the direct parent of this node and allows for siblings to
 104  
     * make use of nodes with their parents if required.  
 105  
     *   
 106  
     * @return this returns the parent node for this node
 107  
     */
 108  
    public InputNode getParent() {
 109  0
            return parent;
 110  
    }
 111  
    
 112  
    /**
 113  
     * This provides the position of this node within the document.
 114  
     * This allows the user of this node to report problems with
 115  
     * the location within the document, allowing the XML to be
 116  
     * debugged if it does not match the class schema.
 117  
     *
 118  
     * @return this returns the position of the XML read cursor
 119  
     */  
 120  
    public Position getPosition() {
 121  306364
       return new InputPosition(source);           
 122  
    }
 123  
 
 124  
    /**
 125  
     * Returns the name of the node that this represents. This is
 126  
     * an immutable property and will not change for this node. 
 127  
     *  
 128  
     * @return returns the name of the node that this represents
 129  
     */   
 130  
    public String getName() {
 131  655815
       return name;
 132  
    }
 133  
 
 134  
    /**
 135  
     * Returns the value for the node that this represents. This 
 136  
     * is an immutable value for the node and cannot be changed.
 137  
     * 
 138  
     * @return the name of the value for this node instance
 139  
     */   
 140  
    public String getValue() {
 141  350179
       return value;
 142  
    }
 143  
    
 144  
    /**
 145  
     * This method is used to determine if this node is the root 
 146  
     * node for the XML document. This will return false as this 
 147  
     * node can never be the root node because it is an attribute.
 148  
     * 
 149  
     * @return this will always return false for attribute nodes
 150  
     */
 151  
    public boolean isRoot() {
 152  0
       return false;
 153  
    }
 154  
 
 155  
    /**
 156  
     * This is used to determine if this node is an element. This
 157  
     * node instance can not be an element so this method returns
 158  
     * false. Returning null tells the users of this node that any
 159  
     * attributes added to the node map will be permenantly lost.
 160  
     *
 161  
     * @return this returns false as this is an attribute node
 162  
     */ 
 163  
    public boolean isElement() {
 164  305644
       return false;           
 165  
    } 
 166  
 
 167  
    /**
 168  
     * Because the <code>InputAttribute</code> object represents an
 169  
     * attribute this method will return null. If nodes are added 
 170  
     * to the node map the values will not be available here.
 171  
     *
 172  
     * @return this always returns null for a requested attribute
 173  
     */ 
 174  
    public InputNode getAttribute(String name) {
 175  0
       return null;
 176  
    }
 177  
 
 178  
    /**
 179  
     * Because the <code>InputAttribute</code> object represents an
 180  
     * attribute this method will return an empty map. If nodes are
 181  
     * added to the node map the values will not be maintained.
 182  
     *
 183  
     * @return this always returns an empty node map of attributes
 184  
     */
 185  
    public NodeMap getAttributes() {
 186  0
       return new InputNodeMap(this);
 187  
    }
 188  
    
 189  
    /**
 190  
     * Because the <code>InputAttribute</code> object represents an
 191  
     * attribute this method will return null. An attribute is a
 192  
     * simple name value pair an so can not contain any child nodes.
 193  
     *
 194  
     * @return this always returns null for a requested child node
 195  
     */
 196  
    public InputNode getNext() {
 197  0
       return null;           
 198  
    }
 199  
    
 200  
    /**
 201  
     * Because the <code>InputAttribute</code> object represents an
 202  
     * attribute this method will return null. An attribute is a
 203  
     * simple name value pair an so can not contain any child nodes.
 204  
     *
 205  
     * @param name this is the name of the next expected element
 206  
     *
 207  
     * @return this always returns null for a requested child node
 208  
     */
 209  
    public InputNode getNext(String name) {
 210  0
       return null;           
 211  
    }
 212  
    
 213  
    /**
 214  
     * This method is used to skip all child elements from this
 215  
     * element. This allows elements to be effectively skipped such
 216  
     * that when parsing a document if an element is not required
 217  
     * then that element can be completely removed from the XML.
 218  
     */ 
 219  
    public void skip() {
 220  0
       return;           
 221  
    }
 222  
    
 223  
    /**
 224  
     * This is used to determine if this input node is empty. An
 225  
     * empty node is one with no attributes or children. This can
 226  
     * be used to determine if a given node represents an empty
 227  
     * entity, with which no extra data can be extracted.
 228  
     * 
 229  
     * @return this will always return false as it has a value
 230  
     */
 231  
    public boolean isEmpty() {
 232  0
       return false;
 233  
    }
 234  
 }