in tapestry-framework/src/org/apache/tapestry/bean/BeanProvider.java [138:189]
public Object getBean(String name)
{
Object bean = null;
if (_beans != null)
bean = _beans.get(name);
if (bean != null)
return bean;
IBeanSpecification spec = _component.getSpecification().getBeanSpecification(name);
if (spec == null)
throw new ApplicationRuntimeException(
Tapestry.format(
"BeanProvider.bean-not-defined",
_component.getExtendedId(),
name));
bean = instantiateBean(name, spec);
BeanLifecycle lifecycle = spec.getLifecycle();
if (lifecycle == BeanLifecycle.NONE)
return bean;
if (_beans == null)
_beans = new HashMap();
_beans.put(name, bean);
// The first time in a request that a REQUEST lifecycle bean is created,
// register with the page to be notified at the end of the
// request cycle.
if (lifecycle == BeanLifecycle.REQUEST && !_registeredForDetach)
{
_component.getPage().addPageDetachListener(this);
_registeredForDetach = true;
}
if (lifecycle == BeanLifecycle.RENDER && !_registeredForRender)
{
_component.getPage().addPageRenderListener(this);
_registeredForRender = true;
}
// No need to register if a PAGE lifecycle bean; those can stick around
// forever.
return bean;
}