use of org.sirix.node.PINode in project sirix by sirixdb.
the class NodeFactoryImpl method createPINode.
@Override
public PINode createPINode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, @Nonnegative final long rightSibKey, final QNm target, final byte[] content, final boolean isCompressed, @Nonnegative final long pathNodeKey, final Optional<SirixDeweyID> id) throws SirixIOException {
final long revision = mPageWriteTrx.getRevisionNumber();
final int prefixKey = target.getPrefix() != null && !target.getPrefix().isEmpty() ? mPageWriteTrx.createNameKey(target.getPrefix(), Kind.PROCESSING_INSTRUCTION) : -1;
final int localNameKey = mPageWriteTrx.createNameKey(target.getLocalName(), Kind.PROCESSING_INSTRUCTION);
final int uriKey = mPageWriteTrx.createNameKey(target.getNamespaceURI(), Kind.NAMESPACE);
final NodeDelegate nodeDel = new NodeDelegate(mPageWriteTrx.getActualRevisionRootPage().getMaxNodeKey() + 1, parentKey, 0, revision, id);
final StructNodeDelegate structDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), rightSibKey, leftSibKey, 0, 0);
final NameNodeDelegate nameDel = new NameNodeDelegate(nodeDel, uriKey, prefixKey, localNameKey, pathNodeKey);
final ValNodeDelegate valDel = new ValNodeDelegate(nodeDel, content, false);
return (PINode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new PINode(structDel, nameDel, valDel, mPageWriteTrx), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
use of org.sirix.node.PINode in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method pi.
/**
* Processing instruction.
*
* @param target target PI
* @param content content of PI
* @param insert insertion location
* @throws SirixException if any unexpected error occurs
*/
private XdmNodeWriteTrx pi(final String target, final String content, final Insert insert) throws SirixException {
final byte[] targetBytes = getBytes(target);
if (!XMLToken.isNCName(checkNotNull(targetBytes))) {
throw new IllegalArgumentException("The target is not valid!");
}
if (content.contains("?>-")) {
throw new SirixUsageException("The content must not contain '?>-'");
}
acquireLock();
try {
if (getCurrentNode() instanceof StructNode) {
checkAccessAndCommit();
// Insert new processing instruction node.
final byte[] processingContent = getBytes(content);
long parentKey = 0;
long leftSibKey = 0;
long rightSibKey = 0;
InsertPos pos = InsertPos.ASFIRSTCHILD;
Optional<SirixDeweyID> id = Optional.<SirixDeweyID>empty();
switch(insert) {
case ASFIRSTCHILD:
parentKey = getCurrentNode().getNodeKey();
leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
rightSibKey = ((StructNode) getCurrentNode()).getFirstChildKey();
id = newFirstChildID();
break;
case ASRIGHTSIBLING:
parentKey = getCurrentNode().getParentKey();
leftSibKey = getCurrentNode().getNodeKey();
rightSibKey = ((StructNode) getCurrentNode()).getRightSiblingKey();
pos = InsertPos.ASRIGHTSIBLING;
id = newRightSiblingID();
break;
case ASLEFTSIBLING:
parentKey = getCurrentNode().getParentKey();
leftSibKey = ((StructNode) getCurrentNode()).getLeftSiblingKey();
rightSibKey = getCurrentNode().getNodeKey();
pos = InsertPos.ASLEFTSIBLING;
id = newLeftSiblingID();
break;
default:
throw new IllegalStateException("Insert location not known!");
}
final QNm targetName = new QNm(target);
final long pathNodeKey = mBuildPathSummary ? mPathSummaryWriter.getPathNodeKey(targetName, Kind.PROCESSING_INSTRUCTION) : 0;
final PINode node = mNodeFactory.createPINode(parentKey, leftSibKey, rightSibKey, targetName, processingContent, mCompression, pathNodeKey, id);
// Adapt local nodes and hashes.
mNodeReader.setCurrentNode(node);
adaptForInsert(node, pos, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
return this;
} else {
throw new SirixUsageException("Current node must be a structural node!");
}
} finally {
unLock();
}
}
Aggregations