Java Code Examples for org.apache.commons.jxpath.ri.model.NodePointer#WHOLE_COLLECTION

The following examples show how to use org.apache.commons.jxpath.ri.model.NodePointer#WHOLE_COLLECTION . 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: PropertyIterator.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new PropertyIterator.
 * @param pointer owning pointer
 * @param name property name
 * @param reverse iteration order
 * @param startWith beginning pointer
 */
public PropertyIterator(
    PropertyOwnerPointer pointer,
    String name,
    boolean reverse,
    NodePointer startWith) {
    propertyNodePointer =
        (PropertyPointer) pointer.getPropertyPointer().clone();
    this.name = name;
    this.reverse = reverse;
    this.includeStart = true;
    if (reverse) {
        this.startPropertyIndex = PropertyPointer.UNSPECIFIED_PROPERTY;
        this.startIndex = -1;
    }
    if (startWith != null) {
        while (startWith != null
                && startWith.getImmediateParentPointer() != pointer) {
            startWith = startWith.getImmediateParentPointer();
        }
        if (startWith == null) {
            throw new JXPathException(
                "PropertyIerator startWith parameter is "
                    + "not a child of the supplied parent");
        }
        this.startPropertyIndex =
            ((PropertyPointer) startWith).getPropertyIndex();
        this.startIndex = startWith.getIndex();
        if (this.startIndex == NodePointer.WHOLE_COLLECTION) {
            this.startIndex = 0;
        }
        this.includeStart = false;
        if (reverse && startIndex == -1) {
            this.includeStart = true;
        }
    }
}
 
Example 2
Source File: InitialContext.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new InitialContext.
 * @param parentContext parent context
 */
public InitialContext(EvalContext parentContext) {
    super(parentContext);
    nodePointer =
        (NodePointer) parentContext.getCurrentNodePointer().clone();
    if (nodePointer != null) {
        collection =
            (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION);
    }
}
 
Example 3
Source File: PropertyIterator.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
/**
 * Prepare for an individual property.
 * @param name property name
 */
protected void prepareForIndividualProperty(String name) {
    targetReady = true;
    empty = true;

    String[] names = propertyNodePointer.getPropertyNames();
    if (!reverse) {
        if (startPropertyIndex == PropertyPointer.UNSPECIFIED_PROPERTY) {
            startPropertyIndex = 0;
        }
        if (startIndex == NodePointer.WHOLE_COLLECTION) {
            startIndex = 0;
        }
        for (int i = startPropertyIndex; i < names.length; i++) {
            if (names[i].equals(name)) {
                propertyNodePointer.setPropertyIndex(i);
                if (i != startPropertyIndex) {
                    startIndex = 0;
                    includeStart = true;
                }
                empty = false;
                break;
            }
        }
    }
    else {
        if (startPropertyIndex == PropertyPointer.UNSPECIFIED_PROPERTY) {
            startPropertyIndex = names.length - 1;
        }
        if (startIndex == NodePointer.WHOLE_COLLECTION) {
            startIndex = -1;
        }
        for (int i = startPropertyIndex; i >= 0; i--) {
            if (names[i].equals(name)) {
                propertyNodePointer.setPropertyIndex(i);
                if (i != startPropertyIndex) {
                    startIndex = -1;
                    includeStart = true;
                }
                empty = false;
                break;
            }
        }
    }
}
 
Example 4
Source File: ExpressionPath.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
/**
 * Walks an expression path (a path that starts with an expression)
 * @param evalContext base context
 * @param firstMatch whether to return the first match found
 * @return Object found
 */
protected Object expressionPath(EvalContext evalContext, boolean firstMatch) {
    Object value = expression.compute(evalContext);
    EvalContext context;
    if (value instanceof InitialContext) {
        // This is an optimization. We can avoid iterating through a
        // collection if the context bean is in fact one.
        context = (InitialContext) value;
    }
    else if (value instanceof EvalContext) {
        // UnionContext will collect all values from the "value" context
        // and treat the whole thing as a big collection.
        context =
            new UnionContext(
                evalContext,
                new EvalContext[] {(EvalContext) value });
    }
    else {
        context = evalContext.getRootContext().getConstantContext(value);
    }

    if (firstMatch
        && isSimpleExpressionPath()
        && !(context instanceof NodeSetContext)) {
        EvalContext ctx = context;
        NodePointer ptr = (NodePointer) ctx.getSingleNodePointer();
        if (ptr != null
            && (ptr.getIndex() == NodePointer.WHOLE_COLLECTION
                || predicates == null
                || predicates.length == 0)) {
            return SimplePathInterpreter.interpretSimpleExpressionPath(
                evalContext,
                ptr,
                predicates,
                getSteps());
        }
    }
    if (predicates != null) {
        for (int j = 0; j < predicates.length; j++) {
            if (j != 0) {
                context = new UnionContext(context, new EvalContext[]{context});
            }
            context = new PredicateContext(context, predicates[j]);
        }
    }
    return firstMatch ? (Object) getSingleNodePointerForSteps(context)
            : evalSteps(context);
}