Package org.apache.commons.jxpath.ri.model

Examples of org.apache.commons.jxpath.ri.model.NodePointer


            Step[] steps, int currentStep,
            Expression[] predicates, int currentPredicate)
    {
        Expression predicate = predicates[currentPredicate];
        String key = keyFromPredicate(context, predicate);
        NodePointer child = valuePointer(parent);
        if (child instanceof PropertyOwnerPointer) {
            PropertyPointer pointer =
                ((PropertyOwnerPointer) child).getPropertyPointer();
            pointer.setPropertyName(key);
            if (pointer.isActual()) {
                return doPredicate(
                    context,
                    pointer,
                    steps,
                    currentStep,
                    predicates,
                    currentPredicate + 1);
            }
        }
        else if (child.isCollection()) {
            // For each node in the collection, perform the following:
            // if the node is a property owner, apply this predicate to it;
            // if the node is a collection, apply this predicate to each elem.;
            // if the node is not a prop owner or a collection,
            //  see if it has the attribute "name" with the right value,
            //  if so - proceed to the next predicate
            NodePointer bestMatch = null;
            int bestQuality = 0;
            int count = child.getLength();
            for (int i = 0; i < count; i++) {
                child.setIndex(i);
                NodePointer valuePointer = valuePointer(child);
                if (valuePointer == child) {
                    valuePointer = (NodePointer) child.clone();
                }
                NodePointer pointer;
                if ((valuePointer instanceof PropertyOwnerPointer)
                    || valuePointer.isCollection()) {
                    pointer =
                        doPredicateName(
                            context,
                            valuePointer,
                            steps,
                            currentStep,
                            predicates,
                            currentPredicate);
                }
                else if (isNameAttributeEqual(valuePointer, key)) {
                    pointer =
                        doPredicate(
                            context,
                            valuePointer,
                            steps,
                            currentStep,
                            predicates,
                            currentPredicate + 1);
                }
                else {
                    pointer = null;
                }
                if (pointer != null) {
                    int quality = computeQuality(pointer);
                    if (quality == PERFECT_MATCH) {
                        return pointer;
                    }
                    if (quality > bestQuality) {
                        bestMatch = (NodePointer) pointer.clone();
                        bestQuality = quality;
                    }
                }
            }
            if (bestMatch != null) {
                return bestMatch;
            }
        }
        else {
            // If the node is a standard InfoSet node (e.g. DOM Node),
            // employ doPredicates_standard, which will iterate through
            // the node's children and apply all predicates
            NodePointer found =
                doPredicatesStandard(
                    context,
                    Collections.singletonList(child),
                    steps,
                    currentStep,
View Full Code Here


        // If all predicates have been processed, take the first
        // element from the list of results and proceed to the
        // remaining steps with that element.
        if (currentPredicate == predicates.length) {
            NodePointer pointer = (NodePointer) parents.get(0);
            return doStep(context, pointer, steps, currentStep + 1);
        }

        Expression predicate = predicates[currentPredicate];
        if (predicate instanceof NameAttributeTest) {
            String key = keyFromPredicate(context, predicate);
            List newList = new ArrayList();
            for (int i = 0; i < parents.size(); i++) {
                NodePointer pointer = (NodePointer) parents.get(i);
                if (isNameAttributeEqual(pointer, key)) {
                    newList.add(pointer);
                }
            }
            if (newList.size() == 0) {
                return null;
            }
            return doPredicatesStandard(
                context,
                newList,
                steps,
                currentStep,
                predicates,
                currentPredicate + 1);
        }
        else {
            // For a subscript, simply take the corresponding
            // element from the list of results and
            // proceed to the remaining predicates with that element
            int index = indexFromPredicate(context, predicate);
            if (index < 0 || index >= parents.size()) {
                return null;
            }
            NodePointer ptr = (NodePointer) parents.get(index);
            return doPredicate(
                context,
                ptr,
                steps,
                currentStep,
View Full Code Here

            Step[] steps, int currentStep,
            Expression[] predicates, int currentPredicate)
    {
        Expression predicate = predicates[currentPredicate];
        int index = indexFromPredicate(context, predicate);
        NodePointer pointer = parent;
        if (isCollectionElement(pointer, index)) {
            pointer.setIndex(index);
            return doPredicate(
                context,
                pointer,
                steps,
                currentStep,
View Full Code Here

                            return (Node)nodeList.get(i);
                        }
                    };
                Iterator iter = GET_CHILD_NODES.iteratePointers(getContext());
                for (int i = 0; iter.hasNext(); i++) {
                    NodePointer p = (NodePointer)iter.next();
                    Object value = p.getNode();
                    if (value instanceof NodeAdapter) {
                        p = (NodePointer) ((NodeAdapter)value).ptr;
                        value = p.getNode();
                    } else if (value instanceof DocumentAdapter) {
                        value = ((DocumentAdapter)value).unwrap();
                    }
                    if (value instanceof Node) {
                        nodeList.add(value);
                    } else {
                        QName q = p.getName();
                        nodeList.add(new ElementAdapter(this, p, i,
                                                        q.getName(),
                                                        value));
                    }
                }
View Full Code Here

                Iterator iter = GET_ATTRS.iteratePointers(getContext());
                final List attrList = new ArrayList();
                final Map nameMap = new HashMap();
                final Map qnameMap = new HashMap();
                while (iter.hasNext()) {
                    final NodePointer np = (NodePointer)iter.next();
                    Attr attr = new AttrAdapter(this, np);
                    attrList.add(attr);
                    String localName = np.getName().getName();
                    nameMap.put(localName, attr);
                    qnameMap.put("{"+np.getNamespaceURI() + "}" +
                                 localName, attr);
                }
                attributes = new NamedNodeMap() {
                        public Node getNamedItem(String name) {
                            return (Node)nameMap.get(name);
View Full Code Here

     * Tests comparing child node pointers for child nodes.
     */
    @Test
    public void testCompareChildNodePointersChildren()
    {
        NodePointer p1 = new ConfigurationNodePointer<ImmutableNode>(
                pointer, root.getChildren().get(1), handler);
        NodePointer p2 = new ConfigurationNodePointer<ImmutableNode>(
                pointer, root.getChildren().get(3), handler);
        assertEquals("Incorrect order", -1, pointer.compareChildNodePointers(
                p1, p2));
        assertEquals("Incorrect symmetric order", 1, pointer
                .compareChildNodePointers(p2, p1));
View Full Code Here

    @Test
    public void testCompareChildNodePointersAttributes()
    {
        ImmutableNode n1 = new ImmutableNode.Builder().name("n1").create();
        ImmutableNode n2 = new ImmutableNode.Builder().name("n2").create();
        NodePointer p1 =
                new ConfigurationNodePointer<ImmutableNode>(pointer, n1,
                        handler);
        NodePointer p2 =
                new ConfigurationNodePointer<ImmutableNode>(pointer, n2,
                        handler);
        assertEquals("Incorrect order", 0,
                pointer.compareChildNodePointers(p1, p2));
        assertEquals("Incorrect symmetric order", 0,
View Full Code Here

        assertEquals("Iterator count differs from children count", node
                .getChildren().size(), iteratorSize(it));

        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pchild = it.getNodePointer();
            assertEquals("Wrong child", node.getChildren().get(index - 1),
                    pchild.getNode());
            checkIterators(pchild);
        }

        it = p.attributeIterator(new QName(null, "*"));
        assertEquals("Iterator count differs from attribute count", node
                .getAttributes().size(), iteratorSize(it));
        for (int index = 1; it.setPosition(index); index++)
        {
            NodePointer pattr = it.getNodePointer();
            assertTrue("Node pointer is no attribute", pattr.isAttribute());
            assertTrue("Wrong attribute name", node.getAttributes()
                    .containsKey(pattr.getName().getName()));
        }
    }
View Full Code Here

            return new NodeSetContext(
                new RootContext(jxpathContext, null),
                (NodeSet) constant);
        }

        NodePointer pointer;
        if (constant instanceof NodePointer) {
            pointer = (NodePointer) constant;
        }
        else {
            pointer = NodePointer.newNodePointer(
View Full Code Here

        // Each set contains exactly one node: the parent
        if (setStarted) {
            return false;
        }
        setStarted = true;
        NodePointer thisLocation = parentContext.getCurrentNodePointer();
        currentNodePointer = thisLocation.getImmediateParentPointer();
        while (currentNodePointer != null
            && currentNodePointer.isContainer()) {
            currentNodePointer = currentNodePointer.getImmediateParentPointer();
        }
        if (currentNodePointer != null
View Full Code Here

TOP

Related Classes of org.apache.commons.jxpath.ri.model.NodePointer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.