org.apache.jackrabbit.name
Class Path.PathElement

java.lang.Object
  extended by org.apache.jackrabbit.name.Path.PathElement
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Path.CurrentElement, Path.NameElement, Path.ParentElement, Path.RootElement
Enclosing class:
Path

public abstract static class Path.PathElement
extends Object
implements Serializable

Object representation of a single JCR path element. A PathElement object contains the qualified name and optional index of a single JCR path element.

Once created, a PathElement object is immutable.

See Also:
Serialized Form

Method Summary
static Path.PathElement create(QName name)
          Creates a path element with the given qualified name.
static Path.PathElement create(QName name, int index)
          Same as create(QName) except that an explicit index can be specified.
abstract  boolean denotesCurrent()
          Returns true if this element denotes the current ('.') element, otherwise returns false.
abstract  boolean denotesName()
          Returns true if this element represents a regular name (i.e. neither root, '.' nor '..'), otherwise returns false.
abstract  boolean denotesParent()
          Returns true if this element denotes the parent ('..') element, otherwise returns false.
abstract  boolean denotesRoot()
          Returns true if this element denotes the root element, otherwise returns false.
 boolean equals(Object obj)
          Check for path element equality.
static Path.PathElement fromString(String s)
          Parses the given path element string into a path element object.
 int getIndex()
          Returns the 1-based index or 0 if no index was specified (which is equivalent to specifying 1).
 QName getName()
          Returns the qualified name of this path element.
 int getNormalizedIndex()
          Returns the normalized index of this path element, i.e. the index is always equals or greater that Path.INDEX_DEFAULT.
 int hashCode()
          Computes a hash code for this path element.
 String toJCRName(NamespaceResolver resolver)
          Returns the JCR name representation of this path element.
 void toJCRName(NamespaceResolver resolver, StringBuffer buf)
          Appends the JCR name representation of this path element to the given string buffer.
 String toString()
          Returns a string representation of this path element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static Path.PathElement create(QName name)
Creates a path element with the given qualified name. The created path element does not contain an explicit index.

If the specified name denotes a special path element (either Path.PARENT_ELEMENT, Path.CURRENT_ELEMENT or Path.ROOT_ELEMENT) then the associated constant is returned.

Parameters:
name - the name of the element
Returns:
a path element
Throws:
IllegalArgumentException - if the name is null

create

public static Path.PathElement create(QName name,
                                      int index)
Same as create(QName) except that an explicit index can be specified.

Note that an IllegalArgumentException will be thrown if the specified name denotes a special path element (either Path.PARENT_ELEMENT, Path.CURRENT_ELEMENT or Path.ROOT_ELEMENT) since an explicit index is not allowed in this context.

Parameters:
name - the name of the element
index - the 1-based index.
Returns:
a path element
Throws:
IllegalArgumentException - if the name is null, if the given index is less than 1 or if name denoting a special path element and an index greater than 1 have been specified.

getName

public QName getName()
Returns the qualified name of this path element.

Returns:
qualified name

getIndex

public int getIndex()
Returns the 1-based index or 0 if no index was specified (which is equivalent to specifying 1).

Returns:
Returns the 1-based index or 0 if no index was specified.

getNormalizedIndex

public int getNormalizedIndex()
Returns the normalized index of this path element, i.e. the index is always equals or greater that Path.INDEX_DEFAULT.


toJCRName

public String toJCRName(NamespaceResolver resolver)
                 throws NoPrefixDeclaredException
Returns the JCR name representation of this path element. Note that strictly speaking the returned value is in fact a JCR relative path instead of a JCR name, as it contains the index value if the index is greater than one.

Parameters:
resolver - namespace resolver
Returns:
JCR name representation of the path element
Throws:
NoPrefixDeclaredException - if the namespace of the path element name can not be resolved

toJCRName

public void toJCRName(NamespaceResolver resolver,
                      StringBuffer buf)
               throws NoPrefixDeclaredException
Appends the JCR name representation of this path element to the given string buffer.

Parameters:
resolver - namespace resolver
buf - string buffer where the JCR name representation should be appended to
Throws:
NoPrefixDeclaredException - if the namespace of the path element name can not be resolved
See Also:
toJCRName(NamespaceResolver)

toString

public String toString()
Returns a string representation of this path element. Note that the path element name is expressed using the {uri}name syntax. Use the toJCRName method to get the prefixed string representation of the path element.

Overrides:
toString in class Object
Returns:
string representation of the path element
See Also:
Object.toString()

fromString

public static Path.PathElement fromString(String s)
                                   throws IllegalArgumentException
Parses the given path element string into a path element object.

Parameters:
s - path element string
Returns:
path element object
Throws:
IllegalArgumentException - if the given path element string is null or if its format is invalid

hashCode

public int hashCode()
Computes a hash code for this path element.

Overrides:
hashCode in class Object
Returns:
hash code

equals

public boolean equals(Object obj)
Check for path element equality. Returns true if the given object is a PathElement and contains the same name and index as this one.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
true if the path elements are equal

denotesRoot

public abstract boolean denotesRoot()
Returns true if this element denotes the root element, otherwise returns false.

Returns:
true if this element denotes the root element; otherwise false

denotesParent

public abstract boolean denotesParent()
Returns true if this element denotes the parent ('..') element, otherwise returns false.

Returns:
true if this element denotes the parent element; otherwise false

denotesCurrent

public abstract boolean denotesCurrent()
Returns true if this element denotes the current ('.') element, otherwise returns false.

Returns:
true if this element denotes the current element; otherwise false

denotesName

public abstract boolean denotesName()
Returns true if this element represents a regular name (i.e. neither root, '.' nor '..'), otherwise returns false.

Returns:
true if this element represents a regular name; otherwise false


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.