1

I have requirement in BAL rule to create objects and add them to a list

For instance, Customer is a class with below members 1. Name 2. Location

Based on the 'if' condition of the BAL rule, need to create objects of Type Customer and add them to Customerlist.

I tried to create objects by creating method in the Customer class in BOM editor by following steps provided under this link

how to create an object (call the constructor) from a BOM member on a decision table action column? But I'm getting below error: 'Incompatible value in the 'return' instruction'

Can anyone please provide detailed steps to create objects and add them to a list in BAL?

Community
  • 1
  • 1
chaithra
  • 13
  • 1
  • 4

3 Answers3

1

Constructors are not directly verbalized in the BOM. You can create a method in XOM which creates the object via constructor and you can map this method onto BOM and verbalize it to be used in rule artifacts.

Mustehssun Iqbal
  • 576
  • 3
  • 19
0

My suggestion to your scenario would be:

  1. Create a verbalization in the XOM to receive the elements that will be added to the main list (Composite pattern).
  2. Verbalize it
  3. Add it in your Action Column (i.e. within a Decision Table)

I used this approach with great success in several scenarios, with no lack of performance.

Hope this helps.

0

Create an object and adding it to a list should be two separate methods.

Create: Assuming you followed the recipe for the link you provided, you should have a BOM method called createCustomer() on the Customer BOM class. Since there is no XOM to back that BOM method, you must supply B2X code for that method. Most people refer to such as a method as a virtual BOM method. It would be helpful to see the B2X code for that method. Are your BOM and XOM classes the same type? If not, you would have specified an execution name for the Customer BOM class. In that case, you may need to cast the return value of the createCustomer() BOM method to the Customer BOM class.

// Verbalize as: new customer
Customer Customer.createCustomer()

return (Customer) new OtherCustomerClassFromXOM();

Add: Define another virtual BOM method on some class, and name the method addCustomer(Customer customer). Usually it would be on the class that contained the list variable as a member. But if the list variable is a global variable (i.e., a ruleset variable), then the method could be a static member on any class, even your Customer class.

// Verbalize as: add {0} to {1}
void Customer.addCustomer(Customer customer, java.util.Collection customerList)

if (customerList == null) { 
    customerList = new java.util.ArrayList(); 
}
customerList.add(customer);