use of org.sirix.node.Kind in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getParentKind.
@Override
public Kind getParentKind() {
assertNotClosed();
if (mCurrentNode.getParentKey() == Fixed.NULL_NODE_KEY.getStandardProperty()) {
return Kind.UNKNOWN;
}
final long nodeKey = mCurrentNode.getNodeKey();
moveToParent();
final Kind parentKind = mCurrentNode.getKind();
moveTo(nodeKey);
return parentKind;
}
use of org.sirix.node.Kind in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method copy.
/**
* Helper method for copy-operations.
*
* @param rtx the source {@link XdmNodeReadTrx}
* @param insert the insertion strategy
* @throws SirixException if anything fails in sirix
*/
private void copy(final XdmNodeReadTrx trx, final Insert insert) throws SirixException {
assert trx != null;
assert insert != null;
final XdmNodeReadTrx rtx = trx.getResourceManager().beginNodeReadTrx(trx.getRevisionNumber());
assert rtx.getRevisionNumber() == trx.getRevisionNumber();
rtx.moveTo(trx.getNodeKey());
assert rtx.getNodeKey() == trx.getNodeKey();
if (rtx.getKind() == Kind.DOCUMENT) {
rtx.moveToFirstChild();
}
if (!(rtx.isStructuralNode())) {
throw new IllegalStateException("Node to insert must be a structural node (Text, PI, Comment, Document root or Element)!");
}
final Kind kind = rtx.getKind();
switch(kind) {
case TEXT:
final String textValue = rtx.getValue();
switch(insert) {
case ASFIRSTCHILD:
insertTextAsFirstChild(textValue);
break;
case ASLEFTSIBLING:
insertTextAsLeftSibling(textValue);
break;
case ASRIGHTSIBLING:
insertTextAsRightSibling(textValue);
break;
default:
throw new IllegalStateException();
}
break;
case PROCESSING_INSTRUCTION:
switch(insert) {
case ASFIRSTCHILD:
insertPIAsFirstChild(rtx.getName().getLocalName(), rtx.getValue());
break;
case ASLEFTSIBLING:
insertPIAsLeftSibling(rtx.getName().getLocalName(), rtx.getValue());
break;
case ASRIGHTSIBLING:
insertPIAsRightSibling(rtx.getName().getLocalName(), rtx.getValue());
break;
default:
throw new IllegalStateException();
}
break;
case COMMENT:
final String commentValue = rtx.getValue();
switch(insert) {
case ASFIRSTCHILD:
insertCommentAsFirstChild(commentValue);
break;
case ASLEFTSIBLING:
insertCommentAsLeftSibling(commentValue);
break;
case ASRIGHTSIBLING:
insertCommentAsRightSibling(commentValue);
break;
default:
throw new IllegalStateException();
}
break;
default:
new XMLShredder.Builder(this, new StAXSerializer(rtx), insert).build().call();
}
rtx.close();
}
use of org.sirix.node.Kind in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method insertElementAsFirstChild.
@Override
public XdmNodeWriteTrx insertElementAsFirstChild(final QNm name) throws SirixException {
if (!XMLToken.isValidQName(checkNotNull(name))) {
throw new IllegalArgumentException("The QName is not valid!");
}
acquireLock();
try {
final Kind kind = mNodeReader.getCurrentNode().getKind();
if (kind == Kind.ELEMENT || kind == Kind.DOCUMENT) {
checkAccessAndCommit();
final long parentKey = mNodeReader.getCurrentNode().getNodeKey();
final long leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
final long rightSibKey = ((StructNode) mNodeReader.getCurrentNode()).getFirstChildKey();
final long pathNodeKey = mBuildPathSummary ? mPathSummaryWriter.getPathNodeKey(name, Kind.ELEMENT) : 0;
final Optional<SirixDeweyID> id = newFirstChildID();
final ElementNode node = mNodeFactory.createElementNode(parentKey, leftSibKey, rightSibKey, 0, name, pathNodeKey, id);
mNodeReader.setCurrentNode(node);
adaptForInsert(node, InsertPos.ASFIRSTCHILD, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
return this;
} else {
throw new SirixUsageException("Insert is not allowed if current node is not an ElementNode!");
}
} finally {
unLock();
}
}
use of org.sirix.node.Kind in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method removeName.
/**
* Remove a name from the {@link NamePage} reference and the path summary if needed.
*
* @throws SirixException if Sirix fails
*/
private void removeName() throws SirixException {
if (getCurrentNode() instanceof NameNode) {
final NameNode node = ((NameNode) getCurrentNode());
final Kind nodeKind = node.getKind();
final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
page.removeName(node.getPrefixKey(), nodeKind);
page.removeName(node.getLocalNameKey(), nodeKind);
page.removeName(node.getURIKey(), Kind.NAMESPACE);
assert nodeKind != Kind.DOCUMENT;
if (mBuildPathSummary) {
mPathSummaryWriter.remove(node, nodeKind, page);
}
}
}
use of org.sirix.node.Kind in project sirix by sirixdb.
the class PrecedingSiblingAxis method nextKey.
@Override
protected long nextKey() {
final XdmNodeReadTrx rtx = getTrx();
if (mIsFirst) {
mIsFirst = false;
/*
* If the context node is an attribute or namespace node, the following-sibling axis is empty.
*/
final Kind kind = rtx.getKind();
if (kind == Kind.ATTRIBUTE || kind == Kind.NAMESPACE) {
return done();
} else {
if (rtx.hasParent()) {
final long startNodeKey = rtx.getNodeKey();
rtx.moveToParent();
rtx.moveToFirstChild();
if (rtx.getNodeKey() == startNodeKey) {
return Fixed.NULL_NODE_KEY.getStandardProperty();
} else {
final long key = rtx.getNodeKey();
rtx.moveTo(startNodeKey);
return key;
}
}
}
}
if (rtx.hasRightSibling() && rtx.getRightSiblingKey() != getStartKey()) {
return rtx.getRightSiblingKey();
}
return done();
}
Aggregations