[kepler-dev] [Bug 4104] - Need resource manager to handle objects in the resources directories

bugzilla-daemon at ecoinformatics.org bugzilla-daemon at ecoinformatics.org
Fri May 22 13:25:48 PDT 2009


http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4104





------- Comment #1 from jones at nceas.ucsb.edu  2009-05-22 13:25 -------
In general I think this is a good idea.  But, I could also envision having a
number of general search paths for resources that the class works through, so
that even the relative paths need not necessarily be encoded in the Java code
for each calling class.  This would make it easy to find resources in common
subdiectories like resources/images, resource/configuration, and
resources/data.  For example, ResourceManager might have two methods like:

(1) ResourceManager.getResource(String module, String name)
    Searches the given module for a resource with the given name, where name
can be either a bare name, or a relative path.  If the name is a bare name,
then a predefined set of paths are searched in the attempt to locate the
resource, with precedence given to the first resource found.  Some
predetermined paths to be searched might include the root of the resources
directory, and then subdirs such as "images", "configuration", and "data".
Because 'name' can include arbitrary paths, users can create their own custom
subdirectories within 'resources' to facilitate module-specific resolution. 
Example custom names include "images/mymodule/splash.png" and "mymodule/data"

(2) ResourceManager.getResource(String name)
    Same as (1), except searches all modules in classpath order rather than
just one specific module. First match has precedence.

Here are some example calls of these functions:

File f = ResourceManager.getResource("about.png");
File f = ResourceManager.getResource("common", "about.png");
File f = ResourceManager.getResource("common", "images/about.png");
File f = ResourceManager.getResource("common",
"images/experimental/about.png");

File f = ResourceManager.getResource("mydata.csv");
File f = ResourceManager.getResource("common", "mydata.csv");
File f = ResourceManager.getResource("common", "data/mydata.csv");
File f = ResourceManager.getResource("mymodule", "mymodule/mydata.csv");

We will want to consider how to deal with these relative paths -- whether there
is an implied '/' in front of each path, or whether "/" is considered the top
of the resource directory structure.

We should also consider whether returning a File is the best thing, or maybe
instead an InputStream? Or as Chad indicated, maybe even specific resource
types like Image can have special methods that return the instantiated java
object.  In this case, we might have:

Image i = ResourceManager.getImageResource("about.png");


More information about the Kepler-dev mailing list