Creating polymorphic maps

Polymorphic mapping allows a single source business object to map to one of many potential destination business objects. To do this form of mapping, you must:

  1. Create a separate map (one source object and one destination object) for each possible outcome.
  2. Create a main polymorphic map that has a single source business object and multiple destination objects.
  3. Within the first attribute of each destination business object, check some condition that dictates which destination business object is to be populated. If the condition is true, run the appropriate map to accomplish the desired results using the runMap() method.

Example: Below is sample code from the first attribute in one of the destination business objects in a main polymorphic map. In this example, ObjInput is the Instance variable for the source business object, ObjOutput1 is the Instance variable for the output object which contains this code, and InputToOutput1 is the submap which performs the actual mapping from ObjInput to ObjOutput1. In this case, the condition which dictates whether this mapping occurs is based on the value of the Attr1 attribute within the source business object. Your condition will obviously vary.

BusObj[] rSrcBO = new BusObj[1];
BusObj[] rDstBO = new BusObj[1];
 
rSrcBO[0] = ObjInput;
String Attr1Val = ObjInput.getString("Attr1");
 
if (Attr1Val.equals("Poly1"))
   {
   try 
      {
      rDstBO = DtpMapService.runMap("InputToOutput1",
         DtpMapService.CWMAPTYPE,rSrcBO,cwExecCtx);
 
      ObjOutput1.setContent(rDstBO[0]);
      }
 
   catch (MapFailureException e)
      {
      e.toString();
      e.printStackTrace();
      raiseException(e);
      }
 
   catch (MapNotFoundException e)
      {
         raiseException("MapNotFoundException",
            "runMap did not find map"); 
      }
 
   catch (Exception e)
      {
      e.printStackTrace();
      }
   }

Copyright IBM Corp. 2004