org.sapia.resource
Class ResourceHandlerChain

java.lang.Object
  extended by org.sapia.resource.ResourceHandlerChain
All Implemented Interfaces:
ResourceCapable

public class ResourceHandlerChain
extends java.lang.Object
implements ResourceCapable

This class implements a chain of responsibility: an instance of this class holds a list of ResourceHandler instances. The instances are traversed when client application request a specific handler, given a URI.

Author:
Yanick Duchesne

Constructor Summary
ResourceHandlerChain()
           
 
Method Summary
 void append(ResourceHandler handler)
          Adds a resource handler to the end of the list that this instance holds.
protected  ResourceHandler doSelect(java.lang.String uri)
           
 void prepend(ResourceHandler handler)
          Adds a resource handler to the beginning of the list that this instance holds.
 Resource resolveResource(java.lang.String uri)
           
 ResourceHandler select(java.lang.String uri)
          Selects a ResourceHandler from this instance and returns it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceHandlerChain

public ResourceHandlerChain()
Method Detail

prepend

public void prepend(ResourceHandler handler)
Adds a resource handler to the beginning of the list that this instance holds.

Parameters:
handler - a ResourceHandler.

append

public void append(ResourceHandler handler)
Adds a resource handler to the end of the list that this instance holds.

Parameters:
handler - a ResourceHandler.

resolveResource

public Resource resolveResource(java.lang.String uri)
                         throws ResourceNotFoundException,
                                java.io.IOException
Specified by:
resolveResource in interface ResourceCapable
Throws:
ResourceNotFoundException
java.io.IOException

select

public ResourceHandler select(java.lang.String uri)
Selects a ResourceHandler from this instance and returns it. The handler is chose based on the given URI.

This instance traverses its handlers, calling the accepts() method on them (the method takes the given URI as a parameter). The first handler that "accepts" the URI (by returning true) is returned to the caller. If no handler as accepted the URI, null is returned.

Parameters:
uri - a URI.
Returns:
a ResourceHandler , or null if no handler could be found for the given URI.

doSelect

protected ResourceHandler doSelect(java.lang.String uri)


Copyright © 2011 Sapia OSS. All Rights Reserved.