public class ResourceFinder
extends java.lang.Object
Constructor and Description |
---|
ResourceFinder(java.lang.String path) |
ResourceFinder(java.lang.String path,
java.lang.ClassLoader classLoader) |
ResourceFinder(java.lang.String path,
java.lang.ClassLoader classLoader,
java.net.URL... urls) |
ResourceFinder(java.lang.String path,
java.net.URL... urls) |
ResourceFinder(java.net.URL... urls) |
Modifier and Type | Method and Description |
---|---|
java.net.URL |
find(java.lang.String uri) |
java.util.List<java.net.URL> |
findAll(java.lang.String uri) |
java.util.List<java.lang.Class> |
findAllClasses(java.lang.String uri)
Executes findAllStrings assuming the strings are
the names of a classes that should be loaded and returned.
|
java.util.List<java.lang.Class> |
findAllImplementations(java.lang.Class interfase)
Assumes the class specified points to a file in the classpath that contains
the name of a class that implements or is a subclass of the specfied class.
|
java.util.List<java.util.Properties> |
findAllProperties(java.lang.String uri)
Finds the corresponding resources and reads them in as a properties files
Any URL that cannot be read in as a properties file will cause an exception to be thrown.
|
java.util.List<java.lang.String> |
findAllStrings(java.lang.String uri)
Reads the contents of the found URLs as a list of
String 's and returns them. |
java.util.List<java.lang.Class> |
findAvailableClasses(java.lang.String uri)
Executes findAvailableStrings assuming the strings are
the names of a classes that should be loaded and returned.
|
java.util.List<java.lang.Class> |
findAvailableImplementations(java.lang.Class interfase)
Assumes the class specified points to a file in the classpath that contains
the name of a class that implements or is a subclass of the specfied class.
|
java.util.List<java.util.Properties> |
findAvailableProperties(java.lang.String uri)
Finds the corresponding resources and reads them in as a properties files
Any URL that cannot be read in as a properties file will be added to the
'resourcesNotLoaded' collection.
|
java.util.List<java.lang.String> |
findAvailableStrings(java.lang.String uri)
Reads the contents of the found URLs as a Strings and returns them.
|
java.lang.Class |
findClass(java.lang.String uri)
Executes
findString(String) assuming the contents URL found is the name of
a class that should be loaded and returned. |
java.lang.Class |
findImplementation(java.lang.Class interfase)
Assumes the class specified points to a file in the classpath that contains
the name of a class that implements or is a subclass of the specfied class.
|
java.util.Properties |
findProperties(java.lang.String uri)
Finds the corresponding resource and reads it in as a properties file
Example classpath:
META-INF/widget.properties
ResourceFinder finder = new ResourceFinder("META-INF/");
Properties widgetProps = finder.findProperties("widget.properties");
|
java.lang.String |
findString(java.lang.String uri)
Reads the contents of the URL as a
String 's and returns it. |
java.util.Map<java.lang.String,java.net.URL> |
getResourcesMap(java.lang.String uri) |
java.util.List<java.lang.String> |
getResourcesNotLoaded()
Returns a list of resources that could not be loaded in the last invoked findAvailable* or
mapAvailable* methods.
|
java.util.Map<java.lang.String,java.lang.Class> |
mapAllClasses(java.lang.String uri)
Executes mapAllStrings assuming the value of each entry in the
map is the name of a class that should be loaded.
|
java.util.Map<java.lang.String,java.lang.Class> |
mapAllImplementations(java.lang.Class interfase)
Assumes the class specified points to a directory in the classpath that holds files
containing the name of a class that implements or is a subclass of the specfied class.
|
java.util.Map<java.lang.String,java.util.Properties> |
mapAllProperties(java.lang.String uri)
Finds the corresponding resources and reads them in as a properties files
Any URL that cannot be read in as a properties file will cause an exception to be thrown.
|
java.util.Map<java.lang.String,java.lang.String> |
mapAllStrings(java.lang.String uri)
Reads the contents of all non-directory URLs immediately under the specified
location and returns them in a map keyed by the file name.
|
java.util.Map<java.lang.String,java.lang.Class> |
mapAvailableClasses(java.lang.String uri)
Executes mapAvailableStrings assuming the value of each entry in the
map is the name of a class that should be loaded.
|
java.util.Map<java.lang.String,java.lang.Class> |
mapAvailableImplementations(java.lang.Class interfase)
Assumes the class specified points to a directory in the classpath that holds files
containing the name of a class that implements or is a subclass of the specfied class.
|
java.util.Map<java.lang.String,java.util.Properties> |
mapAvailableProperties(java.lang.String uri)
Finds the corresponding resources and reads them in as a properties files
Any URL that cannot be read in as a properties file will be added to the
'resourcesNotLoaded' collection.
|
java.util.Map<java.lang.String,java.lang.String> |
mapAvailableStrings(java.lang.String uri)
Reads the contents of all non-directory URLs immediately under the specified
location and returns them in a map keyed by the file name.
|
public ResourceFinder(java.net.URL... urls)
public ResourceFinder(java.lang.String path)
public ResourceFinder(java.lang.String path, java.net.URL... urls)
public ResourceFinder(java.lang.String path, java.lang.ClassLoader classLoader)
public ResourceFinder(java.lang.String path, java.lang.ClassLoader classLoader, java.net.URL... urls)
public java.util.List<java.lang.String> getResourcesNotLoaded()
public java.net.URL find(java.lang.String uri) throws java.io.IOException
java.io.IOException
public java.util.List<java.net.URL> findAll(java.lang.String uri) throws java.io.IOException
java.io.IOException
public java.lang.String findString(java.lang.String uri) throws java.io.IOException
String
's and returns it.uri
- Stringjava.io.IOException
- if a resource pointed out by the uri param could not be findClassLoader.getResource(String)
public java.util.List<java.lang.String> findAllStrings(java.lang.String uri) throws java.io.IOException
String
's and returns them.uri
- Stringjava.io.IOException
- if any of the found URLs are unable to be read.public java.util.List<java.lang.String> findAvailableStrings(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Map<java.lang.String,java.lang.String> mapAllStrings(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if any of the urls cannot be readpublic java.util.Map<java.lang.String,java.lang.String> mapAvailableStrings(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.lang.Class findClass(java.lang.String uri) throws java.io.IOException, java.lang.ClassNotFoundException
findString(String)
assuming the contents URL found is the name of
a class that should be loaded and returned.uri
- Stringjava.io.IOException
java.lang.ClassNotFoundException
public java.util.List<java.lang.Class> findAllClasses(java.lang.String uri) throws java.io.IOException, java.lang.ClassNotFoundException
uri
- Stringjava.io.IOException
java.lang.ClassNotFoundException
public java.util.List<java.lang.Class> findAvailableClasses(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Map<java.lang.String,java.lang.Class> mapAllClasses(java.lang.String uri) throws java.io.IOException, java.lang.ClassNotFoundException
uri
- Stringjava.io.IOException
java.lang.ClassNotFoundException
public java.util.Map<java.lang.String,java.lang.Class> mapAvailableClasses(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.lang.Class findImplementation(java.lang.Class interfase) throws java.io.IOException, java.lang.ClassNotFoundException
interfase
- a superclass or interfacejava.io.IOException
- if the URL cannot be readjava.lang.ClassNotFoundException
- if the class found is not loadablejava.lang.ClassCastException
- if the class found is not assignable to the specified superclass or interfacepublic java.util.List<java.lang.Class> findAllImplementations(java.lang.Class interfase) throws java.io.IOException, java.lang.ClassNotFoundException
interfase
- a superclass or interfacejava.io.IOException
- if the URL cannot be readjava.lang.ClassNotFoundException
- if the class found is not loadablejava.lang.ClassCastException
- if the class found is not assignable to the specified superclass or interfacepublic java.util.List<java.lang.Class> findAvailableImplementations(java.lang.Class interfase) throws java.io.IOException
interfase
- a superclass or interfacejava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Map<java.lang.String,java.lang.Class> mapAllImplementations(java.lang.Class interfase) throws java.io.IOException, java.lang.ClassNotFoundException
interfase
- a superclass or interfacejava.io.IOException
- if the URL cannot be readjava.lang.ClassNotFoundException
- if the class found is not loadablejava.lang.ClassCastException
- if the class found is not assignable to the specified superclass or interfacepublic java.util.Map<java.lang.String,java.lang.Class> mapAvailableImplementations(java.lang.Class interfase) throws java.io.IOException
interfase
- a superclass or interfacejava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Properties findProperties(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if the URL cannot be read or is not in properties file formatpublic java.util.List<java.util.Properties> findAllProperties(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if the URL cannot be read or is not in properties file formatpublic java.util.List<java.util.Properties> findAvailableProperties(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Map<java.lang.String,java.util.Properties> mapAllProperties(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if the URL cannot be read or is not in properties file formatpublic java.util.Map<java.lang.String,java.util.Properties> mapAvailableProperties(java.lang.String uri) throws java.io.IOException
uri
- Stringjava.io.IOException
- if classLoader.getResources throws an exceptionpublic java.util.Map<java.lang.String,java.net.URL> getResourcesMap(java.lang.String uri) throws java.io.IOException
java.io.IOException