Java Code Examples for org.apache.commons.jxpath.ri.model.NodePointer#setIndex()

The following examples show how to use org.apache.commons.jxpath.ri.model.NodePointer#setIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollectionNodeIterator.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare...
 */
private void prepare() {
    collection = new ArrayList();
    NodePointer ptr = (NodePointer) pointer.clone();
    int length = ptr.getLength();
    for (int i = 0; i < length; i++) {
        ptr.setIndex(i);
        NodePointer elementPointer = ptr.getValuePointer();
        NodeIterator iter = getElementNodeIterator(elementPointer);

        for (int j = 1; iter.setPosition(j); j++) {
            NodePointer childPointer = iter.getNodePointer();
            if (reverse) {
                collection.add(0, childPointer);
            }
            else {
                collection.add(childPointer);
            }
        }
    }
    if (startWith != null) {
        int index = collection.indexOf(startWith);
        if (index == -1) {
            throw new JXPathException(
                "Invalid starting pointer for iterator: " + startWith);
        }
        while (collection.size() > index) {
            if (!reverse) {
                collection.remove(collection.size() - 1);
            }
            else {
                collection.remove(0);
            }
        }
    }
}
 
Example 2
Source File: CollectionPointer.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public NodePointer createChild(
    JXPathContext context,
    QName name,
    int index,
    Object value) {
    NodePointer ptr = (NodePointer) clone();
    ptr.setIndex(index);
    return ptr.createPath(context, value);
}
 
Example 3
Source File: CollectionPointer.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public NodePointer createChild(
    JXPathContext context,
    QName name,
    int index) {
    NodePointer ptr = (NodePointer) clone();
    ptr.setIndex(index);
    return ptr.createPath(context);
}
 
Example 4
Source File: SimplePathInterpreter.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a "null pointer" that starts with predicates.
 * @param context evaluation context
 * @param parent parent pointer
 * @param steps path steps
 * @param currentStep step number
 * @param predicates predicates
 * @param currentPredicate int predicate number
 * @return NodePointer
 */
private static NodePointer createNullPointerForPredicates(
        EvalContext context, NodePointer parent,
        Step[] steps, int currentStep,
        Expression[] predicates, int currentPredicate) {
    for (int i = currentPredicate; i < predicates.length; i++) {
        Expression predicate = predicates[i];
        if (predicate instanceof NameAttributeTest) {
            String key = keyFromPredicate(context, predicate);
            parent = valuePointer(parent);
            NullPropertyPointer pointer = new NullPropertyPointer(parent);
            pointer.setNameAttributeValue(key);
            parent = pointer;
        }
        else {
            int index = indexFromPredicate(context, predicate);
            if (parent instanceof NullPropertyPointer) {
                parent.setIndex(index);
            }
            else {
                parent = new NullElementPointer(parent, index);
            }
        }
    }
    // Proceed with the remaining steps
    return createNullPointer(
                context, parent, steps, currentStep + 1);
}