Back to Summer Batch home page

Template facility

In Chapter 6, Flat File Writer was presented. Among other properties to set, for LineAggregator Summer.Batch.Extra.Template.AbstractTemplateLineAggregator<T> is dedicated to format the output to an external format file. The class must be extended by implementing IEnumerable<object> GetParameters(T obj) that converts the business object used in batch into an enumeration of values.

The template file must have a content like this: Key:Format, with the Format in C# fashion. Multiple lines of this form can appear with multiple keys and a format can be multi line by repeating colon.

Example 7.23. Example format file

EMPLOYEE: EMPID:{0} EMPNAME:{1}


Example 7.24. More advanced example format file

EMPLOYEE: EMPID:{0} EMPNAME:{1}
HEADER  :=====================================
        := Employee List for Date {0:MM/dd/yyyy} =
        :=====================================
FOOTER  :=====================================
        := End Employee List                 =
        :=====================================
In this example, there are three formats, and two of them span on three lines each.


The following properties are mandatory (need to be set at initialization time):

Optional properties (Default value is provided, however can set at initialization time):

Configuring the AbstractTemplateLineAggregator:

Example 7.25. Typical AbstractTemplateLineAggregator usage


With a MyTemplateLineAggregator such as:

Example 7.26. Typical TemplateLineAggregator class


[Note]Note

The template line aggregator will be useful with a way to switch between one template Id and another depending on the line to write. This requires a ProcessWriterAdapter, which enables to call the writer in a processor code and have a full control on its use. More details just below.

With a simple use of the ItemplateLineAggregator in a writer, as explained above, the TemplateId is set once and for all in the Unity Loader. This means a multi-format template file would be useful only if several writers are used in the job, and each have a format, all the formats being stored in same template file. However, If a file to write must have several formats depending on the line, a more accurate control on the Template Id must be used. First, the writer with an aggregator must be declared in a process adapter, as explained above in this chapter.


With such a setup, even though a default TemplateId is assigned, it becomes possible to change it programmatically and to drive writer at will.


Please note that GetParameters method of the aggregator class must be adapted to handle different types of input objects.


Back to Summer Batch home page