org.roscopeco.janno.actions.script
Class CachingScriptActionLoader

java.lang.Object
  extended by org.roscopeco.janno.actions.script.CachingScriptActionLoader
All Implemented Interfaces:
ActionClassLoader
Direct Known Subclasses:
GroovyActionLoader

public abstract class CachingScriptActionLoader
extends Object
implements ActionClassLoader

Abstract ActionClassLoader implementation that compiles action classes from an implementation-specific scripting language, and maintains an internal Class cache keyed on the script URL and validated by the last-modified attribute.

A specific script language can be supported with full cache capability simply by subclassing this class and providing an appropriate implementation of the loadScriptClass(URLConnection) method. The resulting class will be a fully-compatible ActionClassLoader implementation that can be used simply by registering it in the context container.

Version:
$Revision: 1.1 $ $Date: 2005/08/27 20:37:38 $
Author:
Ross Bamford (rosco<at>roscopeco.co.uk)

Constructor Summary
protected CachingScriptActionLoader(ClassLoader parentLoader)
          Create a new CachingScriptActionLoader that will use the specified ClassLoader as it's parent.
 
Method Summary
 Class getActionClass(URL script)
          Attempts to load an action class from the specified script URL.

This implementation caches the action classes internally, using the last-modified attribute of the script URL to determine whether it should be recompiled.

protected abstract  Class loadScriptClass(URLConnection conn)
          Loads and compiles a script from the specified URLConnection.
protected  ClassLoader parentLoader()
          Returns the parent classloader assigned to this action loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingScriptActionLoader

protected CachingScriptActionLoader(ClassLoader parentLoader)
Create a new CachingScriptActionLoader that will use the specified ClassLoader as it's parent.

Parameters:
parentLoader - Parent classloader to use. This must not be null.
Method Detail

getActionClass

public Class getActionClass(URL script)
                     throws IOException,
                            ScriptException
Attempts to load an action class from the specified script URL. Implementations will take whatever steps are necessary to compile the action (if valid) and return a compiled Java class.

This implementation caches the action classes internally, using the last-modified attribute of the script URL to determine whether it should be recompiled. The classes themselves are loaded by the protected loadScriptClass(URLConnection) method.

Specified by:
getActionClass in interface ActionClassLoader
Parameters:
script - A URL pointing to the script
Returns:
The compiled class for the script
Throws:
IOException - if an error occurs while retrieving or processing data from the URL.
ScriptException - if an error occurs during compilation.

parentLoader

protected ClassLoader parentLoader()
Returns the parent classloader assigned to this action loader.

Returns:
The parent loader.

loadScriptClass

protected abstract Class loadScriptClass(URLConnection conn)
                                  throws IOException,
                                         ScriptException
Loads and compiles a script from the specified URLConnection. This method is implemented by language specific caching loader implementations, and called only when the URL is not cached or has changed. It should simply compile the class as necessary and return it.

Parameters:
conn - The URLConnection to load the script from.
Returns:
The Class compiled from the script.
Throws:
IOException - if an error occurs while reading from the connection.
ScriptException - if there is a problem with the script itself.


Copyright © 2005 Roscopeco Open Technologies. All Rights Reserved.