Package org.wicketstuff.config
Class MatchingResources
- java.lang.Object
-
- org.wicketstuff.config.MatchingResources
-
public class MatchingResources extends Object
Class to get matching resources - uses Spring'sPathMatchingResourcePatternResolver
.- Author:
- Doug Donohoe
- See Also:
PathMatchingResourcePatternResolver
-
-
Constructor Summary
Constructors Constructor Description MatchingResources(String sPattern)
Initialize list of matchingResource
as found byPathMatchingResourcePatternResolver.getResources(String)
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource[]
getAllMatches()
Get all matching resourcesURL[]
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.Resource
getSingleRequiredResource()
Get a single required matching resource.URL
getSingleRequiredResourceURL()
Similar togetSingleRequiredResource()
, but returns result as anURL
.Resource
getSingleResource()
Get a single matching resource.URL
getSingleResourceURL()
Similar togetSingleResource()
, but returns result as anURL
.URL
getURL(Resource r)
Get URL from resource.String
toString()
-
-
-
Constructor Detail
-
MatchingResources
public MatchingResources(String sPattern)
Initialize list of matchingResource
as found byPathMatchingResourcePatternResolver.getResources(String)
.- Parameters:
sPattern
- the pattern to search for- See Also:
PathMatchingResourcePatternResolver
-
-
Method Detail
-
getAllMatches
public 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 callinggetURL(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 classincludeSubclasses
- 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 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 oneResource
was found
-
getSingleResourceURL
public URL getSingleResourceURL()
Similar togetSingleResource()
, but returns result as anURL
.- Returns:
- The single matching
Resource
as anURL
- Throws:
RuntimeException
- if more than oneResource
was found
-
getSingleRequiredResource
public 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 oneResource
was found
-
getSingleRequiredResourceURL
public URL getSingleRequiredResourceURL()
Similar togetSingleRequiredResource()
, but returns result as anURL
.- Returns:
- The single matching
Resource
as anURL
- Throws:
RuntimeException
- if zero or more than oneResource
was found
-
getURL
public URL getURL(Resource r)
Get URL from resource.- Parameters:
r
- aResource
- Returns:
- its URL
- Throws:
RuntimeException
- ifResource.getURL()
throwsIOException
-
-