[Index]

invoke


Invoke a java method or script snippet, or JMX operation.

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


Property Summary

args An alternative configuration for the values to use as arguments.
function The function/method/operation name to call.
parameters The values to use as arguments.
source The java object or script Invocable on which to invoke the method/function.

Example Summary

Example 1 Invoke a method on a bean.
Example 2 Invoke a static method of a class.
Example 3 Invoking a function of a script.

Property Detail

args

Configured ByELEMENT
AccessREAD_WRITE
RequiredMust match the expected arguments.

An alternative configuration for the values to use as arguments. This was added for convenience as setting up a lot of simple arguments can be tedious. If this property is provided then parameters is ignored.

function

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredYes.

The function/method/operation name to call. Note that for a Java static method the method name must be prefixed with the word static (see examples).

parameters

Configured ByELEMENT
AccessREAD_WRITE
RequiredMust match the expected arguments.

The values to use as arguments. Note that the args property may be more convenient for simple arguments.

source

Configured ByELEMENT
AccessREAD_WRITE
RequiredYes.

The java object or script Invocable on which to invoke the method/function. If the method is a Java static method then this is the class on which to invoke the method.


Examples

Example 1

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 2

Invoke a static method of a class.

<oddjob>
    <job>
        <sequential>
            <jobs>
                <variables id="vars">
                    <message>
                        <invoke function="static greetPerson">
                            <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 3

Invoking a function of a script. See the script examples.


(c) R Gordon Ltd 2005 - Present