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 URL[] URL_ARRAY_MODEL
           
 
Constructor Summary
CommonResources()
           
 
Method Summary
static String[] getClassURLNamesFor(Object obj)
          get the names of places where a Class lies in the classPath
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 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
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

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


Copyright © 2013 LSST. All Rights Reserved.