On May 18, 2009, at 7:11 PM, Fabio Mancinelli wrote:
On May 18, 2009, at 6:52 PM, Vincent Massol wrote:
Great but why do you need the FQN as role hint?
Since you lookup all components implementing the XWikiRestComponent role you have access to all FQN.
At registration time, I have to tell Restlet/JAXRS what are the java.lang.Classes that implement JAXRS entities. So, at startup, I basically do this for registering components once for all:
List<XWikiRestComponent> components = componentManager.lookupList(XWikiRestComponent.class); for (XWikiRestComponent component : components) { jaxRsClassed.add(component.getClass()) }
BTW you can get the list injected automatically with: @Requirement(role = XWikiRestComponent.class) List<XWikiRestComponent> components; Note that obviously this means no hot deploy. For that you need to wait for CM events that I plan to add soon.
During normal operation, Restlet/JAXRS starts calling the object factory through the method
public <T> T getInstance(Class<T> clazz) throws InstantiateException
whenever it needs an instance of a given class.
So, in order to lookup a component, I just have the class name to be used as a way for identifying it. What I do is:
componentManager.lookup(XWikiRestComponent.class, clazz.getName());
That's the reason why the hint if the FQN of the class.
If I don't use the FQN I would have to create a mapping class-
symbolic name (hint) at startup using the lookupMap method. Doable but more complicated, so I just delegated the responsibility to the programmer to declare things in the right way :)
hmm so there's still something not quite right since we have several instances of the same component instantiated in the system: the ones from: List<XWikiRestComponent> components = componentManager.lookupList(XWikiRestComponent.class); and the ones from public <T> T getInstance(Class<T> clazz) throws InstantiateException In the first case all you need is actually the class name and not the object, right? Thanks -Vincent