ch.elca.el4j.core.io.support
Class ListResourcePatternResolverDecorator

java.lang.Object
  extended by ch.elca.el4j.core.io.support.ListResourcePatternResolverDecorator
All Implemented Interfaces:
ResourceLoader, ResourcePatternResolver

public class ListResourcePatternResolverDecorator
extends Object
implements ResourcePatternResolver

This class resolves resources using a list of resource names to preserve a specific order. A request is delegated to another ResourcePatternResolver, if there are no resources found by this class. Hence the list of resource names does not have to be exhaustive.

Author:
Andreas Bur (ABU)
File-location:
ListResourcePatternResolverDecorator
Last check-in date:
2009-08-04 15:17:52 +0200 (Di, 04. Aug 2009) by swismer for revision 3880

Field Summary
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
 
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
 
Constructor Summary
ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider)
          Creates a new instance using a PathMatchingResourcePatternResolver to delegate unresolved requests to and an AntPathMatcher to interprete wildcard notations.
ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider, ResourcePatternResolver patternResovler)
          Creates a new instance using a AntPathMatcher to interprete wildcard notations.
ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider, ResourcePatternResolver patternResovler, PathMatcher pathMatcher)
          Creates a new instance, that is fully configured through constructor arguments.
 
Method Summary
protected  void debugArray(String msg, Object[] array)
          Debugs the given array.
protected  Resource delegateResourceLookup(String location)
          Resolves the given location into one resource, using delegation.
protected  Resource[] delegateResourcesLookup(String locationPattern)
          Resolves the given location into Resource objects, using delegation.
protected  Resource[] findAllClassPathResources(String location)
          Finds all resources that do not contain any wildcards except the classpath*.
protected  Resource[] findAllMatchingResources(String locationPattern)
          Finds all resources that match the given location pattern that is interpreted by the path matcher which this class is configured for.
protected  Resource findFirstClassPathResource(String location)
           
protected  Resource findLastClassPathResource(String location)
           
protected  Resource findSingleClassPathResource(String location)
           
 ClassLoader getClassLoader()
          
protected  PathMatcher getPathMatcher()
           
 ResourcePatternResolver getPatternResolver()
           
 Resource getResource(String location)
          
 Resource[] getResources(String locationPattern)
          
 boolean isMergeWithOuterResources()
           
 boolean isMostSpecificResourceLast()
           
protected  Resource[] mergeResources(Resource[] former, Resource[] latter)
          Merges the two given list of resources with the former having higher precedence, i.e. they are added to the resulting list's head.
 void setMergeWithOuterResources(boolean mergeWithOuterResources)
          Sets whether resources that are hold in this classe's resource list have to be merged with resources looked up in the file system.
 void setMostSpecificResourceLast(boolean mostSpecificResourceLast)
           
 void setPathMatcher(PathMatcher pathMathcher)
          Sets a specific path matcher that is used to interprete a specific wildcard notation.
 void setPatternResolver(ResourcePatternResolver patternResolver)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListResourcePatternResolverDecorator

public ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider)
Creates a new instance using a PathMatchingResourcePatternResolver to delegate unresolved requests to and an AntPathMatcher to interprete wildcard notations.

Parameters:
locationProvider - The configuration location provider to get the locations from.

ListResourcePatternResolverDecorator

public ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider,
                                            ResourcePatternResolver patternResovler)
Creates a new instance using a AntPathMatcher to interprete wildcard notations.

Parameters:
locationProvider - The configuration location provider to get the locations from.
patternResovler - The pattern resolver to delegate unresolved requests to.

ListResourcePatternResolverDecorator

public ListResourcePatternResolverDecorator(ConfigLocationProvider locationProvider,
                                            ResourcePatternResolver patternResovler,
                                            PathMatcher pathMatcher)
Creates a new instance, that is fully configured through constructor arguments.

Parameters:
locationProvider - The configuration location provider to use.
patternResovler - The pattern resolver to delegate unresolved requests to.
pathMatcher - The path matcher that interprets a specific wildcard notation.
Method Detail

getPatternResolver

public ResourcePatternResolver getPatternResolver()
Returns:
Returns the patternResolver.

setPatternResolver

public void setPatternResolver(ResourcePatternResolver patternResolver)
Parameters:
patternResolver - Is the patternResolver to set.

