Package org.exist.numbering

Examples of org.exist.numbering.NodeId


    public Node getLastChild() {
        if (!hasChildNodes())
            {return null;}
        Node node = null;
        if (!isDirty) {
            final NodeId child = nodeId.getChild(children);
            node = ownerDocument.getNode(new NodeProxy(ownerDocument, child));
        }
        if (node == null) {
            final NodeList cl = getChildNodes();
            return cl.item(cl.getLength() - 1);
View Full Code Here


            }
            final StoredNode following = (StoredNode) refChild;
            final StoredNode previous = (StoredNode) following.getPreviousSibling();
            if (previous == null) {
                // there's no sibling node before the new node
                final NodeId newId = following.getNodeId().insertBefore();
                appendChildren(transaction, newId, following.getNodeId(), new NodeImplRef(this),
                    path, nodes, listener);
            } else {
                // insert the new node between the preceding and following sibling
                final NodeId newId = previous.getNodeId().insertNode(following.getNodeId());
                appendChildren(transaction, newId, following.getNodeId(),
                    new NodeImplRef(getLastNode(previous)), path, nodes, listener);
            }
            setDirty(true);
            broker.updateNode(transaction, this, true);
View Full Code Here

                    // persistent node. We scan the current sequence and replace all
                    // in-memory nodes with their new persistent node objects.
                    final DocumentImpl expandedDoc = doc.expandRefs(null);
                    final org.exist.dom.DocumentImpl newDoc = expandedDoc.makePersistent();
                    if (newDoc != null) {
                        NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
                        for (int j = i; j <= size; j++) {
                            v = (NodeValue) values[j];
                            if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
                                NodeImpl node = (NodeImpl) v;
                                if (node.getDocument() == doc) {
                                    if (node.getNodeType() == Node.ATTRIBUTE_NODE)
                                        {node = expandedDoc.getAttribute(node.getNodeNumber());}
                                    else
                                        {node = expandedDoc.getNode(node.getNodeNumber());}
                                    NodeId nodeId = node.getNodeId();
                                    if (nodeId == null)
                                        {throw new XPathException("Internal error: nodeId == null");}
                                    if (node.getNodeType() == Node.DOCUMENT_NODE)
                                        {nodeId = rootId;}
                                    else
View Full Code Here

     * @param contextId
     */
    private NodeSet getDescendantsInSet(int docIdx, NodeSet result, NodeProxy parent,
            boolean childOnly, boolean includeSelf, int mode, int contextId, boolean copyMatches) {
        NodeProxy p;
        final NodeId parentId = parent.getNodeId();
        // document nodes are treated specially
        if (parentId == NodeId.DOCUMENT_NODE) {
            final int end = documentOffsets[docIdx] + documentLengths[docIdx];
            for (int i = documentOffsets[docIdx]; i < end; i++) {
                boolean add;
View Full Code Here

        int low = documentOffsets[docIdx];
        int high = low + (documentLengths[docIdx] - 1);
        final int end = low + documentLengths[docIdx];
        int mid = 0;
        int cmp;
        NodeId id;
        while (low <= high) {
            mid = (low + high) / 2;
            id = nodes[mid].getNodeId();
            if (id.isDescendantOrSelfOf(ancestorId)) {
                break; // found a child node, break out.
            }
            cmp = id.compareTo(ancestorId);
            if (cmp > 0) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
View Full Code Here

     */
    public NodeSet selectPrecedingSiblings(NodeSet contextSet, int contextId) {
        sort();
        final NodeSet result = new NewArrayNodeSet();
        for (final NodeProxy reference : contextSet) {
            final NodeId parentId = reference.getNodeId().getParentId();
            final int docIdx = findDoc(reference.getDocument());
            if (docIdx < 0)
                {continue;}
            // do a binary search to pick some node in the range of valid
            // child ids
            int low = documentOffsets[docIdx];
            int high = low + (documentLengths[docIdx] - 1);
            final int end = low + documentLengths[docIdx];
            int mid = low;
            int cmp;
            NodeProxy p;
            while (low <= high) {
                mid = (low + high) / 2;
                p = nodes[mid];
                if (p.getNodeId().isDescendantOf(parentId)) {
                    break// found a child node, break out.
                }
                cmp = p.getNodeId().compareTo(parentId);
                if (cmp > 0) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            if (low > high) {
                continue; // no node found
            }
            // find the first child node in the range
            while (mid < end && nodes[mid].getNodeId().isDescendantOf(parentId)) {
                ++mid;
            }
            --mid;
            final NodeId refId = reference.getNodeId();
            for (int i = mid; i >= documentOffsets[docIdx]; i--) {
                final NodeId currentId = nodes[i].getNodeId();
                if (!currentId.isDescendantOf(parentId))
                    {break;}
                if (currentId.getTreeLevel() == refId.getTreeLevel() && currentId.compareTo(refId) < 0) {
                    if (Expression.IGNORE_CONTEXT != contextId) {
                        if (Expression.NO_CONTEXT_ID == contextId) {
                            nodes[i].copyContext(reference);
                        } else {
                            nodes[i].addContextNode(contextId, reference);
View Full Code Here

                    public Object start() {
                        EmbeddedXMLStreamReader reader = null;
                        try {
                            final ElementImpl             root            = (ElementImpl)doc.getDocumentElement();
                            reader = broker.getXMLStreamReader( root, true );
                            NodeId                  nodeId;
                            boolean                 attribsAllowed  = false;
                            int                     expectedAttribs = 0;
                            int                     attributeCount  = 0;

                            while( reader.hasNext() ) {
                                final int status = reader.next();

                                nodeId = (NodeId)reader.getProperty( EmbeddedXMLStreamReader.PROPERTY_NODE_ID );
                                ElementNode parent = null;

                                if( ( status != XMLStreamReader.END_ELEMENT ) && !elementStack.isEmpty() ) {
                                    parent = elementStack.peek();
                                    parent.childCount++;

                                    // test parent-child relation
                                    if( !nodeId.isChildOf( parent.elem.getNodeId() ) ) {
                                        return( new ErrorReport.ResourceError( ErrorReport.NODE_HIERARCHY, "Node " + nodeId + " is not a child of " + parent.elem.getNodeId() ) );
                                    }

                                    // test sibling relation
                                    if( ( parent.prevSibling != null ) && !( nodeId.isSiblingOf( parent.prevSibling ) && ( nodeId.compareTo( parent.prevSibling ) > 0 ) ) ) {
                                        return( new ErrorReport.ResourceError( ErrorReport.INCORRECT_NODE_ID, "Node " + nodeId + " is not a sibling of " + parent.prevSibling ) );
                                    }
                                    parent.prevSibling = nodeId;
                                }

                                switch( status ) {

                                    case XMLStreamReader.ATTRIBUTE: {
                                        attributeCount++;
                                        break;
                                    }

                                    case XMLStreamReader.END_ELEMENT: {
                                        if( elementStack.isEmpty() ) {
                                            return( new org.exist.backup.ErrorReport.ResourceError( ErrorReport.NODE_HIERARCHY, "Error in node hierarchy: received END_ELEMENT event " + "but stack was empty!" ) );
                                        }
                                        final ElementNode lastElem = elementStack.pop();
                                        if( lastElem.childCount != lastElem.elem.getChildCount() ) {
                                            return( new ErrorReport.ResourceError( org.exist.backup.ErrorReport.NODE_HIERARCHY, "Element reports incorrect child count: expected " + lastElem.elem.getChildCount() + " but found " + lastElem.childCount ) );
                                        }
                                        break;
                                    }

                                    case XMLStreamReader.START_ELEMENT: {
                                        if( nodeId.getTreeLevel() <= defaultIndexDepth ) {

                                            // check dom.dbx btree, which maps the node
                                            // id to the node's storage address
                                            // look up the node id and check if the
                                            // returned storage address is correct
View Full Code Here

     */
    public NodeSet selectFollowingSiblings(NodeSet contextSet, int contextId) {
        sort();
        final NodeSet result = new NewArrayNodeSet();
        for (final NodeProxy reference : contextSet) {
            final NodeId parentId = reference.getNodeId().getParentId();
            final int docIdx = findDoc(reference.getDocument());
            if (docIdx < 0)
                {return NodeSet.EMPTY_SET;} //BUG: can't be null, make trouble @LocationStep line 388 -shabanovd
            // do a binary search to pick some node in the range of valid
            // child ids
            int low = documentOffsets[docIdx];
            int high = low + (documentLengths[docIdx] - 1);
            final int end = low + documentLengths[docIdx];
            int mid = low;
            int cmp;
            NodeProxy p;
            while (low <= high) {
                mid = (low + high) / 2;
                p = nodes[mid];
                if (p.getNodeId().isDescendantOf(parentId)) {
                    break// found a child node, break out.
                }
                cmp = p.getNodeId().compareTo(parentId);
                if (cmp > 0) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            if (low > high) {
                continue; // no node found
            }
            // find the first child node in the range
            while (mid > documentOffsets[docIdx] && nodes[mid - 1].getNodeId().compareTo(parentId) > -1) {
                --mid;
            }
            final NodeId refId = reference.getNodeId();
            for (int i = mid; i < end; i++) {
                final NodeId currentId = nodes[i].getNodeId();
                if (!currentId.isDescendantOf(parentId))
                    {break;}
                if (currentId.getTreeLevel() == refId.getTreeLevel() && currentId.compareTo(refId) > 0) {
                    if (Expression.IGNORE_CONTEXT != contextId) {
                        if (Expression.NO_CONTEXT_ID == contextId) {
                            nodes[i].copyContext(reference);
                        } else {
                            nodes[i].addContextNode(contextId, reference);
View Full Code Here

        }
    }

    public void selectPreceding( NodeTest test, Sequence result, int position )
            throws XPathException {
        final NodeId myNodeId = getNodeId();
        int    count    = 0;

        for( int i = nodeNumber - 1; i > 0; i-- ) {
            final NodeImpl n = document.getNode( i );
            if( !myNodeId.isDescendantOf( n.getNodeId() ) && test.matches( n ) ) {
                if( ( position < 0 ) || ( ++count == position ) ) {
                    result.add( n );
                }
                if( count == position ) {
                    break;
View Full Code Here

                    break;
                }
                next = (NodeImpl)next.getNextSibling();
            }
        } else {
            final NodeId myNodeId = getNodeId();
            int    count    = 0;
            int    nextNode = nodeNumber + 1;
            while( nextNode < document.size ) {
                final NodeImpl n = document.getNode( nextNode );
                if( !n.getNodeId().isDescendantOf( myNodeId ) && test.matches( n ) ) {
View Full Code Here

TOP

Related Classes of org.exist.numbering.NodeId

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.