com.gridsystems.launcher
Class CLBuilder

java.lang.Object
  extended by com.gridsystems.launcher.CLBuilder

public class CLBuilder
extends java.lang.Object

Builds an URLClassLoader with a "dynamically" constructed classpath.

IMPORTANT: Do not use classes from external libraries here, as they will probably not be in the classpath.

Version:
1.0
Author:
Rodrigo Ruiz

Constructor Summary
CLBuilder()
          Creates a new instance with null parent class loader.
CLBuilder(java.lang.ClassLoader parent)
          Creates a new instance with the specified class loader.
 
Method Summary
 void addClassPath(java.lang.ClassLoader cl)
          Adds the classpath of the specified classloader instance.
 void addContextClassPath()
          Adds the classpath of the current context classloader.
 void addDir(java.io.File dir)
          Adds the specified directory to the classpath.
 void addFile(java.io.File f)
          Adds the specified file to the classpath.
 void addJars(java.io.File f, boolean recursive)
          Adds all jar files in the specified directory to the classpath.
 void addUrl(java.net.URL url)
          Adds a single URL to the path set.
 void addWar(java.io.File f)
          Adds a war to the classpath.
 void addWebApp(java.io.File f)
          Adds WEB-INF/classes and WEB-INF/lib/*.jar to the classpath.
 java.lang.ClassLoader getClassLoader()
          Constructs a classloader with the current classpath.
 java.lang.Object invoke(java.lang.String clazz, java.lang.String method, java.lang.Class[] types, java.lang.Object[] args)
          Invokes the specified method within the context of the currently built classloader.
 void setParent(java.lang.ClassLoader parent)
          Sets the parent classloader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLBuilder

public CLBuilder()
Creates a new instance with null parent class loader.


CLBuilder

public CLBuilder(java.lang.ClassLoader parent)
Creates a new instance with the specified class loader.

Parameters:
parent - The parent classloader for the generated one
Method Detail

setParent

public void setParent(java.lang.ClassLoader parent)
Sets the parent classloader.

Parameters:
parent - The new parent classloader

addClassPath

public void addClassPath(java.lang.ClassLoader cl)
Adds the classpath of the specified classloader instance.

Parameters:
cl - The classloader whose classpath we want to obtain

addContextClassPath

public void addContextClassPath()
Adds the classpath of the current context classloader.


addDir

public void addDir(java.io.File dir)
Adds the specified directory to the classpath.

Parameters:
dir - The directory to add

addFile

public void addFile(java.io.File f)
Adds the specified file to the classpath. Currently, only jar files are admitted.

Parameters:
f - The file to add

addJars

public void addJars(java.io.File f,
                    boolean recursive)
Adds all jar files in the specified directory to the classpath. If recursive is true, jar files in subdirectories are also added.

Parameters:
f - The directory containing the jars to add
recursive - flag indicating if subdirectories must be scanned too

addUrl

public void addUrl(java.net.URL url)
Adds a single URL to the path set. All other "add" methods are based on this one.

Parameters:
url - The URL to add

addWebApp

public void addWebApp(java.io.File f)
Adds WEB-INF/classes and WEB-INF/lib/*.jar to the classpath.

Parameters:
f - The webapp context directory

addWar

public void addWar(java.io.File f)
Adds a war to the classpath.

Parameters:
f - The war file

getClassLoader

public java.lang.ClassLoader getClassLoader()
Constructs a classloader with the current classpath.

Returns:
An URLClassLoader instance with the current path set as its classpath

invoke

public java.lang.Object invoke(java.lang.String clazz,
                               java.lang.String method,
                               java.lang.Class[] types,
                               java.lang.Object[] args)
                        throws java.lang.Exception
Invokes the specified method within the context of the currently built classloader.

If the method is not static, it will attempt to create a new instance before invoking it.

Parameters:
clazz - The class name
method - The method name.
types - The argument types list
args - The arguments list
Returns:
The method invocation returned object
Throws:
java.lang.Exception - In case of any reflection error


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.