# readme - BillOfMaterial

Inhalt

- 1 Basic example of ZBNF-usage: Bill of Material
- 2 Conversion to XML
- 3 Translation to another text format
- 4 Evaluation with Java
- 5 The example contains

Topic:.readme_BillOfMaterial.

.

## 1 Basic example of ZBNF-usage: Bill of Material

Topic:.readme_BillOfMaterial..

This is a simple example showing the usage of the ZBNF-Parser.

The Bill of Material is given in a simple text format with well syntax. It may be an output from another computing system. The example in the file `billOfMaterial.txt` is very short, only the principles should be shown.

## 2 Conversion to XML

Topic:.readme_BillOfMaterial..

The Batchfile or Unix shell script `billOfMaterial2Xml.bat` calls the Zbnf2Xml-Conversion and produces a XML file named `result/billOfMaterial.xml`. You can start that MS-Windows-batchfile as Unix/Linux shell script too, because the less used command line statements are closed indentically.

The result will be written in the destination directory 'result'. To compare the correctness of translation, the file `result.reference.zip` is given in this download, Its content should be identically with the generated file.

In praxis, the bill of material, translated to the XML-Format may be post-processed by several XML Tools, the world of XML is open after the Zbnf2Xml translation.

## 3 Translation to another text format

Topic:.readme_BillOfMaterial..

The ZbnfParser is combined with a text generator. It can translate from one text described with the syntax to another text described with the generation script. More as one text output from the same input is possible. Especially any input text can be translated to a 'csv'-Format which can be inputted to a table calculation tool such as Microsoft Excel or Open Office Calc to show, sort and process the data.

The Batchfile or Unix shell script `billOfMaterial2Csv.bat` calls the Zbnf2Text-Conversion and produces a CSV file named `result/billOfMaterial.csv`.

## 4 Evaluation with Java

Topic:.readme_BillOfMaterial..

The Example contains some Java source files in srcJava/org/vishia/zbnf/example/billOfMaterial/. This source files should be compiled for example in an Eclipse environment. Use the other sources from ../../srcJava_Zbnf/ and ../../srcJava_vishiaBase/. The Java-example executes the parsing like above. The parse result is written then in an instance of type `BillOfMaterialZbnf_Fields` and `BillOfMaterial_Zbnf_ifc.ZbnfStore_BillOfMaterial`. The advantage is: No programming effort is neccessary to take to pieces of the ZBNF parse result and storing in a Java instance. Only proper fields (variant A) and methods (via Interface, Variant B) should be given where the javadoc-Zbnf/org/vishia/zbnf/ZbnfJavaOutput tokenizes and sets the parse result into the correct fields or call the proper methods using the Reflection-mechanism of Java.

It is an example. The example uses the capability of javadoc-vishiaBase/org/vishia/mainCmd/MainCmd, therefore the frame is more complexly as necessary for this example.

You can start that example by calling the

    srcJava/org/vishia/zbnf/example/billOfMaterial/Main/main(...)

routine with this directory as the current and with the command line argument

    -i:billOfMaterial.txt

The other way to start it: Invoke the JZcmd script interpreter with the script

    billOfMaterial2Java.bat

in this directory. You can invoke the

    srcJava_Zbnf/org/vishia/zcmd/JZcmd/main(...)

with one argument

    D:/absolute/path/to/billOfMaterial2Java.bat

Then it runs under debug and runs the same like starting the batch. You can set a breakpoint into the `billOfMaterial/Main/main(...)` and look what is happen.

The decisive methods are:

     void executeStoreFields(Args args)
     {
       /**The instance to store the data of parsing result is created locally and private visible: */
       BillOfMaterialZbnf_Fields bill = new BillOfMaterialZbnf_Fields();
       /**This call processes the whole parsing and storing action in the instance 'bill', using the type of bill.
        * It is the simple form.
        * In this basic example the data won't be used never, therefore please set a breakpoint here
        * and check the data manually.
        */
       String sError = ZbnfJavaOutput.parseFileAndFillJavaObject(bill.getClass(), bill, ...)

and

     void executeStoreViaMethods(Args args)
     {
       /**The instance to store the data of parsing result is created locally and private visible,
        * but it is referenced with an interface. It is possible that the instance is created somewhere other. */
       BillOfMaterial_Zbnf_ifc.ZbnfStore_BillOfMaterial bill = new BillofMaterialData_Methods();
       /**This call processes the whole parsing and storing action in the instance 'bill', using the type of bill.
        * It is the qualification form. The instance is referenced via an interface.
        * The construction of the instance' data is not depending on the syntax form.
        * Some more checks and data processing may be done in the implementation of the interface' methods.
        * In this basic example the data won't be used never, therefore please set a breakpoint here
        * and check the data manually.
        */
       String sError = ZbnfJavaOutput.parseFileAndFillJavaObject(BillOfMaterial_Zbnf_ifc.ZbnfStore_BillOfMaterial.class, bill, ...

The called routine parses and stores the result in a slide. The first version uses an instance, which follows the construction of syntax in the construction of its data. It is simple. The second version shows the usage of interfaces to store the data for a more complex evaluation.

To examine the Java evaluation you should familiar with compiling Java in an IDE like Eclipse. Set a breakpoint before the call of `parseFileAndFillJavaObject(...)` visit the stored data, change the syntax and/or storage classes. The evaluation of the data may be a typical java programming procedure.

## 5 The example contains

Topic:.readme_BillOfMaterial..

- `srcJava`: Directory with java-source `org/vishia/zbnf/example/billOfMaterial/*.java`

- `billOfMaterial.txt`: Given bill list as example.

- `billOfMaterial2xml.bat`, `billOfMaterial2csv.bat`, `billOfMaterial2java.bat`: batches (Windows, Unix) which invoke the example conversions

- `billOfMaterial.zbnf`: Syntax of the input-file for this example.

- `billOfMaterial2csv.jzcmd`: Generation script for text output conversion for this example.

- `result.reference/billOfMaterial.xml`: The result of parsing with given syntax and options.

- `result.reference/billOfMaterial.csv`: The result of parsing and conversion to csv

- `del_results.bat`, `del_results.sh`: batches (Windows, Unix) to clean results (helper).