org.inxar.hotswap
Class ProxyClassLoader

java.lang.Object
  |
  +--org.inxar.hotswap.ProxyClassLoader

public class ProxyClassLoader
extends Object

The ProxyClassLoader acts as a factory of ProxyClass instances. It is the "top-level" object in the library. Note that the name of this class means "a thing that loads ProxyClass instances" and not "a thing that is a ClassLoader". This class does not extend java.lang.ClassLoader.

ProxyCompiler Usage
 ProxyClassLoader loader = new ProxyClassLoader();

 ProxyClass = loader.loadJDK12("org.myname.myproject.MyClass");
 ProxyClass = loader.load("org.myname.myproject.MyClass");
 

Since:
0.8.6

Constructor Summary
ProxyClassLoader()
           
ProxyClassLoader(String propertiesFileName)
           
 
Method Summary
 ClassLoader getDefaultParentClassLoader()
          Returns the default parent ClassLoader instance.
 ProxyCompiler getDefaultProxyCompiler()
          Returns the default ProxyCompiler instance.
 ProxyClass getJDK12(String className)
          Returns the ProxyClass having the given name or null if no such ProxyClass exists; if the given classname is a JDK13 ProxyClass, a ProxyRuntimeException will be thrown.
 ProxyClass getJDK13(String className)
          Returns the ProxyClass having the given name or null if no such ProxyClass exists; if the given classname is NOT a JDK13 ProxyClass, a ProxyRuntimeException will be thrown.
 Collection getLoadedClasses()
          Returns the Collection of ProxyClass instances in this compiler instance.
 ProxyLog getLog()
          Returns the ProxyLog or null if one has not been explicitly set.
 Properties getProperties()
          Returns the configuration Properties object.
 String getVersion()
          Returns the version number for this release.
 boolean hasLog()
          Returns true if there is a non-null log instance, false otherwise.
 ProxyClass load(String className)
          JDK1.3 Factory method; Convenience method that uses the published list of interfaces on the Class object.
 ProxyClass load(String className, Class[] interfaces)
          JDK1.3 Factory method; Creates a new ProxyClass for the given className that will use the JDK1.3 dynamic proxy class mechanism.
 ProxyClass loadJDK12(String className)
          JDK1.2 Factory method; Creates a new ProxyClass for the given className.
 ProxyClass remove(ProxyClass cls)
          Removes the given ProxyClass instance from this cache and returns the cached instance or null if no such ProxyClass exists in this cache.
 void setDefaultParentClassLoader(ClassLoader parent)
          Sets the default parent ClassLoader instance.
 void setDefaultProxyCompiler(ProxyCompiler compiler)
          Sets the default parent ProxyCompiler instance.
 void setLog(ProxyLog master)
          Sets the ProxyLog for this ProxyClassLoader and her daughter ProxyClass instances.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyClassLoader

public ProxyClassLoader()
                 throws ProxyException

ProxyClassLoader

public ProxyClassLoader(String propertiesFileName)
                 throws ProxyException
Method Detail

getVersion

public String getVersion()
Returns the version number for this release.

setLog

public void setLog(ProxyLog master)
Sets the ProxyLog for this ProxyClassLoader and her daughter ProxyClass instances. Pass an instance that implements the ProxyLog interface to hook HotSwap into the logging system in your application.

getLog

public ProxyLog getLog()
Returns the ProxyLog or null if one has not been explicitly set.

hasLog

public boolean hasLog()
Returns true if there is a non-null log instance, false otherwise.

getDefaultParentClassLoader

public ClassLoader getDefaultParentClassLoader()
Returns the default parent ClassLoader instance.

setDefaultParentClassLoader

public void setDefaultParentClassLoader(ClassLoader parent)
Sets the default parent ClassLoader instance.

getDefaultProxyCompiler

public ProxyCompiler getDefaultProxyCompiler()
Returns the default ProxyCompiler instance.

setDefaultProxyCompiler

public void setDefaultProxyCompiler(ProxyCompiler compiler)
Sets the default parent ProxyCompiler instance.

getProperties

public Properties getProperties()
Returns the configuration Properties object.

getLoadedClasses

public Collection getLoadedClasses()
Returns the Collection of ProxyClass instances in this compiler instance.

loadJDK12

public ProxyClass loadJDK12(String className)
JDK1.2 Factory method; Creates a new ProxyClass for the given className. If a ProxyClass having the given name already exists it will be returned instead. This is in contrast to the load methods in this class that use dynamic proxy classes.

load

public ProxyClass load(String className,
                       Class[] interfaces)
JDK1.3 Factory method; Creates a new ProxyClass for the given className that will use the JDK1.3 dynamic proxy class mechanism. The ProxyClass will be a factory for Proxy instances having the given interfaces IN ADDITION TO the Proxy interface. If a ProxyClass having the given name already exists it will be returned instead.

If this method is chosen to construct the ProxyClass, new Proxy instances will be assignable to the given interfaces. Therefore, not only will the return argument of proxyClass.newProxy() be assignable to class Proxy, it will also be assignable to Foo. Therefore, the following idiom works:

Dynamic Proxy Class Programming Idiom
 Foo foo = (Foo)loader.load("FooImpl").newInstance();
 

This Foo instance will transparently monitor implementation changes and hotswap itself behind the scenes as necessary.


load

public ProxyClass load(String className)
JDK1.3 Factory method; Convenience method that uses the published list of interfaces on the Class object. This is equivalent to load(className, Class.forName(className).getInterfaces()).

remove

public ProxyClass remove(ProxyClass cls)
Removes the given ProxyClass instance from this cache and returns the cached instance or null if no such ProxyClass exists in this cache.

getJDK13

public ProxyClass getJDK13(String className)
Returns the ProxyClass having the given name or null if no such ProxyClass exists; if the given classname is NOT a JDK13 ProxyClass, a ProxyRuntimeException will be thrown.

getJDK12

public ProxyClass getJDK12(String className)
Returns the ProxyClass having the given name or null if no such ProxyClass exists; if the given classname is a JDK13 ProxyClass, a ProxyRuntimeException will be thrown.