-
Notifications
You must be signed in to change notification settings - Fork 25
Table Creator Example
A basic configuration example that combines numeric and structural parameters. It's implementation is a reply to this question on stackoverflow. The source code is here.
The code is minimal with:
Design config = new Design("config.xml");
ListCreator creator = config.getValue("ListCreator");
assuming you have a config.xml InPUT design which contains the settings in InPUT syntax:
<SValue id="ListCreator">
<NValue id="SortDescending" value="false"/>
<SValue id="TableWriter" value="Xls"/>
</SValue>
For this to work, you have to define the design space as follows:
<SParam id="ListCreator">
<NParam id="SortDescending" type="boolean" />
<SParam id="TableWriter">
<SChoice id="Xls"/>
<SChoice id="Pdf"/>
</SParam>
</SParam>
You now tailor the programming language independent design space to your Java implementation in a code mapping:
<Mapping id="ListCreator" type="test.ListCreator" constructor="TableWriter SortDescending"/>
<Mapping id="ListCreator.TableWriter" type="test.TableWriter"/>
<Mapping id="ListCreator.TableWriter.Xls" type="test.XlsTableWriter"/>
<Mapping id="ListCreator.TableWriter.Pdf" type="test.PdfTableWriter"/>
From here, extend and customize at free will without touching the code.
-
design space:
-
design (for example):
-
Be prepared to receive an array instead (code):
ListCreator[] creators = config.getValue("ListCreator");
You decide the number and alternatives in the descriptor; the entries arrive in the defined order. This works similar for multiple dimensions (e.g. "[][][]"). You can add alternative table writers with further parameters in the future or change the current parameters without code changes on the caller side. Just make sure the classes are all available, and to test it. There are some sources of error (typos).