}
}
protected Sequence deepCopy(Sequence inSeq) throws XPathException {
context.pushDocumentContext();
final MemTreeBuilder builder = context.getDocumentBuilder();
final DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);
final Serializer serializer = context.getBroker().getSerializer();
serializer.setReceiver(receiver);
try {
final Sequence out = new ValueSequence();
for (final SequenceIterator i = inSeq.iterate(); i.hasNext(); ) {
Item item = i.nextItem();
if (item.getType() == Type.DOCUMENT) {
if (((NodeValue)item).getImplementationType() == NodeValue.PERSISTENT_NODE) {
final StoredNode root = (StoredNode) ((NodeProxy)item).getDocument().getDocumentElement();
item = new NodeProxy(root.getDocument(), root.getNodeId(), root.getInternalAddress());
} else {
item = (Item)((NodeValue) item).getOwnerDocument().getDocumentElement();
}
}
if (Type.subTypeOf(item.getType(), Type.NODE)) {
if (((NodeValue)item).getImplementationType() == NodeValue.PERSISTENT_NODE) {
final int last = builder.getDocument().getLastNode();
final NodeProxy p = (NodeProxy) item;
serializer.toReceiver(p, false, false);
if (p.getNodeType() == Node.ATTRIBUTE_NODE)
{item = builder.getDocument().getLastAttr();}
else
{item = builder.getDocument().getNode(last + 1);}
} else {
((org.exist.memtree.NodeImpl)item).deepCopy();
}
}
out.add(item);