Defining Callable Object Mappings

Use

When you insert callable objects into actions, you need to map their parameters. Depending on the type of the callable object, you have to define different mappings:

  • Callable object for execution - map its input and output parameters to the local context of the action
  • Callable object for display - map its input parameters to the output parameters of the callable object for execution
Mapping information is always stored in the
IGPObjectReference
corresponding to the inserted callable object.

Prerequisites

Procedure

  1. Copy the input and output parameters of the callable object for execution to the input and output contexts of the action respectively. For more information, see Creating Actions .
  2. Copy the input and output parameters of the callable object for execution to the local context of the action.

Copying Input Parameters to Local Context

importcom.sap.caf.eu.gp.process.api.IGPCallableObject;
importcom.sap.caf.eu.gp.process.api.IGPModifiableAction;
importcom.sap.caf.eu.gp.structure.api.IGPStructureInfo;
importcom.sap.caf.eu.gp.structure.api.IGPAttributeInfo;
importjava.util.Collection;
importjava.util.Iterator;
 
// retrieve action's local context
IGPStructureInfo local = action.getLocalParameters();
 
// retrieve the callable object for execution
IGPCallableObject exco = a.getExecuteCallableObject().getCallableObject(); 
 
// retrieve object's input context
IGPStructureInfo in = exco.getInputParameters();
 
// retrieve input attributes
Collection attributes = in.getAttributes();
// for each attribute in the list
for(Iterator iter = attributes.iterator(); iter.hasNext();) {
         IGPAttributeInfo attribute = (IGPAttributeInfo) iter.next();
         // create a corresponding attribute in local structure
         IGPAttributeInfo aCopy = local.addAttribute(attribute.getTechName(), attribute.getNamespace(), attribute.getType());
         // set multiplicity of the new attribute
         aCopy.setMultiplicity(attribute.getMultiplicity());}
 
// retrieve input substructures    
Collection structures = in.getStructures();
// for each structure in the list  
for(Iterator iter = structures.iterator(); iter.hasNext();) {
         IGPStructureInfo struct = (IGPStructureInfo) iter.next();
         // create a corresponding structure in local structure
         IGPStructureInfo sCopy = local.addStructure(struct.getTechName(), struct.getNamespace());
         // set multiplicity of the new structure
         sCopy.setMultiplicity(struct.getMultiplicity());
 
         // use recursion to copy content of structure ...
}    
// finally, save the modified local context
action.setLocalParameters(local);
 

By analogy, copy the output parameters you need to pass to the action.

  1. Define the mappings as follows:
    1. Local parameters of the action to input parameters of the callable object

Mapping Local Action Parameters to Input Callable Object Parameters
importjava.util.Iterator;
importcom.sap.caf.eu.gp.base.api.IGPObjectReference;
importcom.sap.caf.eu.gp.process.api.IGPModifiableAction;
importcom.sap.caf.eu.gp.structure.api.IGPMappingGroup;
importcom.sap.caf.eu.gp.structure.api.IGPStructureInfo;
importcom.sap.caf.eu.gp.structure.api.IGPAttributeInfo;
 
// retrieve the object reference to the callable object for execution in action "a"
IGPObjectReferenceref = a.getExecuteCallableObject();
 
// retrieve the input mapping information
IGPMappingGroupinMap = ref.getInputMapping();
 
// retrieve input definition of CO
IGPStructureInfoin = ref.getReferencedObject().getInputParameters();
 
// for each attribute in CO's input
IteratorattrList = in.getAttributes().iterator();
while(attrList.hasNext()) {
   IGPAttributeInfo attr = (IGPAttributeInfo) attrList.next();
  
   // map action's local to CO's input attribute
   inMap.addMappingRule(
      new String[] {attr.getTechName()},
      new String[] {attr.getTechName()}
   );
}
// for each structure in CO's input
Iterator structList= in.getStructures().iterator();
while(structList.hasNext()) {
   IGPStructureInfo struct = (IGPStructureInfo) structList.next();
  
   // map action's local to CO's input structure
   inMap.addMappingRule(
      new String[] {struct.getTechName()},
      new String[] {struct.getTechName()}
   );
}
// save input mapping     
ref.setInputMapping(inMap);
    
  1. Output parameters of the callable object to local parameters of the action

Mapping Output Callable Object Parameters to Local Action Parameters
 
// retrieve output definition of CO
IGPMappingGroupoutMap = ref.getOutputMapping();
// map everything from CO's output to action's local parameters
outMap.addMappingRule(
   new String[] {},
   new String[] {}
);
// save output mapping
ref.setOutputMapping(outMap);
    
  1. Input-to-local and local-to-input within the action.

    For more information, see Defining Mappings Within an Activity in Defining Activity Mappings .

  1. Optionally, you can consolidate the input parameters of the callable object for display with those parameters in the local context of the action which you need to display after the action is completed.