org.apache.torque.generator.source
Class SourcePath

java.lang.Object
  extended by org.apache.torque.generator.source.SourcePath

public final class SourcePath
extends Object

Methods for traversing a source tree.


Method Summary
static SourceElement getElement(SourceElement sourceElement, String path, boolean acceptEmpty)
          Gets a single source element which can be reached from the start element by a given path.
static List<SourceElement> getElements(SourceElement sourceElement, String path)
          Gets the elements which can be reached from the start element by a given path.
static List<SourceElement> getElementsFromRoot(SourceElement rootElement, String path)
          Gets the elements which can be reached from the root element by a given path.
static List<SourceElement> getFollowing(SourceElement sourceElement, String name)
          Returns all the following elements after this element with the given name.
static String getPathAsString(SourceElement sourceElement)
          Returns the path from the root element to the source element.
static List<SourceElement> getPreceding(SourceElement sourceElement, String name)
          Returns all the preceding elements before this element with the given name.
static boolean hasChild(SourceElement sourceElement, String name)
          Returns whether children with the given name exist.
static boolean hasFollowing(SourceElement sourceElement)
          Returns whether a following element exists as a child of the parent of this element.
static boolean hasFollowingSibling(SourceElement sourceElement)
          Returns whether a following element exists as a child of the parent of this element, which has the same name as this source element.
static boolean hasPreceding(SourceElement sourceElement)
          Returns whether an preceding exists as a child of the parent of this element.
static boolean hasPrecedingSibling(SourceElement sourceElement)
          Returns whether an preceding exists as a child of the parent of this element, which has the same name as this source element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasChild

public static boolean hasChild(SourceElement sourceElement,
                               String name)
Returns whether children with the given name exist.

Parameters:
sourceElement - the start element, not null.
name - the name of the child element, not null.
Returns:
true if children with the given name exist, false otherwise.
Throws:
NullPointerException - if name is null.

hasFollowing

public static boolean hasFollowing(SourceElement sourceElement)
Returns whether a following element exists as a child of the parent of this element.

Parameters:
sourceElement - the start element, not null.
Returns:
true if a following element exists, false if not.

hasPreceding

public static boolean hasPreceding(SourceElement sourceElement)
Returns whether an preceding exists as a child of the parent of this element.

Parameters:
sourceElement - the start element, not null.
Returns:
true if a preceding element exists, false if not.

hasFollowingSibling

public static boolean hasFollowingSibling(SourceElement sourceElement)
Returns whether a following element exists as a child of the parent of this element, which has the same name as this source element.

Parameters:
sourceElement - the start element, not null.
Returns:
true if a following sibling exists, false if not.

hasPrecedingSibling

public static boolean hasPrecedingSibling(SourceElement sourceElement)
Returns whether an preceding exists as a child of the parent of this element, which has the same name as this source element.

Parameters:
sourceElement - the start element, not null.
Returns:
true if a preceding sibling exists, false if not.

getPreceding

public static List<SourceElement> getPreceding(SourceElement sourceElement,
                                               String name)
Returns all the preceding elements before this element with the given name. If name is null, all preceding elements are returned. If this element has no parent, an empty list is returned.

Parameters:
sourceElement - the start element, not null.
name - the name of the preceding elements to select, or null to select all preceding elements.
Returns:
a list containing the preceding elements with the given name, never null.
See Also:
xpath axes

getFollowing

public static List<SourceElement> getFollowing(SourceElement sourceElement,
                                               String name)
Returns all the following elements after this element with the given name. If name is null, all following elements are returned. If this element has no parent, an empty list is returned.

Parameters:
sourceElement - the start element, not null.
name - the name of the following elements to select, or null to select all following elements.
Returns:
a list containing the following elements with the given name, never null.
See Also:
xpath axes

getElements

public static List<SourceElement> getElements(SourceElement sourceElement,
                                              String path)
Gets the elements which can be reached from the start element by a given path.

Parameters:
sourceElement - the start element, not null.
path - the path to use, not null.
Returns:
the list of matching source elements, not null, may be empty.
See Also:
xpath axes

getElementsFromRoot

public static List<SourceElement> getElementsFromRoot(SourceElement rootElement,
                                                      String path)
Gets the elements which can be reached from the root element by a given path. The name of the root element must appear first in the path, otherwise nothing is selected.

Parameters:
rootElement - the root element of the source tree, not null.
path - the path to use, null selects the root element.
Returns:
the list of matching source elements, not null, may be empty.
See Also:
xpath axes

getElement

public static SourceElement getElement(SourceElement sourceElement,
                                       String path,
                                       boolean acceptEmpty)
                                throws GeneratorException
Gets a single source element which can be reached from the start element by a given path.

Parameters:
sourceElement - the start element, not null.
path - the path to use, not null.
acceptEmpty - whether no match is an error(acceptEmpty=false) or not (acceptEmpty=true)
Returns:
the single matching source elements, may be null only if acceptEmpty=true.
Throws:
GeneratorException - if more than one source element matches, or if no source element matches and acceptEmpty=false
See Also:
xpath axes

getPathAsString

public static String getPathAsString(SourceElement sourceElement)
                              throws GeneratorException
Returns the path from the root element to the source element. The element names are separated by slashes. Example: root/firstLevelElement/secondLevelElement/currentNode

Parameters:
sourceElement - the element to output, not null.
Returns:
the path from root, not null.
Throws:
GeneratorException - if the parent chain contains a closed loop.


Copyright © 2000-2012 The Apache Software Foundation. All Rights Reserved.