com.ail.core.command
Class BeanShellAccessor

java.lang.Object
  extended by com.ail.core.Type
      extended by com.ail.core.command.AbstractCommand
          extended by com.ail.core.command.Accessor
              extended by com.ail.core.command.BeanShellAccessor
All Implemented Interfaces:
ConfigurationOwner, CoreUser, java.io.Serializable, java.lang.Cloneable

public class BeanShellAccessor
extends Accessor
implements ConfigurationOwner

This accessor supports the use of BeanShell scripts as services. BeanShell is an open source java interpreter (www.beanshell.org). It interprets a scripting language that looks very like java - the most notable exception being that the variables are not "typed". It literally interprets - from Strings or files, there is no compilation phase involved.

The interpreter runs 'in-jvm' and through the adoption of a simple convension it has access to the command argument instance passed to the service, and can modify the instance's values.

This accessor supports the notion of extending (or inheriting) from another BeanShell service. In effect, the script defined in the extended service is prepended to the script defined in this service and the result is executed. The service will walk up a tree of services if necessary - i.e. if the parent script extends a further service then it also get includes. The sample configuration below shows how the extends feature is setup; the line in bold shows forces BeanShellService2 to extend BeanShellService:

 
 <service name="BeanShellService" builder="ClassBuilder" key="com.ail.core.command.BeanShellAccessor" >
    <parameter name="Script"><![CDATA[
      if (args.getX()<100) {
        args.setR(args.getX()+args.getY());
      }
      else {
        args.setR((2*args.getX())+args.getY());
      }
    ]]></parameter>
 </service>
 
 <service name="BeanShellService2" builder="ClassBuilder" key="com.ail.core.command.BeanShellAccessor">
    <parameter name="Extend">BeanShellService</parameter>
    <parameter name="Script"><![CDATA[
      if (args.getX()>1000) {
          args.setR(args.getX()-(2*args.getY()));
      }
    ]]></parameter>
 </service>
 

Version:
$Revision: 1.9 $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.ail.core.Type
jXPathContext, NOT_PERSISTED
 
Constructor Summary
BeanShellAccessor()
           
 
Method Summary
 CommandArg getArgs()
          Get the argument set associated with this command.
 Configuration getConfiguration()
          Fetch the configuration of the entry point associated with this command.
 java.lang.String getConfigurationNamespace()
          Return the caller's configuration namespace.
 Core getCore()
           
 java.lang.String getExtend()
           
 java.lang.String getScript()
           
 java.security.Principal getSecurityPrincipal()
          Get the callers security principal.
 java.lang.String getUrl()
           
 Version getVersion()
          Fetch the version of the command (entry point) associated with this command.
 VersionEffectiveDate getVersionEffectiveDate()
          The Core uses this callback to determin which versions of artefacts it should use on the CoreUser's behalf.
 java.lang.String getWholeScript()
           
 void invoke()
          Invoke the command associated with this command object.
 void resetConfiguration()
          Factory reset.
 void setArgs(CommandArg args)
          Update this Command object's arguments with those taken from the command arg passed in.
 void setConfiguration(Configuration properties)
          Update the configuration of the entry point associated with this command.
 void setExtend(java.lang.String extend)
           
 void setScript(java.lang.String script)
           
 void setUrl(java.lang.String url)
           
 void setWholeScript(java.lang.String wholeScript)
           
 
Methods inherited from class com.ail.core.command.Accessor
getLoggingIndicator, getLoggingIndicatorAsString, setLoggingIndicator, setLoggingIndicatorAsString
 
Methods inherited from class com.ail.core.Type
addAttribute, clone, deleteLock, deleteSerialVersion, fetchJXPathContext, getAttribute, getAttribute, getAttributeCount, getForeignSystemId, getLock, getSerialVersion, getSystemId, hasLock, hasSerialVersion, hasSystemId, isPersisted, markAsNotPersisted, mergeWithDataFrom, removeAttribute, removeAttribute, setAttribute, setForeignSystemId, setLock, setSerialVersion, setSystemId, xpathGet, xpathGet, xpathIterate, xpathSet
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanShellAccessor

public BeanShellAccessor()
Method Detail

setArgs

public void setArgs(CommandArg args)
Description copied from class: AbstractCommand
Update this Command object's arguments with those taken from the command arg passed in. This is in effect a bulk setter. This interface will be implemented by beans that have many more getters/setters to support their properties. The implementations of this method take 'that', and pull all the relevant properties into this.

Specified by:
setArgs in class AbstractCommand
Parameters:
args - Source for arguments

getArgs

public CommandArg getArgs()
Description copied from class: AbstractCommand
Get the argument set associated with this command.

Specified by:
getArgs in class AbstractCommand
Returns:
This objects arguments.

invoke

public void invoke()
            throws BaseException
Description copied from class: AbstractCommand
Invoke the command associated with this command object. Before invoke is called, the command object must be populated with all the information (parameters) needed to invoke the service via the command object's setters. Once invoke has been called, the object's getters are used to retrieve the results.

Specified by:
invoke in class AbstractCommand
Throws:
BaseException

getVersion

public Version getVersion()
Description copied from class: AbstractCommand
Fetch the version of the command (entry point) associated with this command. This is similar to the 'invoke' entry point in that control is passed to the entry point object. In this case to the getVersion() method.

Note: This method does not return the version of the command.

Specified by:
getVersion in class AbstractCommand
Returns:
The version of the entry point.

getConfiguration

public Configuration getConfiguration()
Description copied from class: AbstractCommand
Fetch the configuration of the entry point associated with this command. This is similar to invoke in that control is passed to the entry point object, in this case to the getConfiguration method. Note: This method does not return the configuration of the command object.

Specified by:
getConfiguration in interface ConfigurationOwner
Specified by:
getConfiguration in class AbstractCommand
Returns:
The entry point's configuration.

setConfiguration

public void setConfiguration(Configuration properties)
Description copied from class: AbstractCommand
Update the configuration of the entry point associated with this command. This is similar to the invoke method in that control is pass to the entry point object, in this case to its setConfiguration method. Note: This method does not set the configuration of the command object.

Specified by:
setConfiguration in interface ConfigurationOwner
Specified by:
setConfiguration in class AbstractCommand
Parameters:
properties - Properties to replace the current configuration.

setScript

public void setScript(java.lang.String script)

getScript

public java.lang.String getScript()

setUrl

public void setUrl(java.lang.String url)

getUrl

public java.lang.String getUrl()

getVersionEffectiveDate

public VersionEffectiveDate getVersionEffectiveDate()
Description copied from interface: CoreUser
The Core uses this callback to determin which versions of artefacts it should use on the CoreUser's behalf.

Specified by:
getVersionEffectiveDate in interface CoreUser
Returns:
The version date that the CoreUser is working at.

getSecurityPrincipal

public java.security.Principal getSecurityPrincipal()
Description copied from interface: CoreUser
Get the callers security principal.

Specified by:
getSecurityPrincipal in interface CoreUser
Returns:
The callers security principal

getConfigurationNamespace

public java.lang.String getConfigurationNamespace()
Return the caller's configuration namespace.

Specified by:
getConfigurationNamespace in interface CoreUser
Returns:
Caller's namespace

resetConfiguration

public void resetConfiguration()
Description copied from interface: ConfigurationOwner
Factory reset. Reset the configuration to the factory defaults.

Specified by:
resetConfiguration in interface ConfigurationOwner

getCore

public Core getCore()

getExtend

public java.lang.String getExtend()

setExtend

public void setExtend(java.lang.String extend)

getWholeScript

public java.lang.String getWholeScript()

setWholeScript

public void setWholeScript(java.lang.String wholeScript)