com.ibm.di.util
Class ResourceLocator

java.lang.Object
  extended by com.ibm.di.util.ResourceLocator

public class ResourceLocator
extends Object

A utility class for working with resources.

Note: This class is for internal usage only. Any dependency from the end-user will not be supported. Changes to this class will happen without a warning.

Since:
7.1

Constructor Summary
ResourceLocator()
           
 
Method Summary
static URL getResourceFromClassLoaderChain(String resource)
          This method looks for a resource using the ClassLoaders chain.
static URL getResourceURL(String resourceName)
          Finds a resource URL by its name.
static URL resolveLocalURL(URL resource)
          If we are inside an OSGi context the URL will not be a file but a bundleresource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLocator

public ResourceLocator()
Method Detail

getResourceURL

public static URL getResourceURL(String resourceName)
Finds a resource URL by its name. The lookup is made by using getResourceFromClassLoaderChain(String) method. If the name does not start with a leading slash and the resource was not found the first time another try will be made by prefixing the name with a forward slash. If the resource exists and an URL is obtained it is then resolved using the resolveLocalURL(URL) method.

Parameters:
resourceName - the name to look for.
Returns:
the URL of the resource.

getResourceFromClassLoaderChain

public static URL getResourceFromClassLoaderChain(String resource)
This method looks for a resource using the ClassLoaders chain. The first classloader that is asked is the context loader, then the loader that has loaded the ResourceLocator class and finally the system loader.

Parameters:
resource - the name of the resource to look for.
Returns:
the url to the resource or null if not found. The first classloader responding with non-null value is the winner and its response is returned.

resolveLocalURL

public static URL resolveLocalURL(URL resource)
If we are inside an OSGi context the URL will not be a file but a bundleresource. Use this method to convert that URL to a file. If the url is already a File or the OSGi context is not present this method will not perform anything and the provided URL will be returned. The access to the eclipse code is done through reflection so it is safe to include this code in non-osgi context.

Parameters:
resource - the URL to convert
Returns:
a connection to the jar file containing the passes resource.
Throws:
IOException - if there is a problem to connect to the jar file.