{
_loadingElement = loadingElement;
_loadingComponentModel = loadingElement.getComponentResources().getComponentModel();
String componentClassName = _loadingComponentModel.getComponentClassName();
ComponentTemplate template = _templateSource.getTemplate(_loadingComponentModel, _locale);
// When the template for a component is missing, we pretend it consists of just a RenderBody
// phase. Missing is not an error ... many component simply do not have a template.
if (template.isMissing())
{
_loadingElement.addToTemplate(newRenderBodyElement());
return;
}
// Pre-allocate ids to avoid later name collisions.
Logger logger = _loadingComponentModel.getLogger();
// Don't have a case-insensitive Set, so we'll make due with a Map
Map<String, Boolean> embeddedIds = newCaseInsensitiveMap();
for (String id : _loadingComponentModel.getEmbeddedComponentIds())
embeddedIds.put(id, true);
_idAllocator.clear();
for (String id : template.getComponentIds())
{
_idAllocator.allocateId(id);
embeddedIds.remove(id);
}
if (!embeddedIds.isEmpty())
logger.error(ServicesMessages.embeddedComponentsNotInTemplate(
embeddedIds.keySet(),
componentClassName));
_addAttributesAsComponentBindings = false;
// The outermost elements of the template belong in the loading component's template list,
// not its body list. This shunt allows everyone else to not have to make that decision,
// they can add to the "body" and (if there isn't an active component), the shunt will
// add the element to the component's template.
BodyPageElement shunt = new BodyPageElement()
{
public void addToBody(PageElement element)
{
_loadingElement.addToTemplate(element);
}
};
_bodyPageElementStack.push(shunt);
for (TemplateToken token : template.getTokens())
{
switch (token.getTokenType())
{
case TEXT:
text((TextToken) token);