<invoke>

Purpose/Function

Use reflection to invoke a method on an object.

This task assumes the target object and all parameter values already exist in the environment. (Note that ncsa.tools.ogrescript.types.JavaConstructor – see Assign and Declare – carries the same constraint vis-à-vis its parameter values.)

If invokeFirst is set to false and there are multiple matches, an exception will be thrown.

Attributes

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

target

java.lang.Object

(required)

invocation target instance, passed in from the environment

methodName

java.lang.String

(required)

exact name of the method to be invoked

fullScan

boolean

true

search the entire class hierarchy for the method

invokeFirst

boolean

true

if multiple methods are found, invoke the first encountered (i.e., that of the specific subclass)

global

boolean

false

if declaring or assigning return value, use global frame

declare

java.lang.String

null

declare return value as variable with this name

assign

java.lang.String

null

assign return value to variable with this name

Elements

TAG

TYPE

COUNT

DESCRIPTION

<parameter-value>

java.lang.Object

0:N

value of a parameter the method signature will accept

These should be added in the order required by the method signature. Polymorphism functions normally here.

ReturnValues

The invocation return value can be directly assigned to environment by setting the declare or assign attribute.

Examples

<ogrescript>
	<declare name="list" configured="true">
   		<list>
      		<value>false</value>
      		<value>string-beans</value>
      		<value>043.24398</value>
      		<value>hypertension</value>
   		</list>
	</declare>

	<declare name="newValue" string="anemia"/>
	<declare name="index" int="3"/>

	<invoke target="${list}" methodName="set">
     	     <parameter-value>${index}</parameter-value>
     	     <parameter-value>${newValue}</parameter-value>
	</invoke>
</ogrescript>

The side-effected list should be:

[OgreScript:false, string-beans, 043.24398, anemia]

  • No labels