Search in sources :

Example 11 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class AVLTreeReader method getLastChildKind.

@Override
public Kind getLastChildKind() {
    final Kind lastChildKind = moveToLastChild().get().getKind();
    moveToParent();
    return lastChildKind;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind)

Example 12 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class LabelFMSEVisitor method addLeafLabel.

/**
 * Add leaf node label.
 */
private void addLeafLabel() {
    final Kind nodeKind = mRtx.getKind();
    if (!mLeafLabels.containsKey(nodeKind)) {
        mLeafLabels.put(nodeKind, new ArrayList<Long>());
    }
    mLeafLabels.get(nodeKind).add(mRtx.getNodeKey());
}
Also used : Kind(org.sirix.node.Kind)

Example 13 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class StAXDiffSerializer method peek.

@Override
public XMLEvent peek() throws XMLStreamException {
    final long currNodeKey = mAxis.getTransaction().getNodeKey();
    final NodeReadTrx rtx = mAxis.getTransaction();
    try {
        if (!mHasNext && mEmitEndDocument) {
            mEvent = mFac.createEndDocument();
        } else if (!mHasNext) {
            return null;
        } else {
            if (mCloseElements && !mCloseElementsEmitted) {
                final TransactionTuple trxTuple = mStack.peek();
                final NodeReadTrx trx = trxTuple.getRtx();
                final long nodeKey = trx.getNodeKey();
                trx.moveTo(trxTuple.getKey());
                emitEndTag(trxTuple.getRtx());
                trx.moveTo(nodeKey);
            } else {
                if (mFirst && mAxis.isSelfIncluded() == IncludeSelf.YES) {
                    emitNode(rtx);
                } else {
                    if (rtx.hasFirstChild()) {
                        rtx.moveToFirstChild();
                        emitNode(rtx);
                    } else if (rtx.hasRightSibling()) {
                        rtx.moveToRightSibling();
                        final Kind nodeKind = rtx.getKind();
                        processNode(nodeKind);
                    } else if (rtx.hasParent()) {
                        rtx.moveToParent();
                        emitEndTag(rtx);
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new XMLStreamException(e);
    }
    rtx.moveTo(currNodeKey);
    return mEvent;
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) Kind(org.sirix.node.Kind) TransactionTuple(org.sirix.gui.view.TransactionTuple) IOException(java.io.IOException)

Example 14 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class StAXDiffSerializer method emit.

/**
 * Move to node and emit it.
 *
 * @param pRtx
 *          Read Transaction.
 * @throws IOException
 *           if any I/O error occurred
 */
private void emit(final NodeReadTrx pRtx) throws IOException {
    assert pRtx != null;
    // Emit pending update elements.
    if (!mUpdatedStack.isEmpty()) {
        mDiff = DiffType.UPDATED;
        final TransactionTuple tuple = mUpdatedStack.peek();
        final NodeReadTrx trx = tuple.getRtx();
        final long nodeKey = trx.getNodeKey();
        trx.moveTo(tuple.getKey());
        if (mFirstUpdate && mDepth <= tuple.getDepth() && trx.getKind() == Kind.ELEMENT) {
            mFirstUpdate = false;
            mStack.pop();
            emitEndTag(trx);
        } else {
            mUpdatedStack.pop();
            emitNode(trx);
            if (trx.getKind() == Kind.ELEMENT) {
                mStack.push(tuple);
            }
            trx.moveTo(nodeKey);
            assert mUpdatedStack.isEmpty();
        }
    } else // Emit pending end elements.
    if (mCloseElements) {
        final long pNodeKey = pRtx.getNodeKey();
        final TransactionTuple tuple = mStack.peek();
        NodeReadTrx rtx = tuple.getRtx();
        final long nodeKey = rtx.getNodeKey();
        int depth = tuple.getDepth();
        mDiff = tuple.getDiff();
        if (mDepth < depth || (mDiff == DiffType.UPDATED && mFirstUpdate)) {
            if (mDiff == DiffType.UPDATED) {
                mFirstUpdate = false;
            }
            rtx.moveTo(mStack.pop().getKey());
            emitEndTag(rtx);
            rtx.moveTo(nodeKey);
        } else {
            mFirstUpdate = true;
            rtx.moveTo(mStack.pop().getKey());
            emitEndTag(rtx);
            rtx.moveTo(nodeKey);
            mCloseElementsEmitted = true;
            mCloseElements = false;
        }
        pRtx.moveTo(pNodeKey);
    } else {
        mCloseElementsEmitted = false;
        // Emit node.
        emitNode(pRtx);
        mLastKey = pRtx.getNodeKey();
        if (mLastKey == 2878) {
            System.out.println();
        }
        mDiff = mAxis.getDiff();
        final int depth = mAxis.getDepth();
        if (mDiff == DiffType.UPDATED) {
            mFirstUpdate = true;
            mUpdatedStack.push(new TransactionTuple(mAxis.getOldRtx().getNodeKey(), mAxis.getOldRtx(), mAxis.getDiff(), mAxis.getDepth()));
        }
        // Push end element to stack if we are a start element.
        if (pRtx.getKind() == Kind.ELEMENT) {
            mStack.push(new TransactionTuple(mLastKey, pRtx, mAxis.getDiff(), mAxis.getDepth()));
        }
        final Kind nodeKind = pRtx.getKind();
        // required.
        if (mLastKey != Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
            if (mAxis.hasNext()) {
                final long peekKey = mAxis.peek();
                mDepth = mAxis.getDepth();
                mAxis.getTransaction().moveTo(peekKey);
                if ((depth > mDepth) || (nodeKind == Kind.ELEMENT && mLastKey != mAxis.getTransaction().getParentKey())) {
                    moveToNextNode();
                } else {
                    mAxis.getTransaction().moveTo(mLastKey);
                }
            } else {
                mToLastKey = true;
                mCloseElements = true;
                mAxis.getTransaction().moveToDocumentRoot();
                mDepth = 0;
            }
        }
    }
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) Kind(org.sirix.node.Kind) TransactionTuple(org.sirix.gui.view.TransactionTuple)

Example 15 with Kind

use of org.sirix.node.Kind in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getLastChildKind.

@Override
public Kind getLastChildKind() {
    assertNotClosed();
    if (mCurrentNode instanceof StructNode && hasLastChild()) {
        final long nodeKey = mCurrentNode.getNodeKey();
        moveToLastChild();
        final Kind lastChildKind = mCurrentNode.getKind();
        moveTo(nodeKey);
        return lastChildKind;
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

Kind (org.sirix.node.Kind)20 PageKind (org.sirix.page.PageKind)13 StructNode (org.sirix.node.interfaces.StructNode)5 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 NodeReadTrx (org.sirix.api.NodeReadTrx)2 SirixUsageException (org.sirix.exception.SirixUsageException)2 TransactionTuple (org.sirix.gui.view.TransactionTuple)2 NameNode (org.sirix.node.interfaces.NameNode)2 NamePage (org.sirix.page.NamePage)2 HashMap (java.util.HashMap)1 Axis (org.sirix.api.Axis)1 ChildAxis (org.sirix.axis.ChildAxis)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)1 PostOrderAxis (org.sirix.axis.PostOrderAxis)1 FilterAxis (org.sirix.axis.filter.FilterAxis)1 NameFilter (org.sirix.axis.filter.NameFilter)1 PathKindFilter (org.sirix.axis.filter.PathKindFilter)1