Class ResourceLocator

  extended by

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.


Constructor Summary
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


public ResourceLocator()
Method Detail


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.

resourceName - the name to look for.
the URL of the resource.


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.

resource - the name of the resource to look for.
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.


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.

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