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();
}
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations