protected boolean pushPop (boolean isPush, boolean needCleanup,
AWComponent component)
{
boolean didCreate = false;
AWEnvironmentStack env = component.env();
Context context = (Context)env.peek(EnvKey);
Assert.that(isPush || context != null, "Should always have context on pop");
boolean forceCreate = isPush && (_pushNewContextBinding != null && _pushNewContextBinding.booleanValue(component) );
if (context == null || forceCreate) {
UIMeta meta = UIMeta.getInstance();
context = meta.newContext();
((UIMeta.UIContext)context).setRequestContext(component.requestContext());
env.push(EnvKey, context);
didCreate = true;
}
if (component.requestContext().currentPhase() == AWRequestContext.Phase_Render) {
// if we haven't checked, look for and init embedded MetaRules tags
if (_hasMetaRuleChildren == 0) {
_hasMetaRuleChildren = initEmbeddedMetaRules(component, context) ? 1 : -1;
}
}
// If we have children, push our template on as context
if (_hasMetaRuleChildren == 1) {
context.merge(MetaRules.TemplateId, component.templateName());
}
AWBindingDictionary bindings = _bindings;
if (isPush) {
context.push();
String scopeKey = (_scopeKeyBinding != null)
? (String)_scopeKeyBinding.value(component) : null;
Map <String, Object> values;
if (_valueMapBinding != null && ((values = (Map)_valueMapBinding.value(component)) != null)) {
// ToDo: sort based on Meta (KeyData) defined rank (e.g. module -> class -> operation ...)
// ToDo: cache sort?
List<String> sortedKeys = new ArrayList(values.keySet());
Collections.sort(sortedKeys);
for (String key : sortedKeys) {
if (key.equals(scopeKeyBindingKey)) {
scopeKey = (String)values.get(key);
} else {
context.set(key, values.get(key));
}
}
}
for (int index = bindings.size() - 1; index >= 0; index--) {
AWBinding currentBinding = bindings.elementAt(index);
Object value = currentBinding.value(component);
String key = bindings.keyAt(index);
context.set(key, value);
}
if (scopeKey != null) context.setScopeKey(scopeKey);
} else {
context.pop();
}
if (needCleanup) {
env.pop(EnvKey);
}
return didCreate;
}