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=2448830

Reply via email to