Search in sources :

Example 6 with Kind

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

the class XdmNodeWriterTrxImpl method setName.

@Override
public XdmNodeWriteTrx setName(final QNm name) throws SirixException {
    checkNotNull(name);
    acquireLock();
    try {
        if (getCurrentNode() instanceof NameNode) {
            if (!getName().equals(name)) {
                checkAccessAndCommit();
                NameNode node = (NameNode) mNodeReader.getCurrentNode();
                final long oldHash = node.hashCode();
                // Create new keys for mapping.
                final int prefixKey = name.getPrefix() != null && !name.getPrefix().isEmpty() ? getPageTransaction().createNameKey(name.getPrefix(), node.getKind()) : -1;
                final int localNameKey = name.getLocalName() != null && !name.getLocalName().isEmpty() ? getPageTransaction().createNameKey(name.getLocalName(), node.getKind()) : -1;
                final int uriKey = name.getNamespaceURI() != null && !name.getNamespaceURI().isEmpty() ? getPageTransaction().createNameKey(name.getNamespaceURI(), Kind.NAMESPACE) : -1;
                // Adapt path summary.
                if (mBuildPathSummary) {
                    mPathSummaryWriter.adaptPathForChangedNode(node, name, uriKey, prefixKey, localNameKey, OPType.SETNAME);
                }
                // Remove old keys from mapping.
                final Kind nodeKind = node.getKind();
                final int oldPrefixKey = node.getPrefixKey();
                final int oldLocalNameKey = node.getLocalNameKey();
                final int oldUriKey = node.getURIKey();
                final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
                page.removeName(oldPrefixKey, nodeKind);
                page.removeName(oldLocalNameKey, nodeKind);
                page.removeName(oldUriKey, Kind.NAMESPACE);
                // Set new keys for current node.
                node = (NameNode) getPageTransaction().prepareEntryForModification(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
                node.setLocalNameKey(localNameKey);
                node.setURIKey(uriKey);
                node.setPrefixKey(prefixKey);
                node.setPathNodeKey(mBuildPathSummary ? mPathSummaryWriter.getNodeKey() : 0);
                mNodeReader.setCurrentNode(node);
                adaptHashedWithUpdate(oldHash);
            }
            return this;
        } else {
            throw new SirixUsageException("setName is not allowed if current node is not an INameNode implementation!");
        }
    } finally {
        unLock();
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) NamePage(org.sirix.page.NamePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 7 with Kind

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

the class WildcardFilter method filter.

@Override
public final boolean filter() {
    final Kind kind = getTrx().getKind();
    switch(kind) {
        case ELEMENT:
            if (mType == EType.LOCALNAME) {
                // local name is given
                return localNameMatch();
            } else {
                // namespace prefix is given
                final int prefixKey = mKnownPartKey;
                for (int i = 0, nsCount = getTrx().getNamespaceCount(); i < nsCount; i++) {
                    getTrx().moveToNamespace(i);
                    if (getTrx().getPrefixKey() == prefixKey) {
                        getTrx().moveToParent();
                        return true;
                    }
                    getTrx().moveToParent();
                }
                return false;
            }
        case ATTRIBUTE:
            if (mType == EType.LOCALNAME) {
                // local name is given
                return localNameMatch();
            } else {
                final String prefix = getTrx().nameForKey(getTrx().getPrefixKey());
                final int prefixKey = getTrx().keyForName(prefix);
                return prefixKey == mKnownPartKey;
            }
        default:
            return false;
    }
}
Also used : Kind(org.sirix.node.Kind)

Example 8 with Kind

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

the class StAXSerializer method peek.

@Override
public XMLEvent peek() throws XMLStreamException {
    final long currNodeKey = mAxis.getTrx().getNodeKey();
    final XdmNodeReadTrx rtx = mAxis.getTrx();
    try {
        if (!mHasNext && mEmitEndDocument) {
            mEvent = mFac.createEndDocument();
        } else if (!mHasNext) {
            return null;
        } else {
            if (mCloseElements && !mCloseElementsEmitted && !mStack.isEmpty()) {
                rtx.moveTo(mStack.peek());
                emitEndTag(rtx);
            } else {
                if (mFirst && mAxis.isSelfIncluded() == IncludeSelf.YES) {
                    emitNode(rtx);
                } else {
                    if (rtx.hasFirstChild()) {
                        rtx.moveToFirstChild();
                        emitNode(rtx);
                    } else if (rtx.hasRightSibling()) {
                        if (rtx.getRightSiblingKey() == mStartRightSibling) {
                            mEvent = mFac.createEndDocument();
                        } else {
                            rtx.moveToRightSibling();
                            final Kind nodeKind = rtx.getKind();
                            processNode(nodeKind);
                        }
                    } else if (rtx.hasParent()) {
                        if (rtx.getParentKey() == mStartParent) {
                            mEvent = mFac.createEndDocument();
                        } else {
                            rtx.moveToParent();
                            emitEndTag(rtx);
                        }
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new XMLStreamException(e);
    }
    rtx.moveTo(currNodeKey);
    mFirst = false;
    return mEvent;
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XMLStreamException(javax.xml.stream.XMLStreamException) Kind(org.sirix.node.Kind) IOException(java.io.IOException)

Example 9 with Kind

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

the class PathSummaryWriter method getPathNodeKey.

/**
 * Insert a new path node or increment the counter of an existing node and return the path node
 * key.
 *
 * @param name the name of the path node to search for
 * @param pathKind the kind of the path node to search for
 * @return a path node key of the found node, or the path node key of a new inserted node
 * @throws SirixException if anything went wrong
 */
public long getPathNodeKey(final QNm name, final Kind pathKind) throws SirixException {
    final Kind kind = mNodeRtx.getNode().getKind();
    int level = 0;
    if (kind == Kind.DOCUMENT) {
        mPathSummaryReader.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
    } else {
        movePathSummary();
        level = mPathSummaryReader.getLevel();
    }
    final long nodeKey = mPathSummaryReader.getNodeKey();
    final Axis axis = new FilterAxis(new ChildAxis(mPathSummaryReader), new NameFilter(mPathSummaryReader, pathKind == Kind.NAMESPACE ? name.getPrefix() : Utils.buildName(name)), new PathKindFilter(mPathSummaryReader, pathKind));
    long retVal = nodeKey;
    if (axis.hasNext()) {
        axis.next();
        retVal = mPathSummaryReader.getNodeKey();
        final PathNode pathNode = (PathNode) mPageWriteTrx.prepareEntryForModification(retVal, PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
        pathNode.incrementReferenceCount();
    } else {
        assert nodeKey == mPathSummaryReader.getNodeKey();
        insertPathAsFirstChild(name, pathKind, level + 1);
        retVal = mPathSummaryReader.getNodeKey();
    }
    return retVal;
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) NameFilter(org.sirix.axis.filter.NameFilter) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) Axis(org.sirix.api.Axis) ChildAxis(org.sirix.axis.ChildAxis) PostOrderAxis(org.sirix.axis.PostOrderAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) LevelOrderAxis(org.sirix.axis.LevelOrderAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) PathKindFilter(org.sirix.axis.filter.PathKindFilter)

Example 10 with Kind

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

the class AVLTreeReader method getFirstChildKind.

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

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