fnug.resource
Class ResourceResolver

java.lang.Object
  extended by fnug.resource.ResourceResolver

public class ResourceResolver
extends Object

Entry point for resource resolving. Comprised of a number of Bundle that are created using Config.

Author:
Martin Algesten

Constructor Summary
protected ResourceResolver()
          Empty constructor for test cases.
  ResourceResolver(List<Resource> configResources)
          Constructs a resolver from the given list of resources pointing out config files.
 
Method Summary
 boolean checkModified()
          Checks if any of the config resources passed in the constructor is changed, in which case the resolver reinitialises all bundles.
 Bundle getBundle(String name)
          Returns the bundle for the given bundle name.
 List<Bundle> getBundles()
          Returns a list of all configured bundles.
 GlobalConfig getGlobalConfig()
          Returns the global config object.
static ResourceResolver getInstance()
          Returns the thread associated instance.
 long getLastModified()
          Returns the last modified date of all the configured bundles, see Bundle.getLastModified().
 Resource resolve(String path)
          Resolves the give path.
protected  void setConfigs(Config... configs)
          Sets the configs to use.
 void setThreadLocal()
          Must be called before using the ResourceResolver to bind this instance of the resolver to the currently executing thread.
protected static void setThreadLocal(ResourceResolver resolver)
          Sets the thread local instance to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceResolver

public ResourceResolver(List<Resource> configResources)
Constructs a resolver from the given list of resources pointing out config files. These files will be parsed into Config by a ConfigParser.

Parameters:
configResources - resources to configure from.

ResourceResolver

protected ResourceResolver()
Empty constructor for test cases.

Method Detail

setThreadLocal

public void setThreadLocal()
Must be called before using the ResourceResolver to bind this instance of the resolver to the currently executing thread.


setThreadLocal

protected static void setThreadLocal(ResourceResolver resolver)
Sets the thread local instance to use. Used for test cases.

Parameters:
resolver - Resolver to use.

getInstance

public static ResourceResolver getInstance()
Returns the thread associated instance.

Returns:
the thread associated instance.

setConfigs

protected void setConfigs(Config... configs)
Sets the configs to use. For test cases.

Parameters:
configs - configs to use.

resolve

public Resource resolve(String path)
Resolves the give path. This first attempts to resolve using just the bundle names themselves. I.e. a path such as /mybundle/myresource.js would be matched against a bundle named mybundle.

Parameters:
path - Path to match.
Returns:
The resolved resource, or null if no bundle will resolve.

getBundle

public Bundle getBundle(String name)
Returns the bundle for the given bundle name.

Parameters:
name - name of the bundle
Returns:
the bundle or null if not found.

getBundles

public List<Bundle> getBundles()
Returns a list of all configured bundles.

Returns:
the bundle that are configured.

getLastModified

public long getLastModified()
Returns the last modified date of all the configured bundles, see Bundle.getLastModified().

Returns:
the last modified date.

checkModified

public boolean checkModified()
Checks if any of the config resources passed in the constructor is changed, in which case the resolver reinitialises all bundles.

Returns:
true if any config was changed

getGlobalConfig

public GlobalConfig getGlobalConfig()
Returns the global config object.

Returns:
global config


Copyright © 2012. All Rights Reserved.