-
Notifications
You must be signed in to change notification settings - Fork 25
Import Export
In this tutorial you will learn how the InPUT import/export mechanisms works and how it can be customized for other formats (e.g. database import/export).
We illustrate the mechanism given the following design space and design examples (solely illustrative purpose).
<SParam id="Steak"> <NParam id="Temperature" type="decimal" inclMin="25" inclMax="80" /> <NParam type="double" id="ProportionBurned" /> <SChoice id="Raw"> <NParam id="HealthRisk" type="boolean" /> </SChoice> <SChoice id="Medium"> <SParam id="Rather"> <SChoice id="Raw" /> <SChoice id="WellDone" /> </SParam> </SChoice> <SChoice id="WellDone" /> </SParam>
Thus, a steak has a certain temperature (between 25 and 80 degrees Celsius), and can be of one of three types: Raw, Medium, and WellDone. If it is raw, there is a potential health risk. The medium steak can lean towards two ends, raw and well done.
<SValue id="Steak" value="Medium"> <NValue id="Temperature" value="39.19306187269093744163228620891459286212921142578125" /> <NValue id="ProportionBurned" value="0.2187556079980736" /> <SValue id="Rather" value="WellDone" /> </SValue>
This steak has been randomly created by the execution of the example code in here (and the precision of the temperature assessment can be questioned). The steak is medium, quite burned, and not hot; a real highlight. ;)
Given that we have created a random steak with
IDesignSpace space = new DesignSpace("structuredSpaceAdvanced.xml"); IDesign steak = space.next("MySteak");
we can export it to XML by
steak.export(new XMLFileExporter("mySteak.xml"));
and import it from the XML again by
IDesign sameSteak = space.impOrt(new XMLFileImporter("mySteak.xml"));
The import/export hook can be customized for other formats. InPUT comes by default with export support to LaTeX tables and Java Properties files. The LaTeX exporter is executed like this
steak.export(new LaTeXExporter("steakTable.tex")); // design space.export(new LaTeXExporter("steakSpaceTable.tex")); // design space
and results in the following (LaTeX processed) output:
For scientific publications, this offers a quick way for printing. The following code prudces a properties file containing the steak parameters.
Properties streakProperties = steak.export(new PropertiesExporter());
You can create your own importer/exporter by implementing the InPUTExporter and InPUTImporter interfaces.
In this tutorial you learned how to import and export InPUT descriptors using Java. Export to LaTeX and Properties files has been exemplified, and the interfaces for implementation of customized import/export mechanisms pointed out.