|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.priha.path.Path
public final class Path
Manages paths, which are a key ingredient in JCR. A Path is an immutable object, so you can't change it once you create it.
It should be noted that Path.toString() can become fairly expensive quickly, since it'll create a StringBuilder to concatenate all the Components, so it's better to avoid it, if possible. The String is cached internally, but still, it's better not to call it even once. The equals(), compareTo() and toString() methods avoid calling toString().
Nested Class Summary | |
---|---|
static class |
Path.Component
A Path component consists of a QName with an optional index (to support same name siblings). |
Field Summary | |
---|---|
static Path |
EMPTY_RELATIVE_PATH
|
static Path |
ROOT
This is a static instance of the root path so that you don't have to create it every single time you use it (as it happens quite often). |
Constructor Summary | |
---|---|
protected |
Path()
This constructor is useful only to subclasses or serialization. |
|
Path(NamespaceMapper ns,
java.lang.String abspath)
Create a new path from a String. |
|
Path(NamespaceMapper ns,
java.lang.String pathStart,
Path pathEnd)
|
|
Path(Path.Component[] components,
boolean absolute)
|
|
Path(Path parentPath,
Path.Component component)
|
|
Path(QName[] components,
boolean absolute)
Creates a Path from a number of QName components. |
|
Path(QName name,
boolean b)
|
Method Summary | |
---|---|
int |
compareTo(Path o)
|
int |
depth()
Returns the depth of this path. |
boolean |
equals(java.lang.Object obj)
Two paths are equal if their string representations are equal. |
Path |
getAncestorPath(int depth)
Returns the Path up to ancestor "depth". |
Path.Component |
getComponent(int idx)
Gets one path component. |
Path.Component[] |
getElements()
|
Path.Component |
getLastComponent()
Returns the name of the last component of the path (i.e. |
Path.Component |
getParentName()
Returns the name of the parent (not the path). |
Path |
getParentPath()
Returns a valid path pointing at the parent of this path. |
Path |
getSubpath(int startidx)
Returns a subpath starting from index "startidx". |
Path |
getSubpath(int startidx,
int endidx)
Gets a valid subpath starting from startidx and ending at endidx. |
int |
hashCode()
|
boolean |
isAbsolute()
|
boolean |
isParentOf(Path p)
Returns true, if this path is a parent of the given Path. |
boolean |
isRoot()
Returns true, if this Path represents the root. |
Path |
resolve(NamespaceMapper ns,
java.lang.String relPath)
Resolves a relative Path against this Path. |
Path |
resolve(Path.Component component)
Adds a new component to the path (since Components are not paths), and returns a new Path. |
Path |
resolve(QName component)
Adds a component to the path (since Components are not paths), and returns a new Path. |
java.lang.String |
toString()
Returns the Path in String format. |
java.lang.String |
toString(NamespaceMapper ns)
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Path ROOT
Using this is faster than using Path p = new Path("/")
.
public static final Path EMPTY_RELATIVE_PATH
Constructor Detail |
---|
protected Path()
public Path(QName[] components, boolean absolute)
components
- A list of componentsabsolute
- true, if this path should be absolute; false if relative.public Path(Path.Component[] components, boolean absolute)
public Path(NamespaceMapper ns, java.lang.String abspath) throws javax.jcr.NamespaceException, javax.jcr.RepositoryException
Path p = new Path("/foo/bar/glob");
abspath
- A path.
javax.jcr.RepositoryException
javax.jcr.NamespaceException
public Path(NamespaceMapper ns, java.lang.String pathStart, Path pathEnd) throws javax.jcr.NamespaceException, javax.jcr.RepositoryException
javax.jcr.NamespaceException
javax.jcr.RepositoryException
public Path(QName name, boolean b)
public Path(Path parentPath, Path.Component component)
Method Detail |
---|
public final boolean isAbsolute()
public final Path.Component getComponent(int idx)
idx
- Which component to get. The top-most component is at index zero.
public final Path.Component getLastComponent()
public final boolean isRoot()
public final int depth()
public final Path.Component getParentName() throws InvalidPathException
InvalidPathException
- If you try to get the parent of the root node.public final Path getParentPath() throws InvalidPathException
InvalidPathException
- If this Path is the root node.public final Path getSubpath(int startidx) throws InvalidPathException
startidx
- Where to start the path from. Zero is root.
InvalidPathException
- If startidx < 0 or startidx > path depth.public final Path getSubpath(int startidx, int endidx) throws InvalidPathException
startidx
- Which component to start from.endidx
- Which component is the last one to include.
InvalidPathException
- If the index values are invalid.public final java.lang.String toString()
toString
in class java.lang.Object
public final java.lang.String toString(NamespaceMapper ns) throws javax.jcr.NamespaceException, javax.jcr.RepositoryException
javax.jcr.NamespaceException
javax.jcr.RepositoryException
public final Path resolve(QName component)
component
- QName to add at the end of the Path.
public final Path resolve(Path.Component component)
component
- A Compoment to add at the end of the Path.
public final Path resolve(NamespaceMapper ns, java.lang.String relPath) throws javax.jcr.NamespaceException, javax.jcr.RepositoryException
relPath
- String describing relative path.
javax.jcr.RepositoryException
javax.jcr.NamespaceException
public final Path getAncestorPath(int depth) throws InvalidPathException
depth
-
InvalidPathException
public final boolean isParentOf(Path p)
path
-
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
public final int compareTo(Path o)
compareTo
in interface java.lang.Comparable<Path>
public final Path.Component[] getElements()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |