com.google.clearsilver.jsilver.resourceloader
Class CompositeResourceLoader

java.lang.Object
  extended by com.google.clearsilver.jsilver.resourceloader.CompositeResourceLoader
All Implemented Interfaces:
ResourceLoader

public class CompositeResourceLoader
extends Object
implements ResourceLoader

ResourceLoader composed of other ResourceLoaders. When a resource is loaded, it will search through each ResourceLoader until it finds something.

See Also:
ResourceLoader

Constructor Summary
CompositeResourceLoader(Iterable<ResourceLoader> loaders)
           
CompositeResourceLoader(ResourceLoader... loaders)
           
 
Method Summary
 void add(ResourceLoader loader)
           
 void close(Reader reader)
          Close the reader.
 Object getKey(String filename)
          We return the filename as the key of uniqueness as we assume that if this CompositeResourceLoader is in use, then there won't be another ResourceLoader that we are competing against.
 Object getResourceVersionId(String filename)
          Return the first non-null version identifier found among the ResourceLoaders, using the same search order as open(String).
 Reader open(String name)
          Open a resource.
 Reader openOrFail(String name)
          Open a resource or throw an exception if no such resource is found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeResourceLoader

public CompositeResourceLoader(Iterable<ResourceLoader> loaders)

CompositeResourceLoader

public CompositeResourceLoader(ResourceLoader... loaders)
Method Detail

add

public void add(ResourceLoader loader)

open

public Reader open(String name)
            throws IOException
Description copied from interface: ResourceLoader
Open a resource. If this resource is not found, null should be returned. The caller of this method is guaranteed to call ResourceLoader.close(Reader) when done with the reader.

Specified by:
open in interface ResourceLoader
Parameters:
name - the name of the resource
Returns:
Reader, or null if not found.
Throws:
IOException - if resource fails to open

openOrFail

public Reader openOrFail(String name)
                  throws JSilverTemplateNotFoundException,
                         IOException
Description copied from interface: ResourceLoader
Open a resource or throw an exception if no such resource is found. The caller of this method is guaranteed to call ResourceLoader.close(Reader) when done with the reader.

Specified by:
openOrFail in interface ResourceLoader
Parameters:
name - the name of the resource
Returns:
Reader, or null if not found.
Throws:
JSilverTemplateNotFoundException - if resource is not found
IOException - if resource fails to open

close

public void close(Reader reader)
           throws IOException
Description copied from interface: ResourceLoader
Close the reader. Allows ResourceLoader to perform any additional clean up.

Specified by:
close in interface ResourceLoader
Parameters:
reader - the reader to close
Throws:
IOException - if reader fasils to close

getKey

public Object getKey(String filename)
We return the filename as the key of uniqueness as we assume that if this CompositeResourceLoader is in use, then there won't be another ResourceLoader that we are competing against. If we did need to worry about it we would want to prepend the key from above.

Specified by:
getKey in interface ResourceLoader
Parameters:
filename - the name we want to identify
Returns:
unique identifier

getResourceVersionId

public Object getResourceVersionId(String filename)
Return the first non-null version identifier found among the ResourceLoaders, using the same search order as open(String).

Specified by:
getResourceVersionId in interface ResourceLoader
Parameters:
filename - the name of the resource to check for resources
Returns:
unique identifier for the current version of the resource or null if the resource cannot be found


Copyright © 2010-2012 Google. All Rights Reserved.