com.google.gdata.model
Class Path

java.lang.Object
  extended by com.google.gdata.model.Path

public class Path
extends java.lang.Object

The Path class represents an immutable path to a model entity in the GData DOM. A path can be absolute (the root ElementMetadata for the path is specified at construction time or relative (the root element type is unknown at construction time).

The toAbsolute(ElementMetadata) method can be used to produce an absolute path from a relative path by interpreting it relative to a root.

New paths can be constructed using the of(MetadataKey...) or to(ElementMetadata, MetadataKey...) methods as well as using the builder() method to obtain a new Path.Builder instance that can be used for incremental path construction.


Nested Class Summary
static class Path.Builder
          The Builder class provides a model for incrementally constructing new Path relative or absolute instances.
 
Field Summary
static Path ROOT
          A simple relative path that selects the root of the path.
 
Method Summary
static Path.Builder builder()
           
 boolean equals(java.lang.Object o)
          The equals method will return true if the target object is also a Path, has the same root or is also relative, and has the same list of path steps.
 ElementKey<?,?> getParentKey()
          Returns the element key for the second-to-last key in the path.
 AttributeMetadata<?> getSelectedAttribute()
          Returns the attribute type currently selected by the path or null if the path selects an element or is relative.
 AttributeKey<?> getSelectedAttributeKey()
          Returns the attribute key at the end of the path.
 ElementMetadata<?,?> getSelectedElement()
          Returns the element type currently selected by the path or null if the path is relative.
 ElementKey<?,?> getSelectedElementKey()
          Returns the element key at the end of the path.
 java.util.List<MetadataKey<?>> getSteps()
          Returns the list of path steps.
 int hashCode()
           
 boolean isRelative()
          Returns true if path is relative
static Path of(MetadataKey<?>... steps)
          Constructs a new relative Path that selects an element defined by the set of path steps to the element.
 boolean selectsAttribute()
          Returns true if the path selects an attribute.
 boolean selectsElement()
          Returns true if the path selects an element.
static Path to(ElementMetadata<?,?> root, MetadataKey<?>... keys)
          Constructs a new absolute Path to an element type as defined by a root type and the relative steps from it to the selected type.
 Path toAbsolute(ElementMetadata<?,?> root)
          Constructs a new Path instance by interpreting the steps in the current path relative to the provided root ElementMetadata.
 java.lang.String toString()
          The toString() implementation is overridden to return the XPath string that represents the path.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOT

public static final Path ROOT
A simple relative path that selects the root of the path.

Method Detail

builder

public static Path.Builder builder()

of

public static Path of(MetadataKey<?>... steps)
Constructs a new relative Path that selects an element defined by the set of path steps to the element.

Parameters:
steps - keys defining steps to the selected element
Returns:
selection path to element

to

public static Path to(ElementMetadata<?,?> root,
                      MetadataKey<?>... keys)
Constructs a new absolute Path to an element type as defined by a root type and the relative steps from it to the selected type.

Parameters:
keys - keys defining steps to the selected element
Returns:
selection path to element
Throws:
PathException - if this path has been bound to a metadata instance and no key with the given step can be found, or if the path is an attribute path. Once a path has an attribute key no more steps may be added.
java.lang.NullPointerException - if root is null.

selectsAttribute

public boolean selectsAttribute()
Returns true if the path selects an attribute.


selectsElement

public boolean selectsElement()
Returns true if the path selects an element.


getSelectedElement

public ElementMetadata<?,?> getSelectedElement()
Returns the element type currently selected by the path or null if the path is relative.


getSelectedAttribute

public AttributeMetadata<?> getSelectedAttribute()
Returns the attribute type currently selected by the path or null if the path selects an element or is relative.


getSteps

public java.util.List<MetadataKey<?>> getSteps()
Returns the list of path steps.


isRelative

public boolean isRelative()
Returns true if path is relative


getSelectedAttributeKey

public AttributeKey<?> getSelectedAttributeKey()
Returns the attribute key at the end of the path.

Throws:
java.lang.IllegalStateException - if this path is not to an attribute.

getSelectedElementKey

public ElementKey<?,?> getSelectedElementKey()
Returns the element key at the end of the path.

Throws:
java.lang.IllegalStateException - if this path is not to an element.

getParentKey

public ElementKey<?,?> getParentKey()
Returns the element key for the second-to-last key in the path. If the path is only a single step this method will return null.


toAbsolute

public Path toAbsolute(ElementMetadata<?,?> root)
Constructs a new Path instance by interpreting the steps in the current path relative to the provided root ElementMetadata.

Parameters:
root - root of returned path
Returns:
new absolute Path bound to the root element metadata.
Throws:
PathException - if the path is not found in the metadata.
java.lang.NullPointerException - if root is null.

toString

public java.lang.String toString()
The toString() implementation is overridden to return the XPath string that represents the path.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
The equals method will return true if the target object is also a Path, has the same root or is also relative, and has the same list of path steps.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object