public final class TLcdDataType extends Object implements ILcdAnnotatedElement
A representation of the type of a data object. A type describes the structure of a data object as a list of properties. Each of these properties is itself of a certain type.
A type always has a super type. The only exception to this rule is the Object
type, which has no super type. A type (recursively) inherits all properties from its super type.
A type can't redefine these inherited properties, they are always inherited as is.
A type is either a primitive type or a data object type. Primitive types are types which have no
internal structure (no properties) and typically represent simple objects such as strings,
numbers, dates etc. All primitive types either extend from another primitive type or directly from
. All data object types either extend
from another data object type or from TLcdCoreDataTypes.OBJECT_TYPE
.TLcdCoreDataTypes.DATA_OBJECT_TYPE
Types are always defined in the context of a TLcdDataModel
. Within
a certain data model, types are uniquely defined by their name. As such, two types
are equal if their data models are equal and they have the same name.
Types are mapped directly onto Java classes. This is a many-to-one mapping; each type is mapped on one Java class, but the same Java class can be represented by different types. Instances of a type are always instances of the type's Java class.
New types can be defined by first creating a TLcdDataModelBuilder
and then defining types within that data
model using TLcdDataTypeBuilder
. See TLcdDataModelBuilder
for a brief example.
Existing types can be retrieved via the TLcdDataModel
in which they are defined.
Instances of this class are thread safe. Once an instance has been created, there is no public API to modify it. The only exception is the annotations and these are thread safe.
TLcdDataModel
,
TLcdDataModelBuilder
,
TLcdDataTypeBuilder
Modifier and Type | Method and Description |
---|---|
<T extends ILcdAnnotation> |
addAnnotation(ILcdAnnotation aAnnotation)
Adds the given annotation to this element.
|
boolean |
equals(Object obj) |
<T extends ILcdAnnotation> |
getAnnotation(Class<T> aAnnotationType)
Returns the element's annotation for the specified class if such an annotation is present,
else null.
|
Collection<ILcdAnnotation> |
getAnnotations()
Returns all annotations present on this element as an unmodifiable collection.
|
TLcdDataModel |
getDataModel()
Returns the data model that defines this type.
|
List<TLcdDataProperty> |
getDeclaredProperties()
Returns the list of all properties that are declared on this type.
|
TLcdDataProperty |
getDeclaredProperty(String aPropertyName)
Returns the first property in the list of declared properties with the given name.
|
String |
getDisplayName()
Returns a displayable name for this type, suitable for usage in user interfaces.
|
String |
getDisplayName(Object aValue)
Returns a displayable name for the specified value of this type, suitable for usage in user
interfaces.
|
Class<?> |
getInstanceClass()
Returns the Java class onto which instances of this type are mapped.
|
String |
getName()
Returns the name of this type.
|
Set<?> |
getPossibleValues()
Returns a collection containing all possible instances for this type.
|
List<TLcdDataProperty> |
getProperties()
Returns a (unmodifiable) list of all properties of this type.
|
TLcdDataProperty |
getProperty(String aPropertyName)
Returns a property in the list of properties with the given name.
|
TLcdDataType |
getSuperType()
Returns the super type from which this type inherits.
|
boolean |
hasDeclaredProperty(TLcdDataProperty aProperty)
Determines if the given property has been declared by this data type.
|
int |
hashCode() |
boolean |
hasProperty(TLcdDataProperty aProperty)
Determines if the given property is a property of this data type, including properties inherited from supertypes.
|
boolean |
isAbstract()
Returns if this type is abstract.
|
boolean |
isAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType)
Returns true if an annotation for the specified class is present on this element,
else false.
|
boolean |
isAssignableFrom(TLcdDataType aType)
Determines if the type represented by this
TLcdDataType object is either the same as, or is a superclass of,
the type represented by the specified
TLcdDataType parameter. |
boolean |
isDataObjectType()
Returns if this type is a data object type.
|
boolean |
isEnumeration()
Returns if this type is an enumeration type.
|
boolean |
isInstance(Object aObject)
Returns if the given object is an instance of this type.
|
boolean |
isPrimitive()
Returns if this type is a primitive type.
|
ILcdDataObject |
newInstance()
Creates a new instance of this type.
|
<T extends ILcdAnnotation> |
removeAnnotation(Class<T> aAnnotationClass)
Removes the annotation of the given class from this element.
|
String |
toString() |
public TLcdDataType getSuperType()
null
for the
TLcdCoreDataTypes.OBJECT_TYPE
.public List<TLcdDataProperty> getDeclaredProperties()
getProperties()
public Class<?> getInstanceClass()
public TLcdDataModel getDataModel()
public String getName()
public List<TLcdDataProperty> getProperties()
Returns a (unmodifiable) list of all properties of this type. This list is the union of getSuperType().getProperties() and getDeclaredProperties().
getDeclaredProperties()
public TLcdDataProperty getDeclaredProperty(String aPropertyName)
null
is returned.aPropertyName
- the name of the property that should be returned. Property names are case sensitivepublic TLcdDataProperty getProperty(String aPropertyName)
null
is returned.aPropertyName
- the name of the property that should be returned. Property names are case sensitivepublic boolean isAbstract()
IllegalArgumentException
being thrown.public boolean isPrimitive()
Returns if this type is a primitive type. Primitive types never have properties and are
not assignable from TLcdCoreDataTypes.DATA_OBJECT_TYPE
. A type is either
a primitive type or a data object type. The only exception to this rule is
TLcdCoreDataTypes.OBJECT_TYPE
which is neither primitive
nor data object type.
Most primitive types don't allow the creation of new instances using the newInstance()
method. This is typically because instances can't be created using a default constructor
(think for instance of String, Integer, etc.).
public boolean isDataObjectType()
Returns if this type is a data object type. Data object types are by definition
assignable from TLcdCoreDataTypes.DATA_OBJECT_TYPE
. A type is either
a primitive type or a data object type. The only exception to this rule is
TLcdCoreDataTypes.DATA_OBJECT_TYPE
which is neither primitive
nor data object type.
New instances of data object types can be created using the
newInstance()
method.
public boolean isInstance(Object aObject)
Returns if the given object is an instance of this type.
aObject
- the object to be checkedboolean
value indicating whether the object
aObject is an instance of this typepublic boolean isAssignableFrom(TLcdDataType aType)
Determines if the type represented by this
TLcdDataType
object is either the same as, or is a superclass of,
the type represented by the specified
TLcdDataType
parameter. It returns true
if so;
otherwise it returns false
.
This is very much similar to Class.isAssignableFrom(Class)
.
aType
- the type
object to be checkedboolean
value indicating whether instances of the
type aType
can be assigned to instances of this typepublic ILcdDataObject newInstance()
Creates a new instance of this type.
Note that this is only supported for data object types. There is no generic mechanism to create a new instance of a primitive type. This is because many of the primitive types are immutable (for instance String, Double, etc.) and as such require additional arguments to create an instance.
IllegalArgumentException
- in case the type is abstract or a primitive typepublic boolean isEnumeration()
public <T extends ILcdAnnotation> T getAnnotation(Class<T> aAnnotationType)
ILcdAnnotatedElement
Returns the element's annotation for the specified class if such an annotation is present, else null.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
null
is returned.
getAnnotation
in interface ILcdAnnotatedElement
aAnnotationType
- - the Class object corresponding to the annotation typepublic boolean isAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType)
ILcdAnnotatedElement
Returns true if an annotation for the specified class is present on this element, else false. This method is designed primarily for convenient access to marker annotations.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
false
is returned.
isAnnotationPresent
in interface ILcdAnnotatedElement
aAnnotationType
- the Class object corresponding to the annotation classpublic Collection<ILcdAnnotation> getAnnotations()
ILcdAnnotatedElement
getAnnotations
in interface ILcdAnnotatedElement
public <T extends ILcdAnnotation> T addAnnotation(ILcdAnnotation aAnnotation)
ILcdAnnotatedElement
addAnnotation
in interface ILcdAnnotatedElement
aAnnotation
- the annotation to addpublic <T extends ILcdAnnotation> T removeAnnotation(Class<T> aAnnotationClass)
ILcdAnnotatedElement
Removes the annotation of the given class from this element.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
nothing is removed and null
is returned.
removeAnnotation
in interface ILcdAnnotatedElement
aAnnotationClass
- the class of annotation to removepublic Set<?> getPossibleValues()
null
is returned.public String getDisplayName()
ILcdDataModelDisplayNameProvider
public String getDisplayName(Object aValue)
aValue.toString()
will be returned.aValue
- a value within the value domain of this type.aValue
.NullPointerException
- if aValue == null
.IllegalArgumentException
- if aValue
is not within this type's value domain.ILcdDataModelDisplayNameProvider
public final boolean hasProperty(TLcdDataProperty aProperty)
aProperty
- the property to validatepublic final boolean hasDeclaredProperty(TLcdDataProperty aProperty)
aProperty
- the property to validate