org.eclipse.actf.util.resources
Class EclipseResourceLocator

java.lang.Object
  extended by org.eclipse.actf.util.resources.DefaultResourceLocator
      extended by org.eclipse.actf.util.resources.EclipseResourceLocator
All Implemented Interfaces:
IResourceLocator

public class EclipseResourceLocator
extends DefaultResourceLocator

an implementation for locating resources within the Eclipse framework.

Author:
Field Summary
 
Fields inherited from interface org.eclipse.actf.util.resources.IResourceLocator
ACTF_RESOURCES_PATHS_KEY, DEFAULT_ACTF_RESOURCES_DIR
 
Constructor Summary
EclipseResourceLocator()
           
 
Method Summary
 String getPath(String name)
          find the Path with the given name. Note: You may also pass a bundle name to this method to obtain a bundle path
 String[] getPaths(String name)
          find the paths with the given name.
 IPath getPathToFile(String bundleName, String relativePath)
           
 URL getResource(String name)
          find the resource with the given name. Search Algorithm is: Search through the registered ClassLoaders for the resource Search through the registered Bundles for the resource Test if the name is actually a Bundle
 InputStream getResourceAsStream(String id, ClassLoader loader)
          get the resource corresponding to the given id as a stream using the specified class loader. Note that resources are located in the context of bundles in Eclipse.
 InputStream getResourceAsStream(String id, String base, String ext, ClassLoader loader)
          get the resource corresponding to the given id as a stream using the specified class loader.
 InputStream getResourceAsStream(String id, String base, String ext, String bundleName)
           
 void registerBundleName(String bundle)
          used to identify the bundles in which resources are to be found.
 
Methods inherited from class org.eclipse.actf.util.resources.DefaultResourceLocator
getResourceAsBufferedStream, getResourceAsBufferedStream, getResourceAsStream, getResources, makeBufferedStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EclipseResourceLocator

public EclipseResourceLocator()
Method Detail

registerBundleName

public void registerBundleName(String bundle)
used to identify the bundles in which resources are to be found. Each bundle in Eclipse has its own class loader and we leave it to the platform to choose the class loader to be used. Thus, calling this method means that a ClassLoader should not be passed to getResourceAsStream. Also, not all methods for finding resources in bundles use ClassLoader objects.

Parameters:
bundle - - the name of the bundle (i.e. plug-in) that is to be searched for a resource

getResourceAsStream

public InputStream getResourceAsStream(String id,
                                       ClassLoader loader)
get the resource corresponding to the given id as a stream using the specified class loader. Note that resources are located in the context of bundles in Eclipse.

Specified by:
getResourceAsStream in interface IResourceLocator
Overrides:
getResourceAsStream in class DefaultResourceLocator
Parameters:
id - - id of resource
loader - -- class loader to use
Returns:
input stream
See Also:
#setBundle(String)

getResourceAsStream

public InputStream getResourceAsStream(String id,
                                       String base,
                                       String ext,
                                       ClassLoader loader)
Description copied from class: DefaultResourceLocator
get the resource corresponding to the given id as a stream using the specified class loader. The base path and extention of the file resource are also specified.

Specified by:
getResourceAsStream in interface IResourceLocator
Overrides:
getResourceAsStream in class DefaultResourceLocator
Parameters:
id - - id of resource
base - - base path
ext - -extentio
loader - -- class loader to use
Returns:
input streamn

getResourceAsStream

public InputStream getResourceAsStream(String id,
                                       String base,
                                       String ext,
                                       String bundleName)

getResource

public URL getResource(String name)
find the resource with the given name. The name is a /-separated path describing the relative path to the resource.

Search Algorithm is:

  1. Search through the registered ClassLoaders for the resource
  2. Search through the registered Bundles for the resource
  3. Test if the name is actually a Bundle

Specified by:
getResource in interface IResourceLocator
Overrides:
getResource in class DefaultResourceLocator
Parameters:
name - - name of resource
Returns:
URL of a resource with the given name or null if no resources with the given name could be found
See Also:
ClassLoader.getResource(String)

getPath

public String getPath(String name)
find the Path with the given name. The name is a /-separated path describing the relative path to the resource. Note: You may also pass a bundle name to this method to obtain a bundle path

Specified by:
getPath in interface IResourceLocator
Overrides:
getPath in class DefaultResourceLocator
Parameters:
name - - name of resource
Returns:
String file representation of the URL returned from getResources or null if no resources with the given name could be found
See Also:
ClassLoader.getResource(String)

getPaths

public String[] getPaths(String name)
find the paths with the given name. The name is a /-separated path describing the relative path to the resource.

Specified by:
getPaths in interface IResourceLocator
Overrides:
getPaths in class DefaultResourceLocator
Parameters:
name - - name of resource
Returns:
String[] file representation of the URL[] returned from getResources or null if no resources with the given name could be found
See Also:
ClassLoader.getResources(String)

getPathToFile

public IPath getPathToFile(String bundleName,
                           String relativePath)