Jesse, The dependency on 1.5 is only there because we are using 1.5 ;-). Actually, I think it can be implented by returning an Object instead of a template. And instead of passing in the "Class<T> baseClass", it would change to passing in a "string" value of the classname and then create it that way. It might need an additional parameter of BaseClass.name. However, the name could be gotten after creating the instance of the class.
regards, Mark -----Original Message----- From: Jesse Kuhnert [mailto:[EMAIL PROTECTED] Sent: Thu 3/23/2006 1:16 PM To: Tapestry users Subject: Re: Dynamically creating components at runtime The only quick obvious thought is that if this is for 3.x you'll probably find a lot of tapestry users unable to move to jdk 1.5 just yet. On 3/23/06, Mark Stang <[EMAIL PROTECTED]> wrote: > > 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 > > > -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. http://opennotion.com