* @param node the node to register
* @return the newly registered node, or the one that was already registered with the node's key
*/
private Node registerNewNode(Node node, Key secondaryKey) {
Key key = node.getKey();
RequestEvaluator reval = app.getCurrentRequestEvaluator();
// if no request evaluator is associated with current thread, do not cache node
// as we cannot invoke onInit() on it.
if (reval == null) {
Node old = (Node) cache.get(key);
if (old != null && !old.isNullNode() && old.getState() != INode.INVALID) {
return old;
}
return node;
}
synchronized(cache) {
Node old = (Node) cache.put(key, node);
if (old != null && !old.isNullNode() && old.getState() != INode.INVALID) {
cache.put(key, old);
if (secondaryKey != null) {
cache.put(secondaryKey, old);
}
return old;
} else if (secondaryKey != null) {
cache.put(secondaryKey, node);
}
}
// New node is going ot be used, invoke onInit() on it
// Invoke onInit() if it is defined by this Node's prototype
try {
// We need to reach deap into helma.framework.core to invoke onInit(),
// but the functionality is really worth it.
reval.invokeDirectFunction(node, "onInit", RequestEvaluator.EMPTY_ARGS);
} catch (Exception x) {
app.logError("Error invoking onInit()", x);
}
return node;
}