Code Generator

The deduced framework comes with a code generator. It uses schema definitions to produce Java code that matches the defined property collection structure.

Pros and Cons

Generating code has the following advantages:

  • The object structure becomes easier to access for java developers as it is closer to the object structure they are familiar with.

Generating code has the following disadvantage:

  • The generated objects don't execute deduction rules.
  • Once generated, the object structure becomes fixed. It becomes impossible to add, modify or remove properties without regenerating the code and recompiling the application.

Command Line

The command line generator is executed with the java class : It has the following options.

usage: javagenerator
 -d,--dependencies <FILES>     List of dependent schema files required to
                               generate the current schema. Use a list of
                               file names separated by a semi-colon. The
                               files have to be in order of dependency.
                               Example :
 -h,--help                     Print this message.
 -i,--input <FILE>             Input file name. This should point to a
                               valid XML file that contains a deduced
                               schema layer. Use quotes to enter file
                               names with blank spaces. This option is
 -o,--output <FOLDER>          Output folder name where the generated
                               files will be created. If the folder
                               doesn't exist, the generator will create
                               it. This option isn't mandatory. If it
                               isn't specified, the output will be in the
                               current folder.
 -x,--ignoreXmlLoadingErrors   Ignore XML loading errors encountered while
                               loading the input file or it's
                               dependencies. Default setting is false.

For example, it can be invoked with the following pattern:

  --input custom-schema.xml 
  --dependencies dependent-schema.xml;other-schema.xml 
  --output target/generated

This will generate the files from custom-schema.xml and output it in the relative folder target/generated. Two files will also be loaded to resolve dependencies : dependent-schema.xml and other-schemal.xml.

The following example shows how to resolve files that contain spaces

  --input "custom schema.xml" 
  --dependencies "dependent schema.xml;other schema.xml" 
  --output target/generated

Generator User Interface

In order to define the schema, the generator user interface can be started with the java class : org.deduced.generator.ui.StartGeneratorApplication.

Steps to create a new schema:

  1. Use the "File -> New Schema" menu. This will create a model layer that contains the schema layer.
  2. Select the model layer and name it.
  3. Select the model layer add fill the list of dependent models with a reference to all the models that contain a schema that is required to complete the new schema.
  4. Select the schema layer and name it.
  5. Select the schema layer and create the root package.
  6. From the root package, create packages, types, instance and rules as required.
  7. Save your work using the "File -> Save As" menu.
  8. Generate the code using the "File -> Generate" menu.