Hi Tariq,

On Feb 27, 2010, at 8:53 AM, webp...@tigris.org wrote:

> Hello Rhett,
>
> Thanks for the reply!
>
> What I would like to do is to create many "application" class  
> instances at runtime through some internal trigger...which can be  
> done using:
>
> attach(String pathTemplate, Restlet target)
>
> and to delete I use:
>
> detach(Restlet target)
>
> no problem here.
>
> but for resource class instances I can only route "applications" to  
> them using:
>
> attach(String pathTemplate, Class<?> targetClass)
>
> Meaning, I would have to use the same resource class instance for  
> all the "applications" that route to it.

I want to clarify something here, just in case: each request will be  
served by a separate resource instance.  You are correct that they  
will all be the same class, though.

> Although what I want to do is to have different "resource" instances  
> that differ in how they are initialized.

Okay, it sounds like you do need a custom Finder.  Internally, when  
you call attach(path, class), the base Router creates a Finder Restlet  
for that class and attaches it like any other Restlet.  You can change  
the kind of Finder used by overriding Router#createFinder.  Or you can  
provide your own custom attach methods in your Router subclass that do  
what you want.

(You can look at the Spring extension for examples of this --  
SpringBeanRouter and SpringBeanFinder.)

Rhett

>
> I hope I have illustrated this properly.
>
> Many thanks,
> Tariq
>
>> Hi Tariq,
>>
>> On Feb 26, 2010, at 5:33 AM, webp...@tigris.org wrote:
>>
>>> I would like to know why instances of "resource" classes cannot be
>>> dynamically created at runtime like the "application" class.
>>
>> Resources _are_ instantiated dynamically at runtime -- one instance
>> per request (assuming that the request gets routed to a Resource).
>> The Restlet which handles this instantiation is is the Finder.  You
>> can use a custom Router subclass to use a different Finder
>> implementation if the default behavior doesn't work for you.
>>
>> Can you give an example of what you're trying to do?
>>
>> Rhett
>>
>>> The idea is that I would like to initialize the resource class
>>> instance depending on different data that is acquired during
>>> runtime, and hence handle interactions differently.
>>>
>>> An alternative to this is to just handle the requests at the
>>> "application" without the use of the resource class. But I would
>>> like to use the resource class so that I could automatically
>>> generate WADLs using the respective extension class(es).
>>>
>>> Many thanks,
>>> Tariq
>>>
>>> ------------------------------------------------------
>>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2452502
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2452885

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2452920

Reply via email to