org.szegedi.spring.web.jsflow
Class ScriptStorage

java.lang.Object
  extended by org.szegedi.spring.web.jsflow.ScriptStorage
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.context.ResourceLoaderAware

public class ScriptStorage
extends java.lang.Object
implements org.springframework.context.ResourceLoaderAware, org.springframework.beans.factory.InitializingBean

A loader and in-memory storage for compiled flowscripts. It is sufficient (and recommended) to have exactly one script storage per application context. The storage will be used by all the flow controllers in the application context. The script storage is resource loader aware, and will use the resource loader it was made aware of for loading script source code.

Version:
$Id: ScriptStorage.java 97 2007-12-10 17:48:16Z szegedia $
Author:
Attila Szegedi

Constructor Summary
ScriptStorage()
           
 
Method Summary
 void afterPropertiesSet()
           
 PersistenceSupport getPersistenceSupport()
          Returns an object implementing support functionality for persistent flow state storage.
 void setContextFactory(org.mozilla.javascript.ContextFactory contextFactory)
          Sets the context factory used to run the library script.
 void setLibraryCustomizer(LibraryCustomizer libraryCustomizer)
          Sets a library customizer.
 void setLibraryScripts(java.util.List libraryScripts)
          Sets a list of library scripts.
 void setNoStaleCheckPeriod(long noStaleCheckPeriod)
          Sets the period in milliseconds during which a script resource will not be checked for staleness.
 void setPrefix(java.lang.String prefix)
          Sets the prefix prepended to the script name to form the full path and name of the resource that stores the script source code, i.e.
 void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
          Sets the resource loader for this storage.
 void setScriptCharacterEncoding(java.lang.String scriptCharacterEncoding)
          Sets the character encoding used to load scripts' source code.
 void setSecurityDomainFactory(SecurityDomainFactory securityDomainFactory)
          Sets a security domain factory for this script storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptStorage

public ScriptStorage()
Method Detail

setScriptCharacterEncoding

public void setScriptCharacterEncoding(java.lang.String scriptCharacterEncoding)
Sets the character encoding used to load scripts' source code. Defaults to the value of the system property file.encoding.

Parameters:
scriptCharacterEncoding -
Since:
1.2

setResourceLoader

public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
Sets the resource loader for this storage. The resource loader will be used to load script source code. As the class implements ResourceLoaderAware, this will usually be invoked by the Spring framework to set the application context as the resource loader.

Specified by:
setResourceLoader in interface org.springframework.context.ResourceLoaderAware

setPrefix

public void setPrefix(java.lang.String prefix)
Sets the prefix prepended to the script name to form the full path and name of the resource that stores the script source code, i.e. "scripts/".

Parameters:
prefix - the resource path prefix used for locating script source code resources. Defaults to "".

setNoStaleCheckPeriod

public void setNoStaleCheckPeriod(long noStaleCheckPeriod)
Sets the period in milliseconds during which a script resource will not be checked for staleness. Defaults to 10000, that is, if upon requesting a script its file's timestamp was checked in the last 10 seconds, then it won't be checked again. If it was checked earlier than 10 seconds though, then its timestamp will be checked and if it changed, the script will be reloaded. Setting it to nonzero improves performance, while setting it to a very large value effectively disables automatic script reloading.

Parameters:
noStaleCheckPeriod - the period in milliseconds during which one script file's timestamp is not rechecked.

setLibraryScripts

public void setLibraryScripts(java.util.List libraryScripts)
Sets a list of library scripts. These scripts will be executed in the context of the global "library" scope that is the prototype of all conversation scopes.

Parameters:
libraryScripts - the list of additional library scripts. Each element can be a string (will resolve to a path as per setResourceLoader(ResourceLoader) and setPrefix(String)), a Resource, or a Script.
Since:
1.2

setLibraryCustomizer

public void setLibraryCustomizer(LibraryCustomizer libraryCustomizer)
Sets a library customizer. A library customizer is an optional object that is given the chance to customize the global "library" scope that is the prototype of all conversation scopes. If you simply wish to execute further scripts that define globally available functions, you'd rather want to use setLibraryScripts(List), as that will also cause the functions defined in those scripts to be properly stubbed for serialization and other clustered replication mechanisms. The customizer is invoked after all library scripts have already been run.

Parameters:
libraryCustomizer -

setSecurityDomainFactory

public void setSecurityDomainFactory(SecurityDomainFactory securityDomainFactory)
Sets a security domain factory for this script storage. It can be used to associate Rhino security domain objects with scripts.

Parameters:
securityDomainFactory -

setContextFactory

public void setContextFactory(org.mozilla.javascript.ContextFactory contextFactory)
Sets the context factory used to run the library script. If none is set the global context factory ContextFactory.getGlobal() is used. If you are using a custom context factory in either FlowController or OpenContextInViewInterceptor, you might want to explicitly specify that factory here as well, although in majority of cases this is not necessary.

Parameters:
contextFactory -

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getPersistenceSupport

public PersistenceSupport getPersistenceSupport()
Returns an object implementing support functionality for persistent flow state storage. Not usable by client applications, this is meant to be used by the persistent flow state storage

Returns:
the persistence support object.