public void execute(final EventDispatcher evtDispatcher,
final ErrorReporter errRep, final SCInstance scInstance,
final Log appLog, final Collection derivedEvents)
throws ModelException, SCXMLExpressionException {
State parentState = getParentState();
Context ctx = scInstance.getContext(parentState);
Evaluator eval = scInstance.getEvaluator();
ctx.setLocal(getNamespacesKey(), getNamespaces());
// "location" gets preference over "name"
if (!SCXMLHelper.isStringEmpty(location)) {
Node oldNode = eval.evalLocation(ctx, location);
if (oldNode != null) {
//// rvalue may be ...
// a Node, if so, import it at location
Node newNode = null;
try {
if (src != null && src.trim().length() > 0) {
newNode = getSrcNode();
} else {
newNode = eval.evalLocation(ctx, expr);
}
if (newNode != null) {
// adopt children, possible spec clarification needed
for (Node child = newNode.getFirstChild();
child != null;
child = child.getNextSibling()) {
Node importedNode = oldNode.getOwnerDocument().
importNode(child, true);
oldNode.appendChild(importedNode);
}
}
} catch (SCXMLExpressionException see) {
// or something else, stuff toString() into lvalue
Object valueObject = eval.eval(ctx, expr);
SCXMLHelper.setNodeValue(oldNode, valueObject.toString());
}
if (appLog.isDebugEnabled()) {
appLog.debug("<assign>: data node '" + oldNode.getNodeName()
+ "' updated");
}
TriggerEvent ev = new TriggerEvent(name + ".change",
TriggerEvent.CHANGE_EVENT);
derivedEvents.add(ev);
} else {
appLog.error("<assign>: location does not point to"
+ " a <data> node");
}
} else {
// lets try "name" (usage as in Sep '05 WD, useful with <var>)
if (!ctx.has(name)) {
errRep.onError(ErrorConstants.UNDEFINED_VARIABLE, name
+ " = null", parentState);
} else {
Object varObj = null;
if (src != null && src.trim().length() > 0) {
varObj = getSrcNode();
} else {
varObj = eval.eval(ctx, expr);
}
ctx.set(name, varObj);
if (appLog.isDebugEnabled()) {
appLog.debug("<assign>: Set variable '" + name + "' to '"
+ String.valueOf(varObj) + "'");
}
TriggerEvent ev = new TriggerEvent(name + ".change",
TriggerEvent.CHANGE_EVENT);
derivedEvents.add(ev);
}
}
ctx.setLocal(getNamespacesKey(), null);
}