|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsleep.runtime.ScriptLoader
The ScriptLoader is a convienence container for instantiating and managing ScriptInstances.
To load a script from a file and run it:
ScriptLoader loader = new ScriptLoader(); ScriptInstance script = loader.loadScript("script.sl"); script.runScript();The above will load the file script.sl and then execute it immediately.
Installation of loadable bridges you create can also be managed by the ScriptLoader.
A loadable bridge is installed into the language by adding it to a script loader class. There are two types of bridges. The two types are specific and global bridges.
The load and unload methods for a specific bridge are executed for every script load and unload, no matter what.
A global bridge is installed once for each script environment. If scripts are sharing an environment there is no sense in loading stuff into the environment more than once. This is why global bridges exist.
An example of adding a loadable bridge to a script loader:
ScriptLoader loader = new ScriptLoader() loader.addSpecificBridge(new MyLoadableBridge());
Loadable
,
ScriptInstance
Field Summary | |
protected static HashMap |
BLOCK_CACHE
cache for parsed scripts mantained (optionally) by the script loader. |
protected LinkedList |
bridgesg
global bridges |
protected LinkedList |
bridgess
specific bridges |
protected boolean |
disableConversions
|
protected LinkedList |
loadedScripts
loaded scripts |
protected HashMap |
scripts
loaded scripts except referable by key |
Constructor Summary | |
ScriptLoader()
initializes the script loader |
Method Summary | |
void |
addGlobalBridge(Loadable l)
A global bridge is loaded into an environment once and only once. |
void |
addSpecificBridge(Loadable l)
A specific bridge is loaded into *every* script regardless of wether or not the environment is shared. |
ScriptEnvironment |
getFirstScriptEnvironment()
Convienence method to return the script environment of the first script tht was loaded, returns null if no scripts are loaded |
LinkedList |
getScripts()
Returns a linked list of all loaded ScriptInstance objects |
HashMap |
getScriptsByKey()
Returns a HashMap with all loaded scripts, the key is a string which is just the filename, the value is a ScriptInstance object |
Set |
getScriptsToLoad(Set configured)
A convienence method to determine the set of scripts to "load" based on a passed in set of scripts that are currently configured. |
Set |
getScriptsToUnload(Set configured)
A convienence method to determine the set of scripts to "unload" based on a passed in set of scripts that are currently configured. |
protected void |
initDefaultBridges()
method call to initialize the default bridges, if you want to change the default bridges subclass this class and override this method |
ScriptInstance |
loadScript(File file)
Loads the specified script file |
ScriptInstance |
loadScript(File file,
Hashtable env)
Loads the specified script file, uses the specified hashtable for the environment |
ScriptInstance |
loadScript(String fileName)
Loads the specified script file |
ScriptInstance |
loadScript(String name,
Block code,
Hashtable env)
|
ScriptInstance |
loadScript(String fileName,
Hashtable env)
Loads the specified script file, uses the specified hashtable for the environment |
ScriptInstance |
loadScript(String name,
InputStream stream)
|
ScriptInstance |
loadScript(String name,
InputStream stream,
Hashtable env)
|
ScriptInstance |
loadScript(String name,
String code,
Hashtable env)
|
ScriptInstance |
loadSerialized(File script,
Hashtable env)
Load a serialized version of the script iff a serialized version exists, and its modification time is greater than the modification time of the script. |
ScriptInstance |
loadSerialized(String name,
InputStream stream,
Hashtable env)
Loads a serialized script from the specified input stream with the specified name |
static void |
saveSerialized(ScriptInstance si)
Saves a serialized version of the compiled script to scriptname.bin. |
static void |
saveSerialized(ScriptInstance si,
OutputStream stream)
Saves a serialized version of the ScriptInstance si to the specified output stream |
void |
setCharsetConversion(boolean b)
Java by default maps characters from an 8bit ascii file to an internal 32bit unicode representation. |
HashMap |
setGlobalCache(boolean setting)
The Sleep script loader can optionally cache parsed script files once they are loaded. |
void |
unloadScript(ScriptInstance script)
unload a script |
void |
unloadScript(String filename)
unload a script |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static HashMap BLOCK_CACHE
protected LinkedList loadedScripts
protected HashMap scripts
protected LinkedList bridgesg
protected LinkedList bridgess
protected boolean disableConversions
Constructor Detail |
public ScriptLoader()
Method Detail |
public HashMap setGlobalCache(boolean setting)
protected void initDefaultBridges()
public void addGlobalBridge(Loadable l)
public void addSpecificBridge(Loadable l)
public HashMap getScriptsByKey()
public ScriptEnvironment getFirstScriptEnvironment()
public LinkedList getScripts()
public ScriptInstance loadSerialized(File script, Hashtable env) throws IOException, ClassNotFoundException
script
- a file object pointing to the script file...
IOException
ClassNotFoundException
public ScriptInstance loadSerialized(String name, InputStream stream, Hashtable env) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
public static void saveSerialized(ScriptInstance si) throws IOException
IOException
public static void saveSerialized(ScriptInstance si, OutputStream stream) throws IOException
IOException
public ScriptInstance loadScript(String name, Block code, Hashtable env)
public ScriptInstance loadScript(String name, String code, Hashtable env) throws YourCodeSucksException
YourCodeSucksException
public ScriptInstance loadScript(String name, InputStream stream) throws YourCodeSucksException, IOException
YourCodeSucksException
IOException
public ScriptInstance loadScript(String name, InputStream stream, Hashtable env) throws YourCodeSucksException, IOException
YourCodeSucksException
IOException
public ScriptInstance loadScript(String fileName) throws IOException, YourCodeSucksException
IOException
YourCodeSucksException
public ScriptInstance loadScript(String fileName, Hashtable env) throws IOException, YourCodeSucksException
IOException
YourCodeSucksException
public ScriptInstance loadScript(File file, Hashtable env) throws IOException, YourCodeSucksException
IOException
YourCodeSucksException
public ScriptInstance loadScript(File file) throws IOException, YourCodeSucksException
IOException
YourCodeSucksException
public void unloadScript(String filename)
public void unloadScript(ScriptInstance script)
public Set getScriptsToUnload(Set configured)
public Set getScriptsToLoad(Set configured)
public void setCharsetConversion(boolean b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |