All,
This is a 3.x mechanism for dynamically creating components at runtime. I am
posting it for two reasons, one is to provide a mechanism for other developers.
The second is so that people can review the implementation and point out any
"concerns".
@SuppressWarnings("unchecked")
private <T> T newComponent(String componentName, Class<T> baseClass,
IRequestCycle cycle)
{
ComponentSpecificationResolver resolver = new
ComponentSpecificationResolver(cycle);
resolver.resolve(cycle, cycle.getPage().getNamespace(), null,
componentName, null);
IComponentSpecification spec = resolver.getSpecification();
IEngine engine = cycle.getEngine();
Class c
=engine.getComponentClassEnhancer().getEnhancedClass(spec,baseClass.getName());
try
{
IComponent result = (IComponent)c.newInstance();
result.setSpecification(spec);
result.setPage(cycle.getPage());
result.setContainer(this);
return (T)result;
}
catch (Exception e)
{
// Toss any instantiation exceptions up the stack; there's nothing
to be done
throw new RuntimeException(e);
}
}
Thoughts?
thanks,
Mark