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:
Toni Kalajainen, Hannu Niemisto

Field Summary
static DataTypeRepository datatypeRepository
           
 
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 DataType getDataType(java.lang.Class<?> clazz)
          Read representation from a class.
static DataType getDataType(java.lang.String name)
          Get data type by name.
static DataType 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

datatypeRepository

public static final DataTypeRepository datatypeRepository
Constructor Detail

DataTypes

public DataTypes()
Method Detail

getDataType

public static DataType 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:
ReflectionBinding

getDataTypeUnchecked

public static DataType 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:
ReflectionBinding

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