getPathMatcher

protected PathMatcher getPathMatcher()
Returns:
Returns the path matcher that is used to interprete a specific wildcard notation.

setPathMatcher

public void setPathMatcher(PathMatcher pathMathcher)
Sets a specific path matcher that is used to interprete a specific wildcard notation.

Parameters:
pathMathcher - The path matcher to set.

isMergeWithOuterResources

public boolean isMergeWithOuterResources()
Returns:
Returns whether to merge resources hold in this classe's resource list with resources looked up in the file system.

setMergeWithOuterResources

public void setMergeWithOuterResources(boolean mergeWithOuterResources)
Sets whether resources that are hold in this classe's resource list have to be merged with resources looked up in the file system. Resources that are in the list have precedence.

Parameters:
mergeWithOuterResources - true to merge file system resources with the ones hold in this classe's resource list. false to force closed-world assumption.

isMostSpecificResourceLast

public boolean isMostSpecificResourceLast()
Returns:
Returns the mostSpecificResourceLast.

setMostSpecificResourceLast

public void setMostSpecificResourceLast(boolean mostSpecificResourceLast)
Parameters:
mostSpecificResourceLast - Is the mostSpecificResourceLast to set.

getResource

public Resource getResource(String location)

Specified by:
getResource in interface ResourceLoader

getResources

public Resource[] getResources(String locationPattern)
                        throws IOException

Specified by:
getResources in interface ResourcePatternResolver
Throws:
IOException

delegateResourcesLookup

protected Resource[] delegateResourcesLookup(String locationPattern)
                                      throws IOException
Resolves the given location into Resource objects, using delegation.

Parameters:
locationPattern - The pattern to resolve.
Returns:
Returns the list with resolved resources.
Throws:
IOException - If an I/O error occurs.

delegateResourceLookup

protected Resource delegateResourceLookup(String location)
Resolves the given location into one resource, using delegation.

Parameters:
location - The location to resolve.
Returns:
Returns the resolved resource.

findAllMatchingResources

protected Resource[] findAllMatchingResources(String locationPattern)
Finds all resources that match the given location pattern that is interpreted by the path matcher which this class is configured for.

Parameters:
locationPattern - The location pattern to match against (contains a particular wildcard notation).
Returns:
Returns a list of resources that matches the given pattern.

findAllClassPathResources

protected Resource[] findAllClassPathResources(String location)
Finds all resources that do not contain any wildcards except the classpath*.

Parameters:
location - The location pattern to match resources against (without any particular wildcard notation).
Returns:
Returns a list of resources that match the given pattern.

findSingleClassPathResource

protected Resource findSingleClassPathResource(String location)
Parameters:
location - Is the looked up resource location.
Returns:
Returns only the first found class path resource.

findFirstClassPathResource

protected Resource findFirstClassPathResource(String location)
                                       throws IOException
Parameters:
location - Is the looked up resource location.
Returns:
Returns only the first found class path resource.
Throws:
IOException - On any io problem.

findLastClassPathResource

protected Resource findLastClassPathResource(String location)
                                      throws IOException
Parameters:
location - Is the looked up resource location.
Returns:
Returns only the last found class path resource. If flag mergeWithOuterResources is set to true this method will try to find a resource that is not in the config location list.
Throws:
IOException - On any io problem.

mergeResources

protected Resource[] mergeResources(Resource[] former,
                                    Resource[] latter)
                             throws IOException
Merges the two given list of resources with the former having higher precedence, i.e. they are added to the resulting list's head. Items of the latter list that are also member of the former are added only once.

Parameters:
former - A list of resources that has higher precedence.
latter - A list of resources that has lower precedence. Items that are already added by the former list are filtered.
Returns:
Returns a list with the merged resources, having the former list at the resulting list's head. Items of the latter list are ignored, if they are already added by the former list.
Throws:
IOException - If an I/O exception occurs.

debugArray

protected void debugArray(String msg,
                          Object[] array)
Debugs the given array.

Parameters:
msg - An arbitrary message prepended to the array.
array - The array to debug.

getClassLoader

public ClassLoader getClassLoader()

Specified by:
getClassLoader in interface ResourceLoader


Copyright © 2005-2011 ELCA. All Rights Reserved.