Hi Thierry,
I'm interested in this last post. Please move to this to different thread as
appropriate. thanks!
The question I have is, how do I detach restlets belonging on cloned route
dynamically.
Example:
.....
VirtualHost host = new VirtualHost(getContext());
....
host.attach("/ws/myApp", new MyApplication("someParameter));
host.attach("/ws/myApp", new MyApplication("another parameter));
.....
// some redirect implementation here in a round robin mode
.....
now I want do detach MyApplication with the parameter "someParameter" only.
TIA!
regards,
Johnny Depp
> Hello Martin and brother,
>
> this method looks for all routes defined on the router. In case a route
> points to the "target" Restlet, this route is removed.
> This method does not apply to such routes, because Resource is not a
> Restlet :
>
> router.attach("/items", ItemsResource.class);
>
> As a workaround, you can create your own router that implements this
> kind of method:
> public void detach(Class<?> targetClass) {
> for (int i = getRoutes().size() - 1; i >= 0; i--) {
> Restlet target = getRoutes().get(i).getNext();
> if (target != null &&
> Finder.class.isAssignableFrom(target.getClass())) {
> Finder finder = (Finder) target;
> if(finder.getTargetClass().equals(targetClass)){
> getRoutes().remove(i);
> }
> }
> }
>
> if (getDefaultRoute() != null) {
> Restlet target = getDefaultRoute().getNext();
> if (target != null &&
> Finder.class.isAssignableFrom(target.getClass())) {
> Finder finder = (Finder) target;
> if(finder.getTargetClass().equals(targetClass)){
> setDefaultRoute(null);
> }
> }
> }
> }
>
> Best regards,
> Thierry Boileau
>
>
> > Thanks for notification, it's valuable info for me. I have aother one
> > question, me and my brother try to use "detach(Restlet target)" method
> > defined for Route class (version 1.1). But can you send me a piece of
> > sample source code? I'm not able to realise what should be an argument of
> > detach method.
> >
> > for example:
> >
> > // Create a router Restlet that defines routes.
> > Router router = new Router(getContext());
> > // Defines a route for the resource "list of items"
> > router.attach("/items", ItemsResource.class);
> >
> > ..and now how will I say that I would like to remove "ItemsResource" class
> > as resource accessible under "/items" URI?
> >
> > Really thanks!! your help is unbelievable!
> >
> > ------------------------------------------------------
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2448803
> >
> >
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2593071