Vocabulary Data Types
Vocabulary data types are used to define a list of possible values for a particular data type, that is, to create a vocabulary for data.
The vocabulary data type is created as follows:
-
The first row is the header.
It starts with the Datatype keyword, followed by the vocabulary data type name. The predefined data type is in angle brackets based on which the vocabulary data type is created at the end.
-
The second and following rows list values of the vocabulary data type.
The values can be of the indicated predefined data type only.
Supported Base Types
The base type specified in the angle brackets can be any non-array scalar type available in the OpenL binding context, including:
- Text types, such as String and Character
- Numeric types, both primitive and boxed, such as int/Integer, double/Double, long/Long, short/Short, byte/Byte, float/Float, BigDecimal, and BigInteger
- Boolean / boolean
- Date
- Range types, such as IntRange, DoubleRange, DateRange
- User-defined vocabulary or datatype names from the same or imported module
Array types are not allowed as the base type. For example, Datatype MyType <String[]> is rejected with an error.
Example
In the example described in Introducing Datatype Tables, the data type Person has an attribute gender of the Gender data type which is the following vocabulary data type.
| Datatype Gender <String> |
|---|
| Male |
| Female |
Example of vocabulary datatype table with String parameters
Thus, data of Gender data type can only be Male or Female.
OpenL Tablets checks all data of the vocabulary data type on whether its value is in the defined list of possible values. If the value is outside of the valid domain, or defined vocabulary, OpenL Tablets displays an appropriate error. Usage of vocabulary data types provides data integrity and allows users to avoid accidental mistakes in rules.