Item item = context.getContextItem();
if (!(item instanceof NodeInfo)) {
out.append(item, locationId);
return null;
}
NodeInfo source = (NodeInfo)item;
// Processing depends on the node kind.
switch(source.getNodeKind()) {
case Type.ELEMENT:
// use the generic code for creating new elements
return super.processLeavingTail(c2);
case Type.ATTRIBUTE:
try {
CopyOf.copyAttribute(source, schemaType, validation, locationId, c2);
} catch (NoOpenStartTagException err) {
DynamicError e = new DynamicError(err.getMessage());
e.setXPathContext(context);
e.setErrorCode(err.getErrorCode());
context.getController().recoverableError(e);
}
break;
case Type.TEXT:
out.characters(source.getStringValue(), locationId, 0);
break;
case Type.PROCESSING_INSTRUCTION:
out.processingInstruction(source.getDisplayName(), source.getStringValue(), locationId, 0);
break;
case Type.COMMENT:
out.comment(source.getStringValue(), locationId, 0);
break;
case Type.NAMESPACE:
try {
source.copy(out, NodeInfo.NO_NAMESPACES, false, locationId);
} catch (NoOpenStartTagException err) {
DynamicError e = new DynamicError(err.getMessage());
e.setXPathContext(context);
e.setErrorCode(err.getErrorCode());
context.getController().recoverableError(e);
}
break;
case Type.DOCUMENT:
Receiver val = controller.getConfiguration().
getDocumentValidator(out,
source.getBaseURI(),
controller.getNamePool(),
validation);
if (val != out) {
SequenceReceiver sr = new TreeReceiver(val);
sr.setConfiguration(controller.getConfiguration());
c2.setReceiver(sr);
val = sr;
}
val.setConfiguration(controller.getConfiguration());
val.startDocument(0);
processChildren(c2);
val.endDocument();
break;
default:
throw new IllegalArgumentException("Unknown node kind " + source.getNodeKind());
}
return null;
}