org.simantics.databoard
Class Datatypes

java.lang.Object
  extended by org.simantics.databoard.Datatypes

public class Datatypes
extends java.lang.Object

This class is a facade to the data type services.

Author:
Hannu Niemisto, Toni Kalajainen

Field Summary
static BooleanType BOOLEAN
           
static ArrayType BOOLEAN_ARRAY
           
static ByteType BYTE
           
static ArrayType BYTE_ARRAY
           
static DataTypeRepository datatypeRepository
           
static DoubleType DOUBLE
           
static ArrayType DOUBLE_ARRAY
           
static FloatType FLOAT
           
static ArrayType FLOAT_ARRAY
           
static IntegerType INTEGER
           
static ArrayType INTEGER_ARRAY
           
static LongType LONG
           
static ArrayType LONG_ARRAY
           
static StringType STRING
           
static VariantType VARIANT
           
static Datatype VOID
           
 
Constructor Summary
Datatypes()
           
 
Method Summary
static void addDatatype(java.lang.String name, Datatype type)
          Adds a type to the repository.
static void addDefinitions(java.lang.String definitions)
          Parses and adds type definitions to the repository.
static
<T extends Datatype>
T
getDatatype(java.lang.Class<?> clazz)
          Read representation from a class.
static Datatype getDatatype(java.lang.String name)
          Get data type by name.
static
<T extends Datatype>
T
getDatatypeUnchecked(java.lang.Class<?> clazz)
          Read representation from a class.
static Datatype translate(java.lang.String typeString)
          Parses an unnamed data type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN

public static final BooleanType BOOLEAN

BYTE

public static final ByteType BYTE

INTEGER

public static final IntegerType INTEGER

LONG

public static final LongType LONG

FLOAT

public static final FloatType FLOAT

DOUBLE

public static final DoubleType DOUBLE

STRING

public static final StringType STRING

VARIANT

public static final VariantType VARIANT

VOID

public static final Datatype VOID

BOOLEAN_ARRAY

public static final ArrayType BOOLEAN_ARRAY

BYTE_ARRAY

public static final ArrayType BYTE_ARRAY

INTEGER_ARRAY

public static final ArrayType INTEGER_ARRAY

LONG_ARRAY

public static final ArrayType LONG_ARRAY

FLOAT_ARRAY

public static final ArrayType FLOAT_ARRAY

DOUBLE_ARRAY

public static final ArrayType DOUBLE_ARRAY

datatypeRepository

public static final DataTypeRepository datatypeRepository
Constructor Detail

Datatypes

public Datatypes()
Method Detail

getDatatype

public static <T extends Datatype> T getDatatype(java.lang.Class<?> clazz)
                                      throws DatatypeConstructionException
Read representation from a class. DataType details and parameters are read as annotations placed in the class. (See org.simantics.databoard.annotations)

As an exception, in the subclasses of Throwable, the fields of Throwable are omited.

Parameters:
clazz -
Returns:
data type
Throws:
DatatypeConstructionException
See Also:
ClassBindingFactory

getDatatypeUnchecked

public static <T extends Datatype> T getDatatypeUnchecked(java.lang.Class<?> clazz)
                                               throws RuntimeDatatypeConstructionException
Read representation from a class. DataType details and parameters are read as annotations placed in the class. (See org.simantics.databoard.annotations)

This method is used when the caller is 100% sure that binding will be constructed without exceptions. Such classes are all primitive types (Double, Integer, etc, arrays, DataType, ...) This method is unchecked if binding construction to the clazz cannot be trusted. If construction fails, a RuntimeException is thrown.

Parameters:
clazz -
Returns:
data type
Throws:
RuntimeDatatypeConstructionException
See Also:
ClassBindingFactory

addDatatype

public static void addDatatype(java.lang.String name,
                               Datatype type)
Adds a type to the repository.

Parameters:
name - Name of the type
type - Type to be added

getDatatype

public static Datatype getDatatype(java.lang.String name)
Get data type by name. e.g. get("Vec2");

Parameters:
name -
Returns:
data type

addDefinitions

public static void addDefinitions(java.lang.String definitions)
                           throws DataTypeSyntaxError
Parses and adds type definitions to the repository. The data type can be acquired with #getType e.g. "type Vec2 = { x : Double, y : Double }"

Parameters:
definitions - Definitions in textual format.
Throws:
DataTypeSyntaxError

translate

public static Datatype translate(java.lang.String typeString)
                          throws DataTypeSyntaxError
Parses an unnamed data type. Datatype Notation e.g. "{ direction : Vec, vector : Vec2 }"

Parameters:
typeString - The textual representation of the type to be translated
Returns:
Translated data type
Throws:
DataTypeSyntaxError