Collections
In the BOM, arrays and collections represent a set of objects. In the BAL, you must set a collection domain on a collection of type java.util.Collection.
In the BOM, collections are members that are semantically linked to a BOM class with a one-to-many relationship.
Collections appear in business rules with BAL operators and constructs such as:
- <an object> is one of <objects>
- the number of <objects> in <objects>
In the following example, the action rule uses collections:
definitions set 'company1' to a company; set 'customer1' to a customer in the employees of 'company1'; if the number of books in the items of the shopping cart of 'customer1' is more than 5 …
You can represent a set of objects in the BOM in two ways:
-
Array (java.lang.Object[])
-
Collection (java.util.Collection)
Both are mapped to the concept of collection of objects
in
the BAL. From a BAL perspective, a collection is an element with multiple-cardinality.
From a BOM perspective, it is an array, or a BOM member with a collection
domain.
A collection is treated as a collection of objects
in the
BAL only if it has a collection domain. A collection domain specifies
the cardinality and the type of collection elements, for example, 0,*
class Customer.
Ruleset parameters or variables of type or subtype java.util.Collection are
treated as collection of objects
in the BAL.
When you edit a business rule using the Content Assist box in designer, you can access the constructs relative to collections if the member is of type:
-
array
-
java.util.Collection and has a collection domain.
Collections of array type
Members (attributes, methods, constructors) of array type are automatically treated as collections.
For example, in the following BOM class, the method getEmployees is automatically treated in business rules as a collection of Employee objects.
public class Company {
Employee[] getEmployees();
}
Collections of java.util.Collection type
In the BAL, a member of type java.util.Collection is not treated as a collection until you set a collection domain.
For example, in the following BOM class, a collection domain is set and defined.
public class Company {
java.util.Collection getEmployees() domain 0, * class Employee;
}
Use the BOM editor to set a domain on a member of type java.util.Collection. For information about defining domains, refer to Defining domains.