Search in sources :

Example 1 with PINode

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());
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) PINode(org.sirix.node.PINode) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate)

Example 2 with PINode

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();
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) PINode(org.sirix.node.PINode) SirixUsageException(org.sirix.exception.SirixUsageException) SirixDeweyID(org.sirix.node.SirixDeweyID) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

PINode (org.sirix.node.PINode)2 QNm (org.brackit.xquery.atomic.QNm)1 SirixUsageException (org.sirix.exception.SirixUsageException)1 SirixDeweyID (org.sirix.node.SirixDeweyID)1 NameNodeDelegate (org.sirix.node.delegates.NameNodeDelegate)1 NodeDelegate (org.sirix.node.delegates.NodeDelegate)1 StructNodeDelegate (org.sirix.node.delegates.StructNodeDelegate)1 ValNodeDelegate (org.sirix.node.delegates.ValNodeDelegate)1 StructNode (org.sirix.node.interfaces.StructNode)1 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)1