org.oddjob.script
Class InvokeType

java.lang.Object
  extended by org.oddjob.script.InvokeType
All Implemented Interfaces:
ArooaValue, ArooaSessionAware

public class InvokeType
extends Object
implements ArooaValue, ArooaSessionAware

Description

Invoke a java method or script snippet.

For a script, the source must be a javax.script.Invocable object.

For a java method, the source specifies the object on which to invoke the method. If the source is a class then the static method of the class is invoked.

Example

Invoke a method on a bean. The method takes a single date parameter which is uses to generate a time of day dependent greeting.
<oddjob>
    <job>
        <sequential>
            <jobs>
                <variables id="vars">
                    <message>
                        <invoke function="greeting">
                            <source>
                                <bean class="org.oddjob.script.GreetingService"/>
                            </source>
                            <parameters>
                                <schedule>
                                    <date>
                                        <value value="${date}"/>
                                    </date>
                                    <schedule>
                                        <schedules:now xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
                                    </schedule>
                                </schedule>
                            </parameters>
                        </invoke>
                    </message>
                </variables>
                <echo id="echo-greeting">${vars.message}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>
The ${date} reference is there so that it can be injected during a test, to get a guaranteed result. When this is example is run as is, this is null so the system clock to be used there by giving a real time based greeting.

One subtle point to note about Oddjob configuration that this example highlights is to do with when types are resolved. The invoke type will be resolved when the echo job is run. The schedule type will be resolved when the variables job is run. If the echo job were scheduled to run several hours after the variables job had run it would not give the correct greeting!

Example

Invoke a static method of a class.
<oddjob>
    <job>
        <sequential>
            <jobs>
                <variables id="vars">
                    <message>
                        <invoke function="greetPerson" static="true">
                            <source>
                                <class name="org.oddjob.script.GreetingService"/>
                            </source>
                            <parameters>
                                <value value="John"/>
                            </parameters>
                        </invoke>
                    </message>
                </variables>
                <echo id="echo-greeting">${vars.message}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example

Invoking a function of a script. See the ScriptJob examples.
Author:
Rob.

Nested Class Summary
static class InvokeType.Conversions
           
 
Constructor Summary
InvokeType()
           
 
Method Summary
 String getFunction()
           
 ArooaValue getParameters(int index)
           
 Object getSource()
           
 boolean getStatic()
           
 void setArooaSession(ArooaSession session)
           
 void setFunction(String function)
           
 void setParameters(int index, ArooaValue parameter)
           
 void setSource(Object source)
           
 void setStatic(boolean staticMethod)
           
 String toString()
           
 Object toValue()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InvokeType

public InvokeType()
Method Detail

setArooaSession

public void setArooaSession(ArooaSession session)
Specified by:
setArooaSession in interface ArooaSessionAware

toValue

public Object toValue()
               throws ArooaConversionException
Throws:
ArooaConversionException

getSource

public Object getSource()

setSource

public void setSource(Object source)

getFunction

public String getFunction()

setFunction

public void setFunction(String function)

getParameters

public ArooaValue getParameters(int index)

setParameters

public void setParameters(int index,
                          ArooaValue parameter)

setStatic

public void setStatic(boolean staticMethod)

getStatic

public boolean getStatic()

toString

public String toString()
Overrides:
toString in class Object