Coverage Report - org.simpleframework.xml.core.Expression
 
Classes in this File Line Coverage Branch Coverage Complexity
Expression
N/A
N/A
1
 
 1  
 /*
 2  
  * Expression.java November 2010
 3  
  *
 4  
  * Copyright (C) 2010, 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  
 /**
 22  
  * The <code>Expression</code> interface is used to represent an XPath
 23  
  * expression. Any element or attribute may be defined as having an
 24  
  * XPath expression so that it may be located within an XML document.
 25  
  * This provides a convenient interface to navigating structures
 26  
  * based on an XPath expression. The below formats are supported.
 27  
  * <pre>
 28  
  * 
 29  
  *    ./example/path
 30  
  *    ./example[2]/path/
 31  
  *    example/path
 32  
  *    example/path/@attribute
 33  
  *    ./path/@attribute              
 34  
  *    
 35  
  * </pre>
 36  
  * As can be seen only a subset of the XPath syntax is supported by
 37  
  * this. For convenience this provides a means to acquire paths
 38  
  * from within a path, which makes a single expression more useful
 39  
  * when navigating structures representing the XML document.
 40  
  * 
 41  
  * @author Niall Gallagher
 42  
  * 
 43  
  * @see org.simpleframework.xml.core.ExpressionBuilder
 44  
  */
 45  
 interface Expression extends Iterable<String> {
 46  
         
 47  
    /**
 48  
     * If the first path segment contains an index it is provided
 49  
     * by this method. There may be several indexes within a 
 50  
     * path, however only the index at the first segment is issued
 51  
     * by this method. If there is no index this will return 1.
 52  
     * 
 53  
     * @return this returns the index of this path expression
 54  
     */
 55  
    int getIndex();
 56  
    
 57  
    /**
 58  
     * This is used to extract a namespace prefix from the path
 59  
     * expression. A prefix is used to qualify the XML element name
 60  
     * and does not form part of the actual path structure. This
 61  
     * can be used to add the namespace in addition to the name.
 62  
     * 
 63  
     * @return this returns the prefix for the path expression
 64  
     */
 65  
    String getPrefix();
 66  
    
 67  
    /**
 68  
     * This can be used to acquire the first path segment within
 69  
     * the expression. The first segment represents the parent XML
 70  
     * element of the path. All segments returned do not contain
 71  
     * any slashes and so represents the real element name.
 72  
     * 
 73  
     * @return this returns the parent element for the path
 74  
     */
 75  
    String getFirst();
 76  
 
 77  
    /**
 78  
     * This can be used to acquire the last path segment within
 79  
     * the expression. The last segment represents the leaf XML
 80  
     * element of the path. All segments returned do not contain
 81  
     * any slashes and so represents the real element name.
 82  
     * 
 83  
     * @return this returns the leaf element for the path
 84  
     */   
 85  
    String getLast();
 86  
    
 87  
    /**
 88  
     * This location contains the full path expression with all
 89  
     * of the indexes explicitly shown for each path segment. This
 90  
     * is used to create a uniform representation that can be used
 91  
     * for comparisons of different path expressions. 
 92  
     * 
 93  
     * @return this returns an expanded version of the path
 94  
     */
 95  
    String getPath();
 96  
    
 97  
    /**
 98  
     * This is used to acquire the element path using this XPath
 99  
     * expression. The element path is simply the fully qualified
 100  
     * path for this expression with the provided name appended.
 101  
     * If this is an empty path, the provided name is returned.
 102  
     * 
 103  
     * @param name this is the name of the element to be used
 104  
     * 
 105  
     * @return a fully qualified path for the specified name
 106  
     */
 107  
    String getElement(String name);
 108  
    
 109  
    /**
 110  
     * This is used to acquire the attribute path using this XPath
 111  
     * expression. The attribute path is simply the fully qualified
 112  
     * path for this expression with the provided name appended.
 113  
     * If this is an empty path, the provided name is returned.
 114  
     * 
 115  
     * @param name this is the name of the attribute to be used
 116  
     * 
 117  
     * @return a fully qualified path for the specified name
 118  
     */
 119  
    String getAttribute(String name);
 120  
    
 121  
    /**
 122  
     * This allows an expression to be extracted from the current
 123  
     * context. Extracting expressions in this manner makes it 
 124  
     * more convenient for navigating structures representing
 125  
     * the XML document. If an expression can not be extracted
 126  
     * with the given criteria an exception will be thrown.
 127  
     * 
 128  
     * @param from this is the number of segments to skip to
 129  
     * 
 130  
     * @return this returns an expression from this one
 131  
     */
 132  
    Expression getPath(int from);
 133  
    
 134  
    /**
 135  
     * This allows an expression to be extracted from the current
 136  
     * context. Extracting expressions in this manner makes it 
 137  
     * more convenient for navigating structures representing
 138  
     * the XML document. If an expression can not be extracted
 139  
     * with the given criteria an exception will be thrown.
 140  
     * 
 141  
     * @param from this is the number of segments to skip to
 142  
     * @param trim the number of segments to trim from the end
 143  
     * 
 144  
     * @return this returns an expression from this one
 145  
     */
 146  
    Expression getPath(int from, int trim);
 147  
    
 148  
    /**
 149  
     * This is used to determine if the expression points to an
 150  
     * attribute value. An attribute value contains an '@' character
 151  
     * before the last segment name. Such expressions distinguish
 152  
     * element references from attribute references.
 153  
     * 
 154  
     * @return this returns true if the path has an attribute
 155  
     */
 156  
    boolean isAttribute();
 157  
    
 158  
    /**
 159  
     * This is used to determine if the expression is a path. An
 160  
     * expression represents a path if it contains more than one
 161  
     * segment. If only one segment exists it is an element name.
 162  
     * 
 163  
     * @return true if this contains more than one segment
 164  
     */
 165  
    boolean isPath();
 166  
    
 167  
    /**
 168  
     * This method is used to determine if this expression is an
 169  
     * empty path. An empty path can be represented by a single
 170  
     * period, '.'. It identifies the current path.
 171  
     * 
 172  
     * @return returns true if this represents an empty path
 173  
     */
 174  
    boolean isEmpty();
 175  
 
 176  
    /**
 177  
     * Provides a canonical XPath expression. This is used for both
 178  
     * debugging and reporting. The path returned represents the 
 179  
     * original path that has been parsed to form the expression.
 180  
     * 
 181  
     * @return this returns the string format for the XPath
 182  
     */
 183  
    String toString();
 184  
 }