Method from org.apache.commons.jxpath.ri.EvalContext Detail: |
public List getContextNodeList() {
int pos = position;
if (pos != 0) {
reset();
}
List list = new ArrayList();
while (nextNode()) {
list.add(getCurrentNodePointer());
}
if (pos != 0) {
setPosition(pos);
}
else {
reset();
}
return list;
}
Returns the list of all Pointers in this context for the current
position of the parent context. |
public Pointer getContextNodePointer() {
return getCurrentNodePointer();
}
|
abstract public NodePointer getCurrentNodePointer()
Returns the current context node. Undefined before the beginning
of the iteration. |
public int getCurrentPosition() {
return position;
}
|
public int getDocumentOrder() {
if (parentContext != null && parentContext.isChildOrderingRequired()) {
return 1;
}
return 0;
}
Determines the document order for this context. |
public JXPathContext getJXPathContext() {
return getRootContext().getJXPathContext();
}
|
public NodeSet getNodeSet() {
if (position != 0) {
throw new JXPathException(
"Simultaneous operations: "
+ "should not request pointer list while "
+ "iterating over an EvalContext");
}
BasicNodeSet set = new BasicNodeSet();
while (nextSet()) {
while (nextNode()) {
set.add((Pointer)getCurrentNodePointer().clone());
}
}
return set;
}
Returns the list of all Pointers in this context for all positions
of the parent contexts. If there was an ongoing iteration over
this context, the method should not be called. |
public int getPosition() {
return position;
}
|
public RootContext getRootContext() {
if (rootContext == null) {
rootContext = parentContext.getRootContext();
}
return rootContext;
}
Returns the root context of the path, which provides easy
access to variables and functions. |
public Pointer getSingleNodePointer() {
reset();
while (nextSet()) {
if (nextNode()) {
return getCurrentNodePointer();
}
}
return null;
}
Returns the first encountered Pointer that matches the current
context's criteria. |
public Object getValue() {
return getNodeSet();
}
Typically returns the NodeSet by calling getNodeSet(),
but will be overridden for contexts that more naturally produce
individual values, e.g. VariableContext |
public boolean hasNext() {
if (pointerIterator != null) {
return pointerIterator.hasNext();
}
if (getDocumentOrder() != 0) {
return constructIterator();
}
else {
if (!done && !hasPerformedIteratorStep) {
performIteratorStep();
}
return !done;
}
}
Returns true if there are mode nodes matching the context's constraints. |
public boolean isChildOrderingRequired() {
// Default behavior: if this context needs to be ordered,
// the children need to be ordered too
if (getDocumentOrder() != 0) {
return true;
}
return false;
}
Even if this context has the natural ordering and therefore does
not require collecting and sorting all nodes prior to returning them,
such operation may be required for any child context. |
public Object next() {
if (pointerIterator != null) {
return pointerIterator.next();
}
if (getDocumentOrder() != 0) {
if (!constructIterator()) {
throw new NoSuchElementException();
}
return pointerIterator.next();
}
else {
if (!done && !hasPerformedIteratorStep) {
performIteratorStep();
}
if (done) {
throw new NoSuchElementException();
}
hasPerformedIteratorStep = false;
return getCurrentNodePointer();
}
}
Returns the next node pointer in the context |
abstract public boolean nextNode()
Returns true if there is another object in the current set.
Switches the current position and node to the next object. |
public boolean nextSet() {
reset(); // Restart iteration within the set
// Most of the time you have one set per parent node
// First time this method is called, we should look for
// the first parent set that contains at least one node.
if (!startedSetIteration) {
startedSetIteration = true;
while (parentContext.nextSet()) {
if (parentContext.nextNode()) {
return true;
}
}
return false;
}
// In subsequent calls, we see if the parent context
// has any nodes left in the current set
if (parentContext.nextNode()) {
return true;
}
// If not, we look for the next set that contains
// at least one node
while (parentContext.nextSet()) {
if (parentContext.nextNode()) {
return true;
}
}
return false;
}
Returns true if there is another sets of objects to interate over.
Resets the current position and node. |
public void remove() {
throw new UnsupportedOperationException(
"JXPath iterators cannot remove nodes");
}
Operation is not supported |
public void reset() {
position = 0;
}
Sets current position = 0, which is the pre-iteration state. |
public boolean setPosition(int position) {
this.position = position;
return true;
}
Moves the current position to the specified index. Used with integer
predicates to quickly get to the n'th element of the node set.
Returns false if the position is out of the node set range.
You can call it with 0 as the position argument to restart the iteration. |
public String toString() {
Pointer ptr = getContextNodePointer();
if (ptr == null) {
return "Empty expression context";
}
else {
return "Expression context [" + getPosition() + "] " + ptr.asPath();
}
}
|