|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ail.core.Type
com.ail.core.command.AbstractCommand
com.ail.core.command.Accessor
com.ail.core.command.JaninoAccessor
public class JaninoAccessor
This accessor provides access to services implented using Janino. Services that use this accessor either define a script inline (using a Script parameter in the configuration), of they point at a script via a URL (using the Url parameter). Either way, the script is compiled to java byte code by Janino at runtime and the resulting code is invoked by the accssor.
Compilation is only carried on when the service is initially loaded - on the first attemt to execute the service. Once compiled, the resulting class is cached by the accessor for faster access later on. As used by this accessor, Janino scripts adopt a simple contract: they must define an invoke method which accepts only one argument of a type which is suitable for the command being serviced. In the following example the command called 'TestCommand' had been bound to the Janino based 'TestService'. The convension within the core is to have a the command class (TestCommand) paired with an argument implementation (TestArgImp); therefore, the invoke method accepts an argument of that type.
<service name="TestService" builder="CachingClassBuilder" key="com.ail.core.command.JaninoAccessor" >
<parameter name="Script"><![CDATA[
import com.ail.coretest.service.TestArgImp;
public static void invoke(TestArgImp args) {
if (args.getX()>1000) {
args.setR(args.getX()-(2*args.getY()));
}
}
]]></parameter>
</service>
<command name="TestCommand" builder="ClassBuilder" key="com.ail.coretest.service.TestCommand">
<parameter name="Service">TestService</parameter>
</command>
The JaninoAccessor supports the concept of inheritance (or extension) between services based on it. The concept of one service 'Extend'ing
another is common to all Core accessors, but in the case of the JaninoAccessor the approach adopted is better thought of as a chain. In effect
the service which form part of the chain are each invoked in turn by the accessor.
Building on the sample code above, an 'extending' service could be added as follows:
<service name="TestExtendingService" builder="CachingClassBuilder" key="com.ail.core.command.JaninoAccessor" >
<parameter name="Extends">TestService</parameter>
<parameter name="Script"><![CDATA[
import com.ail.coretest.service.TestArgImp;
public static void invoke(TestArgImp args) {
if (args.getX()<1000) {
args.setR(args.getX()-(4*args.getY()));
}
}
]]></parameter>
</service>
<command name="TestExtendingCommand" builder="ClassBuilder" key="com.ail.coretest.service.TestCommand">
<parameter name="Service">TestExtendingService</parameter>
</command>
The 'Extends' parameter in 'TestExtendingService' tells the accessor to execute the named service before this one - a
chain with two links. So in this case invoking the 'TestExtendingCommand' will lead to a 'TestService' being invoked first,
and then 'TestExtendingService' being invoked.
Note that the invoke() methods in all the services in a chain must accept an argument of the same type.
| Field Summary |
|---|
| Fields inherited from class com.ail.core.Type |
|---|
jXPathContext, NOT_PERSISTED |
| Constructor Summary | |
|---|---|
JaninoAccessor()
|
|
| Method Summary | |
|---|---|
void |
activate(Core core,
Type typeSpec)
|
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. |
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)
|
| 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 |
|---|
public JaninoAccessor()
| Method Detail |
|---|
public void setArgs(CommandArg args)
AbstractCommand
setArgs in class AbstractCommandargs - Source for argumentspublic CommandArg getArgs()
AbstractCommand
getArgs in class AbstractCommand
public void activate(Core core,
Type typeSpec)
public void invoke()
throws BaseException
AbstractCommand
invoke in class AbstractCommandBaseExceptionpublic Version getVersion()
AbstractCommandNote: This method does not return the version of the command.
getVersion in class AbstractCommandpublic Configuration getConfiguration()
AbstractCommand
getConfiguration in interface ConfigurationOwnergetConfiguration in class AbstractCommandpublic void setConfiguration(Configuration properties)
AbstractCommand
setConfiguration in interface ConfigurationOwnersetConfiguration in class AbstractCommandproperties - Properties to replace the current configuration.public void setScript(java.lang.String script)
public java.lang.String getScript()
public void setUrl(java.lang.String url)
public java.lang.String getUrl()
public VersionEffectiveDate getVersionEffectiveDate()
CoreUser
getVersionEffectiveDate in interface CoreUserpublic java.security.Principal getSecurityPrincipal()
CoreUser
getSecurityPrincipal in interface CoreUserpublic java.lang.String getConfigurationNamespace()
getConfigurationNamespace in interface CoreUserpublic void resetConfiguration()
ConfigurationOwner
resetConfiguration in interface ConfigurationOwnerpublic Core getCore()
public java.lang.String getExtend()
public void setExtend(java.lang.String extend)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||