}
public void initWithContext (Context context, AWComponent component)
{
Meta meta = context.meta();
AWTemplate template = component.template();
String templateId = template.templateName().intern();
TemplateData data = (TemplateData)meta.identityCache().get(templateId);
if (data != null && data.template != template) {
// unload rules
for (Map.Entry<MetaRules, Meta.RuleSet> entry : data.elementMap.entrySet()) {
Meta.RuleSet ruleSet = entry.getValue();
ruleSet.disableRules();
// FIXME! Need to support reloading rules with same "natural order"
// salience as in the original rule set
// Force page rerendering, because we are invalidating the global
// match -> property -> componentreference cache and will possibly
// break the interphase (render -> applyValues) change rule for
// meta content rendered *before* this
component.requestContext().forceRerender();
}
data = null;
}
if (data == null) {
data = new TemplateData();
data.template = template;
meta.identityCache().put(templateId, data);
}
Meta.RuleSet ruleSet= data.elementMap.get(this);
if (ruleSet == null) {
meta.beginRuleSet(Meta.TemplateRulePriority, template.templateName());
try {
new Parser(meta, contentString()).addRulesWithSelector(
Arrays.asList(new Rule.Selector(TemplateId, templateId)));
} catch (Error e) {
meta.endRuleSet().disableRules();
throw new AWGenericException(Fmt.S("Error reading rules in <m:Rules> tag in %s -- %s", template.templateName(), e));
} catch (Exception e) {
meta.endRuleSet().disableRules();
throw new AWGenericException(Fmt.S("Exception reading rules in <m:Rules> tag in %s", template.templateName()), e);
}
data.elementMap.put(this, meta.endRuleSet());
}
}