JTools

org.jtools.activate
Class CentralLoader

java.lang.Object
  extended by org.jtools.activate.CentralLoader

public class CentralLoader
extends Object

Provides managed classloading.


Field Summary
static int CENTRAL
          Specifies the ClassLoader set as CentralLoader.
static int CONTEXT
          Specifies the ClassLoader of the overgiven context.
static int CONTEXTCL
          Specifies the ClassLoader as the overgiven context.
static int CURRENT
          Specifies the ClassLoader of class CentralLoader.
static int[] DEFAULT_STRATEGY
          Default strategy.
static int SYSTEM
          Specifies the SystemClassLoader.
static int THREAD
          Specifies the ThreadContextClassLoader.
 
Constructor Summary
CentralLoader()
           
CentralLoader(int[] strategy)
           
 
Method Summary
static ClassLoader getClassLoader()
          gets the central classloader.
static ClassLoader getClassLoader(Object context)
          gets the central classloader.
static URL getResource(String name, Object context)
          gets a resource from the central classloader.
static InputStream getResourceAsStream(String name, Object context)
          gets a resource from the central classloader.
static Enumeration getResources(String name, Object context)
          get resources from the central classloader.
protected static CentralLoader getSingleton()
           
 int[] getStrategy()
           
static
<E> Class<E>
loadClass(String name, Object context)
          loads a class from the central classloader.
protected  ClassLoader onGetClassLoader()
           
protected  ClassLoader onGetClassLoader(int type, Object context)
           
protected  ClassLoader onGetClassLoader(Object context)
           
protected  URL onGetResource(String name, Object context)
           
protected  InputStream onGetResourceAsStream(String name, Object context)
           
protected  Enumeration onGetResources(String name, Object context)
           
protected
<E> Class<E>
onLoadClass(String name, Object context)
           
protected  ClassLoader onSetClassLoader(ClassLoader classloader)
           
static ClassLoader setClassLoader(ClassLoader classloader)
          sets a central classloader.
protected static CentralLoader setSingleton(CentralLoader classloader)
           
 void setStrategy(int[] strategy)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTRAL

public static final int CENTRAL
Specifies the ClassLoader set as CentralLoader.

See Also:
Constant Field Values

THREAD

public static final int THREAD
Specifies the ThreadContextClassLoader.

See Also:
Constant Field Values

CONTEXT

public static final int CONTEXT
Specifies the ClassLoader of the overgiven context.

See Also:
Constant Field Values

CURRENT

public static final int CURRENT
Specifies the ClassLoader of class CentralLoader.

See Also:
Constant Field Values

SYSTEM

public static final int SYSTEM
Specifies the SystemClassLoader.

See Also:
Constant Field Values

CONTEXTCL

public static final int CONTEXTCL
Specifies the ClassLoader as the overgiven context.

See Also:
Constant Field Values

DEFAULT_STRATEGY

public static final int[] DEFAULT_STRATEGY
Default strategy. It searches a classloader in the following order:
  1. the ClassLoader last set via CentralLoader.setClassLoader
  2. the ThreadContextClassLoader
  3. the ClassLoader that loaded the overgiven context
  4. the ClassLoader that loaded the class CentralLoader
  5. the SystemClassLoader
.

Constructor Detail

CentralLoader

public CentralLoader()

CentralLoader

public CentralLoader(int[] strategy)
Method Detail

getClassLoader

public static ClassLoader getClassLoader()
gets the central classloader.

Returns:
the central classloader or null if there is none.

getClassLoader

public static ClassLoader getClassLoader(Object context)
gets the central classloader.

Returns:
the central classloader if there is one or the classloader from context.

getResource

public static URL getResource(String name,
                              Object context)
gets a resource from the central classloader.

Returns:
the resource loaded.

getResourceAsStream

public static InputStream getResourceAsStream(String name,
                                              Object context)
gets a resource from the central classloader.

Returns:
the resource loaded.

getResources

public static Enumeration getResources(String name,
                                       Object context)
                                throws IOException
get resources from the central classloader.

Returns:
the available resources.
Throws:
IOException

getSingleton

protected static CentralLoader getSingleton()

loadClass

public static <E> Class<E> loadClass(String name,
                                     Object context)
                          throws ClassNotFoundException
loads a class from the central classloader.

Returns:
the class loaded.
Throws:
ClassNotFoundException

setClassLoader

public static ClassLoader setClassLoader(ClassLoader classloader)
sets a central classloader.

Returns:
the last central classloader ore none if there was none.

setSingleton

protected static CentralLoader setSingleton(CentralLoader classloader)

getStrategy

public int[] getStrategy()

setStrategy

public void setStrategy(int[] strategy)

onGetClassLoader

protected ClassLoader onGetClassLoader()

onGetClassLoader

protected ClassLoader onGetClassLoader(int type,
                                       Object context)

onGetClassLoader

protected ClassLoader onGetClassLoader(Object context)

onGetResource

protected URL onGetResource(String name,
                            Object context)

onGetResourceAsStream

protected InputStream onGetResourceAsStream(String name,
                                            Object context)

onGetResources

protected Enumeration onGetResources(String name,
                                     Object context)
                              throws IOException
Throws:
IOException

onLoadClass

protected <E> Class<E> onLoadClass(String name,
                                   Object context)
                        throws ClassNotFoundException
Throws:
ClassNotFoundException

onSetClassLoader

protected ClassLoader onSetClassLoader(ClassLoader classloader)

JTools

© 2000-2006, JTools.org.