org.wicketstuff.config
Class MatchingResources

java.lang.Object
  extended by org.wicketstuff.config.MatchingResources

public class MatchingResources
extends Object

Class to get matching resources - uses Spring's PathMatchingResourcePatternResolver.

Author:
Doug Donohoe
See Also:
PathMatchingResourcePatternResolver

Constructor Summary
MatchingResources(String sPattern)
          Initialize list of matching Resource as found by PathMatchingResourcePatternResolver.getResources(String).
 
Method Summary
 org.springframework.core.io.Resource[] getAllMatches()
          Get all matching resources
 URL[] getAllMatchesURL()
          Get all matching resources as URLs.
 List<Class<?>> getAnnotatedMatches(Class<? extends Annotation> annotation)
          Get all matching classes that are annotated with the given Annotation.
 List<Class<?>> getAnnotatedMatches(Class<? extends Annotation> annotation, boolean includeSubclasses)
          Get all matching classes that are annotated with the given Annotation.
 org.springframework.core.io.Resource getSingleRequiredResource()
          Get a single required matching resource.
 URL getSingleRequiredResourceURL()
          Similar to getSingleRequiredResource(), but returns result as an URL.
 org.springframework.core.io.Resource getSingleResource()
          Get a single matching resource.
 URL getSingleResourceURL()
          Similar to getSingleResource(), but returns result as an URL.
 URL getURL(org.springframework.core.io.Resource r)
          Get URL from resource.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MatchingResources

public MatchingResources(String sPattern)
Initialize list of matching Resource as found by PathMatchingResourcePatternResolver.getResources(String).

Parameters:
sPattern - the pattern to search for
See Also:
PathMatchingResourcePatternResolver
Method Detail

getAllMatches

public org.springframework.core.io.Resource[] getAllMatches()
Get all matching resources

Returns:
A Resource array of all matches. If no matches are found this is a zero-length array.

getAllMatchesURL

public URL[] getAllMatchesURL()
Get all matching resources as URLs.

Returns:
URL array detemined by calling getURL(Resource) on each resource.

getAnnotatedMatches

public List<Class<?>> getAnnotatedMatches(Class<? extends Annotation> annotation,
                                          boolean includeSubclasses)
Get all matching classes that are annotated with the given Annotation.

Parameters:
annotation - an annotation class
includeSubclasses - if true, this will also return classes whose superclass has the specified annotation
Returns:
List of all classes that have the given annotation. List is empty if non matches found.

getAnnotatedMatches

public List<Class<?>> getAnnotatedMatches(Class<? extends Annotation> annotation)
Get all matching classes that are annotated with the given Annotation. Note that this method only returns those classes that actually contain the annotation, and does not return classes whose superclass contains the annotation.

Parameters:
annotation - an annotation class
Returns:
List of all classes that have the given annotation. List is empty if non matches found.
See Also:
getAnnotatedMatches(Class, boolean)

getSingleResource

public org.springframework.core.io.Resource getSingleResource()
Get a single matching resource. Throws an exception if multiple are found. This is useful if you are expecting to find only one instance of an item on the classpath.

Returns:
The single matching Resource
Throws:
RuntimeException - if more than one Resource was found

getSingleResourceURL

public URL getSingleResourceURL()
Similar to getSingleResource(), but returns result as an URL.

Returns:
The single matching Resource as an URL
Throws:
RuntimeException - if more than one Resource was found

getSingleRequiredResource

public org.springframework.core.io.Resource getSingleRequiredResource()
Get a single required matching resource. Throws an exception if zero or multiple are found. This is useful if you are expecting to find one and only one instance of an item on the classpath.

Returns:
The single matching Resource
Throws:
RuntimeException - if zero or more than one Resource was found

getSingleRequiredResourceURL

public URL getSingleRequiredResourceURL()
Similar to getSingleRequiredResource(), but returns result as an URL.

Returns:
The single matching Resource as an URL
Throws:
RuntimeException - if zero or more than one Resource was found

getURL

public URL getURL(org.springframework.core.io.Resource r)
Get URL from resource.

Parameters:
r - a Resource
Returns:
its URL
Throws:
RuntimeException - if Resource.getURL() throws IOException

toString

public String toString()
Overrides:
toString in class Object
Returns:
string representing all matching resouces as URLs


Copyright © 2012. All Rights Reserved.