Data Type Table

Description

A data type table defines an OpenL Tablets data carrier. Using data types inside the OpenL Tablets rules is recommended, since using data types created in OpenL Tablets table from Java code is limited in the current implementation. For Java code, the preferable method is to use Java or Vocabulary type. For information on how this is done, see Data Table.

The following is an example of a data type table defining a data type called Person:

Figure 20: Data type table

The first row is the header containing the keyword 'Datatype' followed by the name of the data type. Every row, beginning with the second one, represents one property of the data type. The first column contains property types; the second column contains corresponding property names.

There is an optional 3rd column, that defines default values for fields. The following example extends the type Person with default values for some fields:

Figure 21: Data type table with default values

Fields ‘gender’ and ‘male’ will have the given values for all newly created instances, if other values won`t be provided.

How OpenL handles Datatypes inside

Datatypes tables are being processed second after Properties Table it is done to build a domain model that is used in rules.

Datatype header format:

[Datatype <typename>] or [Datatype <typename> extends <parentTypeName>] or [Datatype <typename> <aliastype>]

Datatype lifecycle

1.Define datatype table in Excel

2.At runtime for each datatype, java class is being generated (see Byte code generation at runtime)

3.If it was used the Generating a Static Wrapper and the goal ‘generate datatypes’ was called, the appropriate java files will be added to classpath (see Java files generation)

Inheritance in Datatypes

There is possibility to inherit one datatype from another in OpenL Tablets. New datatype that inherits another will have access to all fields defined in parent datatype. If child datatype contains fields that defined in parent you will get warnings or errors (if field declared with different types in child and parent).

Also constructor with all fields of child datatype will contains all fields from parent fields and toString, equals and hashCode methods will use all fields form parent datatype.

Byte code generation at runtime

At runtime, when Openl engine instance is being built, for each datatype component java byte code is being generated in case there are no previously generated java files on classpath (see Java files generation) it represents simple java bean for this datatype. This byte code is being loaded to classloader so the object of type Class<?> can be accessible. Using this object through reflections new instances are being created and fields of datatypes are being initialized (see DatatypeOpenClass and DatatypeOpenField classes). Remember! If you have previously generated java files for your datatypes on classpath, they will be used at runtime. And it doesn`t matter that you have made any changes in Excel. To apply these changes, remove java files and run Generating a Static Wrapper.

Java files generation

As generation of datatypes is performed on runtime and users can`t access this classes in their code, so to the JavaWrapperAntTask was added a goal "generate datatypes". It adds the possibility of generation java files and putting it to the file system. So users can use this types in their code.

Access datatype at runtime and after building OpenL wrapper

After parsing, each datatype is put to compilation context, so it will be accessible for rules during binding. Also all datatypes are placed to IOpenClass of whole module and will be accessible from CompiledOpenClass#getTypes when Openl wrapper will be generated.

Each TableSyntaxNode that is of type xls.datatype contains an object of datatype as its member.

Working with Datatype arrays from rules

There are 2 possibilities to work with Datatype arrays from rules: