Extender mapping

Extender mapping is designed to use Java™ rather than rule language. In a Java extender class, you create static elements that have the same name as business class elements.

You define an extender class name for a class in the Extender name field of the BOM to XOM Mapping section of the BOM Editor. The BOM-to-XOM mapping mechanism then looks up extender elements that have the same name as your business elements in the extender class. Therefore, when you create the extender class, make sure that you create elements that can be found from the business element name.

The following table shows extender mapping options. It assumes that an extender class name ExtenderClass is used for a business class named BusinessClass.

Table 1. Extender mapping options
Member of business class BusinessClass Case Scope Extender member of class ExtenderClass
Constructor BusinessClass(MyBizClassB, MyBizClassC) Call by new - static ExtenderClass create(MyClassB, MyClassC)
Attribute MyBizClassA attr Assignment static

static MyClassA attr

—OR—

static void setAttr(MyClassA)

instance static void setAttr(ExtenderClass, MyClassA)
Access static

static MyClassA

—OR—

static MyClassA getAttr()

instance static MyClassA getAttr(ExtenderClass)
Method MyBizClassA myBizMethod(MyBizClassB, MyBizClassC) Invocation static static MyClassA myMethod(MyClassB, MyClassC)
instance static MyClassA myMethod(ExtenderClass, MyClassB, MyClassC)
InstanceOf operator (Tester) Use of operator classification in conditions. - static boolean tester(ExtenderClass)

Example

The following code shows an example of an extender class for a BOM class that is named EventDispatcher.

public class DispatcherExtender {
  /**
   * This extender method implements
   * EventDispatcher.exception(FinancialEvent, String) 
   */
  public static void exception(GenericObject dispatcher, 
                               GenericObject event, 
                               String message) {
    System.out.println("###> Processing Exception : event " 
                                         + event + message + "<###");
  }
  
  /**
   * This extender method implements
   * EventDispatcher.send(FinancialEvent, String) 
   */
  public static void send(GenericObject dispatcher, 
                          GenericObject event, 
                          String target) {
    System.out.println("===> Sending " + event + " to " + target + " <===");
  }
}

Class tester mapping

The mapping from a business class to an execution class can become complex. For example, you might have several business classes that are mapped to one execution class. To make mapping easier, you can specify a tester to test the instances of the execution class.

For example, you have a RichCustomer business class that corresponds to an execution class Customer:

  • Set Execution name to Customer.

  • Set Extender name to RichCustomerExt. This class has no naming conventions.

  • Enter the following code in the Tester field:

    public static boolean tester(Customer customer) {
      return customer.money > 100000;
    }

    The code specifies that the tester method is a Java static method of the extender class that is named tester. It returns a boolean and takes the execution class Customer as its parameter.

Attribute mapping to an expression to return a value

You can use extender mapping to map a BOM attribute to an expression and return an attribute value at run time.

In this example, the method that is used when the attribute averageItemPrice is accessed is provided as a Java static method that is named getAverageItemPrice:

public class CartExtender {
  public static double getAverageItemPrice(ShoppingCart cart) {
    if (cart.getNumberOfItems() == 0)
      return 0;
    return cart.getValue()/ cart.getNumberOfItems();    
  }
}

Attribute mapping to an expression to set a value

You can map a BOM attribute to an expression that sets the value of the attribute at run time.

In this example, the method that is used when the attribute averageItemPrice is accessed is provided as a Java static method that is named setAverageItemPrice:

public class CartExtender {  
  public static void setAverageItemPrice(ShoppingCart cart, double v) {
    cart.setValue(cart.getNumberOfItems()*v);
  }
}

Method call mapping

You can map a method call to a specified expression.

In this example, the method that is used when the method isOlderThan is called is provided as a Java static method with the same name in the extender class:

public class ExtCustomer {  
  public static boolean isOlderThan(Customer customer, int age) {
    return customer.getAge() > age;
  }
}

Constructor call mapping

You can map a constructor call to any expression.

In this example, the method that is used when the constructor is called is provided as a Java static method that is called create:

public class ExtCustomer {  
  public static Customer create(String name, int age) {
    Customer c = new Customer(name);
    c.setAge(age);
    return c;
  }
}

Synthetic object mapping

You can use a synthetic object to simulate the state of real objects. Like a real object, a synthetic object can store attributes. Service Data Objects (SDO) is an example of a synthetic object framework. You can use synthetic objects instead of regular Java objects as application data. You can then use BOM-to-XOM mapping to implement a complete business object model that uses only synthetic objects.

Specify the name of your extender class in the Extender name field, and specify the name of the execution class in the Execution name field.

In this example, the extender class defines all the necessary mappings to the interface of the execution class java.util.Map:

import java.util.*;
public class CustomerExtender {
  public static String getName(Map customer) {
    return (String) customer.get("name");
  }

  public static int getMoney(Map customer) {
    return ((Integer) customer.get("money")).intValue();
  }

  public static void setMoney(Map customer, int value) {
    customer.put("money", new Integer(value));
  }

  public static Map create(String name) {
    Map result = new HashMap(3);
    result.put("name", name);
    result.put("money", new Integer(0));
    // as assumed it always contains an Integer
    result.put("className", "Customer");
    return result;
  }

  public static boolean tester(Map customer) {
    return "Customer".equals(customer.get("className"));
  }
}