{
_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.
Log log = _loadingComponentModel.getLog();
Set<String> embeddedIds = CollectionFactory.newSet(_loadingComponentModel
.getEmbeddedComponentIds());
_idAllocator.clear();
for (String id : template.getComponentIds())
{
_idAllocator.allocateId(id);
embeddedIds.remove(id);
}
if (!embeddedIds.isEmpty())
log.error(ServicesMessages.embeddedComponentsNotInTemplate(
embeddedIds,
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);