use of org.sirix.node.delegates.NodeDelegate 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.delegates.NodeDelegate in project sirix by sirixdb.
the class NamespaceNodeTest method testNamespaceNode.
@Test
public void testNamespaceNode() throws IOException {
final NodeDelegate nodeDel = new NodeDelegate(99l, 13l, 0, 0, Optional.of(SirixDeweyID.newRootID()));
final NameNodeDelegate nameDel = new NameNodeDelegate(nodeDel, 13, 14, 15, 1);
// Create empty node.
final NamespaceNode node = new NamespaceNode(nodeDel, nameDel, new QNm("ns", "a", "p"));
// Serialize and deserialize node.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
node.getKind().serialize(new DataOutputStream(out), node, mPageReadTrx);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final NamespaceNode node2 = (NamespaceNode) Kind.NAMESPACE.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
check(node2);
}
use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.
the class TextNodeTest method testTextRootNode.
@Test
public void testTextRootNode() throws IOException {
// Create empty node.
final byte[] value = { (byte) 17, (byte) 18 };
final NodeDelegate del = new NodeDelegate(13, 14, 0, 0, Optional.of(SirixDeweyID.newRootID()));
final ValNodeDelegate valDel = new ValNodeDelegate(del, value, false);
final StructNodeDelegate strucDel = new StructNodeDelegate(del, Fixed.NULL_NODE_KEY.getStandardProperty(), 16l, 15l, 0l, 0l);
final TextNode node = new TextNode(valDel, strucDel);
check(node);
// Serialize and deserialize node.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
node.getKind().serialize(new DataOutputStream(out), node, mPageReadTrx);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final TextNode node2 = (TextNode) Kind.TEXT.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
check(node2);
}
use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.
the class AttributeNodeTest method testAttributeNode.
@Test
public void testAttributeNode() throws IOException {
final byte[] value = { (byte) 17, (byte) 18 };
final NodeDelegate del = new NodeDelegate(99, 13, 0, 0, Optional.of(SirixDeweyID.newRootID()));
final NameNodeDelegate nameDel = new NameNodeDelegate(del, 13, 14, 15, 1);
final ValNodeDelegate valDel = new ValNodeDelegate(del, value, false);
final AttributeNode node = new AttributeNode(del, nameDel, valDel, new QNm("ns", "a", "p"));
// Create empty node.
check(node);
// Serialize and deserialize node.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
node.getKind().serialize(new DataOutputStream(out), node, mPageReadTrx);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final AttributeNode node2 = (AttributeNode) Kind.ATTRIBUTE.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
check(node2);
}
use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.
the class DocumentRootNodeTest method testDocumentRootNode.
@Test
public void testDocumentRootNode() throws IOException {
// Create empty node.
final NodeDelegate nodeDel = new NodeDelegate(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, Optional.of(SirixDeweyID.newRootID()));
final StructNodeDelegate strucDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, 0);
final DocumentRootNode node = new DocumentRootNode(nodeDel, strucDel);
check(node);
// Serialize and deserialize node.
final ByteArrayOutputStream out = new ByteArrayOutputStream();
node.getKind().serialize(new DataOutputStream(out), node, mPageReadTrx);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final DocumentRootNode node2 = (DocumentRootNode) Kind.DOCUMENT.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
check(node2);
}
Aggregations