Another frequent requirement encountered when building rule templates is the collection of macros. To support this, the <macro-type> tag defines a new type of macro with pre-existing components. An example follows:
<text>
#foreach($single_macro in ${heterogenous.getComponents()})
#if ($single_macro.type == "varname")
Value of text is $single_macro.
#else
Value of list is $single_macro.selectedValue.
#end
#end
</text>
</template>
The <macro-type> tag defines a heterogeneous collection of macros. Each component is described in a <macro-component> tag containing references to macro names (text and list) and editor names (editor_text and editor_list). The macros and editors are defined as ordinary, except that editors have a supplementary name attribute.
This rule template unit generates a drop-down list, as shown in Figure 27.
Figure 27. Rule wizard example 5
With this wizard, the user can add list and text macros to the collection. Dialog boxes appear allowing the user to enter values for these macros. The standard behavior allows the user to add values no matter how many components exist in the collection. Write a Java class derived from com.savvion.rulewizard.data.AggregateData when another policy is required. All the references passed to a collection macro are passed to its components.
After adding a few components of different types to the collection, click Finish to view the results. Notice the foreach Velocity construct used to display the results. Iterate through the collection obtained by calling the collection macro’s getComponents method. Because collection components contain different types, find a component’s type by accessing the type property. Based on this type, you decide what properties to use.