org.lsst.ccs.utilities.jars
Class CommonResources

java.lang.Object
  extended by org.lsst.ccs.utilities.jars.CommonResources

public class CommonResources
extends Object

This class deals with "common resources": that is resources that are not linked to a specific package (such resources are often queried using an initial slash when querying a resource through the Class resource methods such as getResource : getResource("/global.properties")).

Beware: in the codeusing this class these resource names should not start with a slash (same protocol as with the ClassLoader resource methods.

The general idea is that when dealing with multiple jars there may be many "common resources" with the same name.
So:

Other utilities methods:

Author:
bamade

Field Summary
static Logger CURLOG
           
static URL[] URL_ARRAY_MODEL
           
 
Constructor Summary
CommonResources()
           
 
Method Summary
static Properties gatherAllPropertiesFrom(ClassLoader loader, String loaderResourceName)
          this method will create a Properties object filled with ALL the ".properties" resources and Files that happen to bear the same name in the ClassPath and in the current directory.
static Properties gatherAllPropertiesFrom(String loaderResourceName)
          same as the method with a ClassLoader argument but uses the current ClassLoader
static String[] getClassURLNamesFor(Object obj)
          get the names of places where a Class lies in the classPath
static InputStream getInput(Class clazz, String pathName)
          searches for a file as a local file or a resource linked to a class or a global resource.
static Manifest getManifestFor(Object obj)
          returns a Manifest for an object
static Properties getPropertiesFrom(URL url)
          fills a Property Object from an URL the references a file in ".properties" format
static Properties getPropertiesFromAny(String name)
           
static String getResourceContainer(URL url, String commonResourceName)
          gets the name of a jar that contains a "common resource"
static URL[] getURLsFor(Object obj, String commonResourceName)
          return the URL of a resource that lies in the same jar as a class.
static URL[] getURLsFrom(ClassLoader loader, String commonResourceName)
          As "seen" from a ClassLoader the various URLs that point to resources with a given name.
static URL[] getURLsFrom(String commonResourceName)
          As "seen" from the context ClassLoader the various URLs that point to resources with a given name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_ARRAY_MODEL

public static final URL[] URL_ARRAY_MODEL

CURLOG

public static final Logger CURLOG
Constructor Detail

CommonResources

public CommonResources()
Method Detail

getURLsFrom

public static URL[] getURLsFrom(ClassLoader loader,
                                String commonResourceName)
As "seen" from a ClassLoader the various URLs that point to resources with a given name. Normally these are ordered along the ClassPath order so if used for a hierarchical exploration the resulting array should be exploited backwards.

Parameters:
loader - a current ClassLoader
commonResourceName - name of resource (without initial slash!)
Returns:
an Array of URL that point to resources with that name

getURLsFrom

public static URL[] getURLsFrom(String commonResourceName)
As "seen" from the context ClassLoader the various URLs that point to resources with a given name

Parameters:
commonResourceName - name of resource (without initial slash!)
Returns:
an Array of URL that point to resources with that name

getURLsFor

public static URL[] getURLsFor(Object obj,
                               String commonResourceName)
return the URL of a resource that lies in the same jar as a class.

Parameters:
obj - any instance of a Class object if no instance is at hand
commonResourceName - name of resource (without initial slash!)
Returns:
an Array (with normally only one element)

getClassURLNamesFor

public static String[] getClassURLNamesFor(Object obj)
get the names of places where a Class lies in the classPath

Parameters:
obj - any object or Class
Returns:
mostly an array of size one

getPropertiesFrom

public static Properties getPropertiesFrom(URL url)
fills a Property Object from an URL the references a file in ".properties" format

Parameters:
url -
Returns:
a Properties object that may be empty if URL incorrect (or read error of the resource)

getResourceContainer

public static String getResourceContainer(URL url,
                                          String commonResourceName)
gets the name of a jar that contains a "common resource"

Parameters:
url -
commonResourceName - name of resource (without initial slash!)
Returns:
the name of a jar that "contains" the object referenced by the URL (can also be a directory)

getManifestFor

public static Manifest getManifestFor(Object obj)
returns a Manifest for an object

Parameters:
obj - an object instance or a Class
Returns:
a Manifest or null if not found

getInput

public static InputStream getInput(Class clazz,
                                   String pathName)
                            throws IOException
searches for a file as a local file or a resource linked to a class or a global resource.

Parameters:
clazz -
pathName -
Returns:
Throws:
IOException

getPropertiesFromAny

public static Properties getPropertiesFromAny(String name)
Parameters:
name -
Returns:

gatherAllPropertiesFrom

public static Properties gatherAllPropertiesFrom(ClassLoader loader,
                                                 String loaderResourceName)
this method will create a Properties object filled with ALL the ".properties" resources and Files that happen to bear the same name in the ClassPath and in the current directory. It uses a hierarchical reading of these files: any property which is in a file "before" the others in the current directory and in the classPath will "shadow" other values.

Parameters:
loader - ClassLoader
loaderResourceName - the name of the Resource according to ClassLoader conventions (this means that the usual ResourceName with Objects should not be used)
Returns:
a Properties object with content read from these various files

gatherAllPropertiesFrom

public static Properties gatherAllPropertiesFrom(String loaderResourceName)
same as the method with a ClassLoader argument but uses the current ClassLoader

Parameters:
loaderResourceName - file name or resource name that uses the ClassLoader resource naming convention
Returns:
a filled Properties object


Copyright © 2013 LSST. All Rights Reserved.