SourceForge.net Logo

How to invoke an operation?

This section shows how to invoke an operation using the JMI reflective interface.

openMDX restricts the parameter and return types of operations to be of structure type. In addition operations must have exactly one parameter. At first sight this looks like a big restriction. However, an operation with one or more parameters can always be mapped to an operation with one parameter of type struct.

To pass input parameters to the call you create an instance of a parameter structure and assign all the input parameters as attribute values. In case there has not been modeled a parameter structure for the input parameters, such a parameter structure is created implicitely by the generator.

The following code snippet shows an example call.

Example 6-9. Call an operation

// create an instance of the implicitely created parameter structure
// PersonSerializeParams and set input parameters
RefStruct personSerializeParams = lab1Pkg.refCreateStruct(
  "org:openmdx:example:lab1:PersonSerializeParams", 
  Arrays.asList(new Object[]{"asString"})
);

// call the operation and receive an instance of the modelled 
// parameter structure PersonSerializeResult as reply
RefStruct result = (RefStruct)person.refInvokeOperation(
  "org:openmdx:example:lab1:Person:serialize", 
  Arrays.asList(new Object[] { personSerializeParams })
);
String serializedForm = result.refGetValue(
  "org:openmdx:example:lab1:PersonSerializeResult:result"
);