Coverage Report - org.simpleframework.xml.core.EmptyExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
EmptyExpression
58%
10/17
N/A
1
 
 1  
 /*
 2  
  * EmptyExpression May 2007
 3  
  *
 4  
  * Copyright (C) 2007, 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.core;
 20  
 
 21  
 import java.util.Iterator;
 22  
 import java.util.LinkedList;
 23  
 import java.util.List;
 24  
 
 25  
 import org.simpleframework.xml.stream.Format;
 26  
 import org.simpleframework.xml.stream.Style;
 27  
 
 28  
 /**
 29  
  * The <code>EmptyExpression</code> object is used to represent a path
 30  
  * that represents the current context. This is a much more lightweight
 31  
  * alternative to parsing "." with the <code>PathParser</code> object
 32  
  * as it does not require the allocation of collections or buffers.
 33  
  * 
 34  
  * @author Niall Gallagher
 35  
  * 
 36  
  * @see org.simpleframework.xml.core.PathParser
 37  
  */
 38  
 class EmptyExpression implements Expression {
 39  
 
 40  
    /**
 41  
     * This is a list that is used to create an empty iterator.
 42  
     */
 43  
    private final List<String> list;
 44  
    
 45  
    /**
 46  
     * This is the style that is used to style any paths created. 
 47  
     */
 48  
    private final Style style;
 49  
 
 50  
    /**
 51  
     * Constructor for <code>EmptyExpression</code> object. This is
 52  
     * used to create an expression for an empty path. An empty path
 53  
     * is basically the root element ".". 
 54  
     * 
 55  
     * @param format the format used to style the paths created
 56  
     */
 57  5110
    public EmptyExpression(Format format) {
 58  5110
       this.list = new LinkedList<String>();
 59  5110
       this.style = format.getStyle();
 60  5110
    }
 61  
 
 62  
    /**
 63  
     * This is used to iterate over the path segments that have 
 64  
     * been extracted from the source XPath expression. Iteration
 65  
     * over the segments is done in the order they were parsed
 66  
     * from the source path.
 67  
     * 
 68  
     * @return this returns an iterator for the path segments
 69  
     */
 70  
    public Iterator<String> iterator() {
 71  0
       return list.iterator();
 72  
    }
 73  
 
 74  
    /**
 75  
     * If the first path segment contains an index it is provided
 76  
     * by this method. There may be several indexes within a 
 77  
     * path, however only the index at the first segment is issued
 78  
     * by this method. If there is no index this will return 1.
 79  
     * 
 80  
     * @return this returns the index of this path expression
 81  
     */
 82  
    public int getIndex() {
 83  0
       return 0;
 84  
    }
 85  
 
 86  
    /**
 87  
     * This is used to extract a namespace prefix from the path
 88  
     * expression. A prefix is used to qualify the XML element name
 89  
     * and does not form part of the actual path structure. This
 90  
     * can be used to add the namespace in addition to the name.
 91  
     * 
 92  
     * @return this returns the prefix for the path expression
 93  
     */
 94  
    public String getPrefix() {
 95  0
       return null;
 96  
    }
 97  
 
 98  
    /**
 99  
     * This can be used to acquire the first path segment within
 100  
     * the expression. The first segment represents the parent XML
 101  
     * element of the path. All segments returned do not contain
 102  
     * any slashes and so represents the real element name.
 103  
     * 
 104  
     * @return this returns the parent element for the path
 105  
     */
 106  
    public String getFirst() {
 107  0
       return null;
 108  
    }
 109  
 
 110  
    /**
 111  
     * This can be used to acquire the last path segment within
 112  
     * the expression. The last segment represents the leaf XML
 113  
     * element of the path. All segments returned do not contain
 114  
     * any slashes and so represents the real element name.
 115  
     * 
 116  
     * @return this returns the leaf element for the path
 117  
     */ 
 118  
    public String getLast() {
 119  0
       return null;
 120  
    }
 121  
 
 122  
    /**
 123  
     * This location contains the full path expression with all
 124  
     * of the indexes explicitly shown for each path segment. This
 125  
     * is used to create a uniform representation that can be used
 126  
     * for comparisons of different path expressions. 
 127  
     * 
 128  
     * @return this returns an expanded version of the path
 129  
     */
 130  
    public String getPath() {
 131  4589
       return "";
 132  
    }
 133  
 
 134  
    /**
 135  
     * This is used to acquire the element path using this XPath
 136  
     * expression. The element path is simply the fully qualified
 137  
     * path for this expression with the provided name appended.
 138  
     * If this is an empty path, the provided name is returned.
 139  
     * 
 140  
     * @param name this is the name of the element to be used
 141  
     * 
 142  
     * @return a fully qualified path for the specified name
 143  
     */
 144  
    public String getElement(String name) {
 145  1793131
       return style.getElement(name);
 146  
    }
 147  
 
 148  
    /**
 149  
     * This is used to acquire the attribute path using this XPath
 150  
     * expression. The attribute path is simply the fully qualified
 151  
     * path for this expression with the provided name appended.
 152  
     * If this is an empty path, the provided name is returned.
 153  
     * 
 154  
     * @param name this is the name of the attribute to be used
 155  
     * 
 156  
     * @return a fully qualified path for the specified name
 157  
     */
 158  
    public String getAttribute(String name) {
 159  711835
       return style.getAttribute(name);
 160  
    }
 161  
 
 162  
    /**
 163  
     * This allows an expression to be extracted from the current
 164  
     * context. Extracting expressions in this manner makes it 
 165  
     * more convenient for navigating structures representing
 166  
     * the XML document. If an expression can not be extracted
 167  
     * with the given criteria an exception will be thrown.
 168  
     * 
 169  
     * @param from this is the number of segments to skip to
 170  
     * 
 171  
     * @return this returns an expression from this one
 172  
     */
 173  
    public Expression getPath(int from) {
 174  0
       return null;
 175  
    }
 176  
 
 177  
    /**
 178  
     * This allows an expression to be extracted from the current
 179  
     * context. Extracting expressions in this manner makes it 
 180  
     * more convenient for navigating structures representing
 181  
     * the XML document. If an expression can not be extracted
 182  
     * with the given criteria an exception will be thrown.
 183  
     * 
 184  
     * @param from this is the number of segments to skip to
 185  
     * @param trim the number of segments to trim from the end
 186  
     * 
 187  
     * @return this returns an expression from this one
 188  
     */
 189  
    public Expression getPath(int from, int trim) {
 190  0
       return null;
 191  
    }
 192  
 
 193  
    /**
 194  
     * This is used to determine if the expression points to an
 195  
     * attribute value. An attribute value contains an '@' character
 196  
     * before the last segment name. Such expressions distinguish
 197  
     * element references from attribute references.
 198  
     * 
 199  
     * @return this returns true if the path has an attribute
 200  
     */
 201  
    public boolean isAttribute() {
 202  1
       return false;
 203  
    }
 204  
 
 205  
    /**
 206  
     * This is used to determine if the expression is a path. An
 207  
     * expression represents a path if it contains more than one
 208  
     * segment. If only one segment exists it is an element name.
 209  
     * 
 210  
     * @return true if this contains more than one segment
 211  
     */
 212  
    public boolean isPath() {
 213  1
       return false;
 214  
    }
 215  
 
 216  
    /**
 217  
     * This method is used to determine if this expression is an
 218  
     * empty path. An empty path can be represented by a single
 219  
     * period, '.'. It identifies the current path.
 220  
     * 
 221  
     * @return returns true if this represents an empty path
 222  
     */
 223  
    public boolean isEmpty() {
 224  3538
       return true;
 225  
    }
 226  
 }