net.xoetrope.optional.resources
Class XProjectClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by net.xoetrope.optional.resources.XProjectClassLoader
All Implemented Interfaces:
XResourceLoader

public class XProjectClassLoader
extends java.lang.ClassLoader
implements XResourceLoader

Used to locate project files. This classloader is used in the XProject and is initialised when a project is created or opened. It searches for files within the paths specified in the paths array.

Copyright: Copyright (c) Xoetrope Ltd., 1998-2003

$Revision: 1.6 $


Field Summary
protected  java.lang.String basePath
           
protected  java.lang.String[] paths
           
protected  java.net.URL[] urls
           
 
Constructor Summary
XProjectClassLoader(java.lang.ClassLoader classLoader)
          Create a new class loader.
XProjectClassLoader(java.lang.ClassLoader classLoader, java.lang.String path)
          Create a new class loader.
 
Method Summary
 java.lang.Class findClass(java.lang.String className)
           
 java.lang.Class findClass(java.lang.String className, boolean resolveIt)
          Overrides the method from ClassLoader.
 java.net.URL findResource(java.lang.String fileName)
          Overrides the Classloader method and searches for the resource file specifies by the parameter fileName.
 java.net.URL getResource(java.lang.String fileName)
           
 java.io.InputStream getResourceAsStream(java.lang.String fileName)
          Overrides the Classloader method and searches for the resource file specifies by the parameter fileName.
 boolean setSources(java.lang.String[] projectPaths)
          Set the paths for loading files
 boolean setUrls(java.net.URL[] projectURLs)
          Set the urls for loading files
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResources, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

urls

protected java.net.URL[] urls

paths

protected java.lang.String[] paths

basePath

protected java.lang.String basePath
Constructor Detail

XProjectClassLoader

public XProjectClassLoader(java.lang.ClassLoader classLoader)
Create a new class loader. Initially no search path is set.

Parameters:
classLoader - the super ClassLoader

XProjectClassLoader

public XProjectClassLoader(java.lang.ClassLoader classLoader,
                           java.lang.String path)
Create a new class loader. Initially no search path is set.

Parameters:
classLoader - the super ClassLoader
path - the basic path prefix to search
Method Detail

setSources

public boolean setSources(java.lang.String[] projectPaths)
Set the paths for loading files

Specified by:
setSources in interface XResourceLoader
Parameters:
projectPaths - The String array of paths for inclusion in the search.
Returns:
true to indicate that the sources are setup, false to indicate some failure

setUrls

public boolean setUrls(java.net.URL[] projectURLs)
Set the urls for loading files

Parameters:
projectURLs - The URL array of paths for inclusion in the search.
Returns:
true to indicate that the sources are setup, false to indicate some failure

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String fileName)
Overrides the Classloader method and searches for the resource file specifies by the parameter fileName.

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Parameters:
fileName - The name of the file to be found.
Returns:
An InputStream created by from the filename if found or null if not found.

getResource

public final java.net.URL getResource(java.lang.String fileName)
Overrides:
getResource in class java.lang.ClassLoader

findResource

public java.net.URL findResource(java.lang.String fileName)
Overrides the Classloader method and searches for the resource file specifies by the parameter fileName.

Overrides:
findResource in class java.lang.ClassLoader
Parameters:
fileName - The name of the file to be found.
Returns:
A URL from the filename if found or null if not found.

findClass

public java.lang.Class findClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Overrides:
findClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

findClass

public java.lang.Class findClass(java.lang.String className,
                                 boolean resolveIt)
                          throws java.lang.ClassNotFoundException
Overrides the method from ClassLoader. This method is called auotmatically if the system classloader cannot find the class it is looking for. We then have the chance to find, load and return the class.

Parameters:
className - The name of the class we are being asked to find
resolveIt - Simply forward the value passed in
Returns:
The newly created Class
Throws:
java.lang.ClassNotFoundException