Keel 2.1RC2

org.keel.services.script.bsf
Class BSFScript

java.lang.Object
  extended byorg.keel.core.container.AbstractKeelServiceable
      extended byorg.keel.services.script.bsf.BSFScript
All Implemented Interfaces:
Configurable, Initializable, LogEnabled, Script, Serviceable

public class BSFScript
extends AbstractKeelServiceable
implements Configurable, Initializable, LogEnabled, Script

This is an implementation of the Keel Script service, based on the Jakarta Bean Scripting Framework (BSF). BSF in turn can work with TCL (JACL), JavaScript (Mozilla Rhino), Netrexx and Jython out of the box in Keel. With the approrpaite libraries added, BSF can also use Jython, Ruby, Perl and even VBScript (Micro$oft).

Version:
$Revision: 1.3 $ $Date: 2003/07/13 15:51:58 $
Author:
Shash Chatterjee Created on Jun 14, 2003

Field Summary
private  Configuration configuration
           
private  java.lang.String language
           
private  Logger logger
           
private  org.apache.bsf.BSFManager mgr
           
(package private)  java.net.URL rootURL
           
 
Fields inherited from class org.keel.core.container.AbstractKeelServiceable
 
Fields inherited from interface org.keel.services.script.Script
ROLE
 
Constructor Summary
BSFScript()
           
 
Method Summary
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
protected  java.io.Reader createInputReader(java.lang.String script)
           
protected  java.net.URL createRelativeURL(java.net.URL rootURL, java.lang.String relativeURI)
           
 void enableLogging(Logger logger)
          Provide component with a logger.
 void execute(java.lang.String script)
          Run the script in the named file
 void expose(java.lang.Object o, java.lang.String name)
          Expose a Java object to the script context
 void expose(java.lang.Object o, java.lang.String name, java.lang.String scope)
          Expose a java object to the script context, with a scoped name
 java.net.URL getResource(java.lang.String uri)
          Returns a URL for the given resource from the specified path.
 java.io.InputStream getResourceAsStream(java.lang.String uri)
          Attempts to open an InputStream to the given resource at the specified path.
protected  java.lang.String getScopedName(java.lang.String name, java.lang.String scope)
           
 void initialize()
          Initialize the component.
 void remove(java.lang.String name)
          Delete an object from the script context
 void remove(java.lang.String name, java.lang.String scope)
          Delete an object from the script context, with a scoped name
 java.lang.Object retrieve(java.lang.String name)
          Get an object from the script context
 java.lang.Object retrieve(java.lang.String name, java.lang.String scope)
          Get an object from the script context, with a scoped name
 
Methods inherited from class org.keel.core.container.AbstractKeelServiceable
getService, getService, getService, getService, getServiceManager, getServiceSelector, releaseService, releaseServices, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private Logger logger

configuration

private Configuration configuration

language

private java.lang.String language

mgr

private org.apache.bsf.BSFManager mgr

rootURL

java.net.URL rootURL
Constructor Detail

BSFScript

public BSFScript()
Method Detail

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations. Must not be null.
Throws:
ConfigurationException - if an error occurs
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

enableLogging

public void enableLogging(Logger logger)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
logger - the logger. Must not be null.
See Also:
LogEnabled.enableLogging(org.apache.avalon.framework.logger.Logger)

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: Initializable
Initialize the component. Initialization includes allocating any resources required throughout the component's lifecycle.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - if an error occurs
See Also:
Initializable.initialize()

expose

public void expose(java.lang.Object o,
                   java.lang.String name)
            throws ScriptException
Description copied from interface: Script
Expose a Java object to the script context

Specified by:
expose in interface Script
Parameters:
o - The object to expose
name - The name the object will be referred to by
Throws:
ScriptException - Error when the object cannot be exposed
See Also:
Script.expose(java.lang.Object, java.lang.String)

expose

public void expose(java.lang.Object o,
                   java.lang.String name,
                   java.lang.String scope)
            throws ScriptException
Description copied from interface: Script
Expose a java object to the script context, with a scoped name

Specified by:
expose in interface Script
Parameters:
o - The object to expose
name - The name the object will be referred to by
scope - The scope for the name
Throws:
ScriptException - Error when the object cannot be exposed
See Also:
Script.expose(java.lang.Object, java.lang.String, java.lang.String)

retrieve

public java.lang.Object retrieve(java.lang.String name)
                          throws ScriptException
Description copied from interface: Script
Get an object from the script context

Specified by:
retrieve in interface Script
Parameters:
name - The name of the object to retrieve
Returns:
The retrieved object
Throws:
ScriptException - Error when the object cannot be retrieved
See Also:
Script.retrieve(java.lang.String)

retrieve

public java.lang.Object retrieve(java.lang.String name,
                                 java.lang.String scope)
                          throws ScriptException
Description copied from interface: Script
Get an object from the script context, with a scoped name

Specified by:
retrieve in interface Script
Parameters:
name - The name of the object to retrieve
scope - The scope for the name
Returns:
The retrieved object
Throws:
ScriptException - Error when the object cannot be retrieved
See Also:
Script.retrieve(java.lang.String, java.lang.String)

remove

public void remove(java.lang.String name)
            throws ScriptException
Description copied from interface: Script
Delete an object from the script context

Specified by:
remove in interface Script
Parameters:
name - The name of the object to delete
Throws:
ScriptException - Error when the object cannot be deleted
See Also:
Script.remove(java.lang.String)

remove

public void remove(java.lang.String name,
                   java.lang.String scope)
            throws ScriptException
Description copied from interface: Script
Delete an object from the script context, with a scoped name

Specified by:
remove in interface Script
Parameters:
name - The name of the object to delete
scope - The scope for the name
Throws:
ScriptException - Error when the object cannot be deleted
See Also:
Script.remove(java.lang.String, java.lang.String)

execute

public void execute(java.lang.String script)
             throws ScriptException
Description copied from interface: Script
Run the script in the named file

Specified by:
execute in interface Script
Parameters:
script - The file name of the script
Throws:
ScriptException - Error from the scripting engine
See Also:
Script.execute(java.lang.String)

createInputReader

protected java.io.Reader createInputReader(java.lang.String script)
                                    throws ScriptException
Throws:
ScriptException

getScopedName

protected java.lang.String getScopedName(java.lang.String name,
                                         java.lang.String scope)

createRelativeURL

protected java.net.URL createRelativeURL(java.net.URL rootURL,
                                         java.lang.String relativeURI)
                                  throws java.net.MalformedURLException
Parameters:
rootURL - is the root context from which the relative URI will be applied
relativeURI - is the relative URI (without a leading "/")
Returns:
a new relative URL from the given root and with the addition of the extra relative URI
Throws:
java.net.MalformedURLException - if the URL is invalid.

getResource

public java.net.URL getResource(java.lang.String uri)
                         throws java.net.MalformedURLException
Returns a URL for the given resource from the specified path. If the uri starts with "/" then the path is taken as relative to the current context root. If the uri is a well formed URL then it is used. If the uri is a file that exists and can be read then it is used. Otherwise the uri is interpreted as relative to the current context (the location of the current script).

Throws:
java.net.MalformedURLException

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String uri)
                                        throws ScriptException
Attempts to open an InputStream to the given resource at the specified path. If the uri starts with "/" then the path is taken as relative to the current context root. If the uri is a well formed URL then it is used. Otherwise the uri is interpreted as relative to the current context (the location of the current script).

Returns:
null if this resource could not be loaded, otherwise the resources input stream is returned.
Throws:
ScriptException

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.