/**
* Execute the XUpdate commands against a document.
*/
public void execute(Node contextNode) throws Exception {
CommandObject currentCommand = new DefaultCommand(contextNode);
Enumeration commands = super.query[0].elements();
Enumeration attributes = super.query[1].elements();
Enumeration characters = super.query[2].elements();
Node origNode = contextNode;
CommandObject.getXPath().setNamespace(nsMap.getContextNode());
while (commands.hasMoreElements()) {
int id = ((Integer) commands.nextElement()).intValue();
if (id == CommandConstants.ATTRIBUTES) {
currentCommand.submitAttributes((Hashtable) attributes.nextElement());
} else if (id == CommandConstants.CHARACTERS) {
currentCommand.submitCharacters((String) characters.nextElement());
} else if (id > 0) {
if (!currentCommand.submitInstruction(id)) {
super.commandConstants.setContextNode(contextNode);
currentCommand = super.commandConstants.commandForID(id);
if (currentCommand == null) {
throw new Exception("Operation can not have any XUpdate-instruction!");
}
currentCommand.reset();
}
} else {
if (!currentCommand.executeInstruction()) {
try {
contextNode = currentCommand.execute();
} catch (Exception e) {
// While not ideal, CommandObject.execute throws
// Exception("no nodes selected !") if nothing is
// selected for modification we trap that case
// and ignore allowing continued processing
// of remaining xupdate instructions that may be present
if (!"no nodes selected !".equals(e.getMessage())) {
throw e;
}
}
// Default do-nothing command will soak up anything
// (characters, attributes, etc.) encountered until we
// come across the next xupdate instruction
// (e.g. remove, append, insert, etc.)
currentCommand = new DefaultCommand(contextNode);
}
}
}
if (origNode instanceof CompressedNode) {