Package org.simpleframework.xml.core
Class PathParser.PathSection
- java.lang.Object
-
- org.simpleframework.xml.core.PathParser.PathSection
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
,Expression
- Enclosing class:
- PathParser
private class PathParser.PathSection extends java.lang.Object implements Expression
ThePathSection
represents a section of a path that is extracted. Providing a section allows the expression to be broken up in to smaller parts without having to parse the path again. This is used primarily for better performance.
-
-
Field Summary
Fields Modifier and Type Field Description private int
begin
This is the first section index for this path section.private java.util.List<java.lang.String>
cache
This contains a cache of the path segments of the section.private int
end
This is the last section index for this path section.private java.lang.String
path
This contains a cache of the canonical path representation.private java.lang.String
section
This is the fragment of the original path this section uses.
-
Constructor Summary
Constructors Constructor Description PathSection(int index, int end)
Constructor for thePathSection
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAttribute(java.lang.String name)
This is used to acquire the attribute path using this XPath expression.private java.lang.String
getCanonicalPath()
This is used to acquire the path section that contains all the segments in the section as well as the indexes for the segments.java.lang.String
getElement(java.lang.String name)
This is used to acquire the element path using this XPath expression.java.lang.String
getFirst()
This can be used to acquire the first path segment within the expression.private java.lang.String
getFragment()
Provides a canonical XPath expression.int
getIndex()
If the first path segment contains an index it is provided by this method.java.lang.String
getLast()
This can be used to acquire the last path segment within the expression.java.lang.String
getPath()
This location contains the full path expression with all of the indexes explicitly shown for each path segment.Expression
getPath(int from)
This allows an expression to be extracted from the current context.Expression
getPath(int from, int trim)
This allows an expression to be extracted from the current context.java.lang.String
getPrefix()
This is used to extract a namespace prefix from the path expression.boolean
isAttribute()
This is used to determine if the expression points to an attribute value.boolean
isEmpty()
This method is used to determine if this expression is an empty path.boolean
isPath()
This is used to determine if the expression is a path.java.util.Iterator<java.lang.String>
iterator()
This is used to iterate over the path segments that have been extracted from the source XPath expression.java.lang.String
toString()
Provides a canonical XPath expression.
-
-
-
Field Detail
-
cache
private java.util.List<java.lang.String> cache
This contains a cache of the path segments of the section.
-
section
private java.lang.String section
This is the fragment of the original path this section uses.
-
path
private java.lang.String path
This contains a cache of the canonical path representation.
-
begin
private int begin
This is the first section index for this path section.
-
end
private int end
This is the last section index for this path section.
-
-
Constructor Detail
-
PathSection
public PathSection(int index, int end)
Constructor for thePathSection
object. A path section represents a section of an original path expression. To create a section the first and last segment index needs to be provided.- Parameters:
index
- this is the first path segment indexend
- this is the last path segment index
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
This method is used to determine if this expression is an empty path. An empty path can be represented by a single period, '.'. It identifies the current path.- Specified by:
isEmpty
in interfaceExpression
- Returns:
- returns true if this represents an empty path
-
isPath
public boolean isPath()
This is used to determine if the expression is a path. An expression represents a path if it contains more than one segment. If only one segment exists it is an element name.- Specified by:
isPath
in interfaceExpression
- Returns:
- true if this contains more than one segment
-
isAttribute
public boolean isAttribute()
This is used to determine if the expression points to an attribute value. An attribute value contains an '@' character before the last segment name. Such expressions distinguish element references from attribute references.- Specified by:
isAttribute
in interfaceExpression
- Returns:
- this returns true if the path has an attribute
-
getPath
public java.lang.String getPath()
This location contains the full path expression with all of the indexes explicitly shown for each path segment. This is used to create a uniform representation that can be used for comparisons of different path expressions.- Specified by:
getPath
in interfaceExpression
- Returns:
- this returns an expanded version of the path
-
getElement
public java.lang.String getElement(java.lang.String name)
This is used to acquire the element path using this XPath expression. The element path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.- Specified by:
getElement
in interfaceExpression
- Parameters:
name
- this is the name of the element to be used- Returns:
- a fully qualified path for the specified name
-
getAttribute
public java.lang.String getAttribute(java.lang.String name)
This is used to acquire the attribute path using this XPath expression. The attribute path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.- Specified by:
getAttribute
in interfaceExpression
- Parameters:
name
- this is the name of the attribute to be used- Returns:
- a fully qualified path for the specified name
-
getIndex
public int getIndex()
If the first path segment contains an index it is provided by this method. There may be several indexes within a path, however only the index at the first segment is issued by this method. If there is no index this will return 1.- Specified by:
getIndex
in interfaceExpression
- Returns:
- this returns the index of this path expression
-
getPrefix
public java.lang.String getPrefix()
This is used to extract a namespace prefix from the path expression. A prefix is used to qualify the XML element name and does not form part of the actual path structure. This can be used to add the namespace in addition to the name.- Specified by:
getPrefix
in interfaceExpression
- Returns:
- this returns the prefix for the path expression
-
getFirst
public java.lang.String getFirst()
This can be used to acquire the first path segment within the expression. The first segment represents the parent XML element of the path. All segments returned do not contain any slashes and so represents the real element name.- Specified by:
getFirst
in interfaceExpression
- Returns:
- this returns the parent element for the path
-
getLast
public java.lang.String getLast()
This can be used to acquire the last path segment within the expression. The last segment represents the leaf XML element of the path. All segments returned do not contain any slashes and so represents the real element name.- Specified by:
getLast
in interfaceExpression
- Returns:
- this returns the leaf element for the path
-
getPath
public Expression getPath(int from)
This allows an expression to be extracted from the current context. Extracting expressions in this manner makes it more convenient for navigating structures representing the XML document. If an expression can not be extracted with the given criteria an exception will be thrown.- Specified by:
getPath
in interfaceExpression
- Parameters:
from
- this is the number of segments to skip to- Returns:
- this returns an expression from this one
-
getPath
public Expression getPath(int from, int trim)
This allows an expression to be extracted from the current context. Extracting expressions in this manner makes it more convenient for navigating structures representing the XML document. If an expression can not be extracted with the given criteria an exception will be thrown.- Specified by:
getPath
in interfaceExpression
- Parameters:
from
- this is the number of segments to skip totrim
- the number of segments to trim from the end- Returns:
- this returns an expression from this one
-
iterator
public java.util.Iterator<java.lang.String> iterator()
This is used to iterate over the path segments that have been extracted from the source XPath expression. Iteration over the segments is done in the order they were parsed from the source path.- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
- Returns:
- this returns an iterator for the path segments
-
getCanonicalPath
private java.lang.String getCanonicalPath()
This is used to acquire the path section that contains all the segments in the section as well as the indexes for the segments. This method basically gets a substring of the primary path location from the first to the last segment.- Returns:
- this returns the section as a fully qualified path
-
getFragment
private java.lang.String getFragment()
Provides a canonical XPath expression. This is used for both debugging and reporting. The path returned represents the original path that has been parsed to form the expression.- Returns:
- this returns the string format for the XPath
-
toString
public java.lang.String toString()
Provides a canonical XPath expression. This is used for both debugging and reporting. The path returned represents the original path that has been parsed to form the expression.- Specified by:
toString
in interfaceExpression
- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns the string format for the XPath
-
-