Class TLcdDataType

java.lang.Object
com.luciad.datamodel.TLcdDataType
All Implemented Interfaces:
ILcdAnnotatedElement

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 TLcdCoreDataTypes.OBJECT_TYPE. All data object types either extend from another data object type or from 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.

Since:
10.0
See Also:
  • Method Details

    • getSuperType

      public TLcdDataType getSuperType()
      Returns the super type from which this type inherits. Only returns null for the TLcdCoreDataTypes.OBJECT_TYPE.
      Returns:
      the super type of this type
    • getDeclaredProperties

      public List<TLcdDataProperty> getDeclaredProperties()
      Returns the list of all properties that are declared on this type. This list is a sub list of all the properties of this type.
      Returns:
      the list of all properties declared on this type
      See Also:
    • getInstanceClass

      public Class<?> getInstanceClass()
      Returns the Java class onto which instances of this type are mapped. This can be an interface.
      Returns:
      the Java class of its instances
    • getDataModel

      public TLcdDataModel getDataModel()
      Returns the data model that defines this type.
      Returns:
      the data model that defines this type
    • getName

      public String getName()
      Returns the name of this type. This name is unique within the type's data model.
      Returns:
      the name of this type
    • getProperties

      public List<TLcdDataProperty> getProperties()

      Returns a (unmodifiable) list of all properties of this type. This list is the union of getSuperType().getProperties() and getDeclaredProperties().

      Returns:
      an unmodifiable list of all properties of this type
      See Also:
    • getDeclaredProperty

      public TLcdDataProperty getDeclaredProperty(String aPropertyName)
      Returns the first property in the list of declared properties with the given name. In case the type has no such property, null is returned.
      Parameters:
      aPropertyName - the name of the property that should be returned. Property names are case sensitive
      Returns:
      a declared property with the given name
    • getProperty

      public TLcdDataProperty getProperty(String aPropertyName)
      Returns a property in the list of properties with the given name. In case multiple such properties exist, returns the last one (this corresponds to the property which is declared in the most specific subtype). In case the type has no such property, null is returned.

      This method looks both at the name and source name of the properties. It returns the last property of which either of those names matches the given name.

      Parameters:
      aPropertyName - the name of the property that should be returned. Property names are case-sensitive. Both a property's name and source name are accepted.
      Returns:
      a property with the given name
    • isAbstract

      public boolean isAbstract()
      Returns if this type is abstract. Trying to create a new instance of an abstract type will result in an IllegalArgumentException being thrown.
      Returns:
      if this type is abstract
    • isPrimitive

      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.).

      Returns:
      if this type is a primitive type
    • isDataObjectType

      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.

      Returns:
      if this type is a primitive type
    • isInstance

      public boolean isInstance(Object aObject)

      Returns if the given object is an instance of this type.

      Parameters:
      aObject - the object to be checked
      Returns:
      the boolean value indicating whether the object aObject is an instance of this type
    • isAssignableFrom

      public 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).

      Parameters:
      aType - the type object to be checked
      Returns:
      the boolean value indicating whether instances of the type aType can be assigned to instances of this type
    • newInstance

      public 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.

      Returns:
      a new instance of this type
      Throws:
      IllegalArgumentException - in case the type is abstract or a primitive type
    • isEnumeration

      public boolean isEnumeration()
      Returns if this type is an enumeration type. An enumeration type is always a primitive type and has a limited number of possible instances. A typical example is a primitive type that represents a Java enumeration class.
      Returns:
      if this type is an enumeration type
    • getAnnotation

      public <T extends ILcdAnnotation> T getAnnotation(Class<T> aAnnotationType)
      Description copied from interface: 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.

      Specified by:
      getAnnotation in interface ILcdAnnotatedElement
      Parameters:
      aAnnotationType - - the Class object corresponding to the annotation type
      Returns:
      this element's annotation for the specified annotation class if present on this element, else null
    • isAnnotationPresent

      public boolean isAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType)
      Description copied from interface: 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.

      Specified by:
      isAnnotationPresent in interface ILcdAnnotatedElement
      Parameters:
      aAnnotationType - the Class object corresponding to the annotation class
      Returns:
      true if an annotation for the specified annotation class is present on this element, else false
    • getAnnotations

      public Collection<ILcdAnnotation> getAnnotations()
      Description copied from interface: ILcdAnnotatedElement
      Returns all annotations present on this element as an unmodifiable collection.
      Specified by:
      getAnnotations in interface ILcdAnnotatedElement
      Returns:
      all annotations present on this element
    • addAnnotation

      public <T extends ILcdAnnotation> T addAnnotation(ILcdAnnotation aAnnotation)
      Description copied from interface: ILcdAnnotatedElement
      Adds the given annotation to this element.
      Specified by:
      addAnnotation in interface ILcdAnnotatedElement
      Parameters:
      aAnnotation - the annotation to add
      Returns:
      the previous annotation of the same class as the given annotation associated with this element, or null if there was no annotation for that class.
    • removeAnnotation

      public <T extends ILcdAnnotation> T removeAnnotation(Class<T> aAnnotationClass)
      Description copied from interface: 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.

      Specified by:
      removeAnnotation in interface ILcdAnnotatedElement
      Parameters:
      aAnnotationClass - the class of annotation to remove
      Returns:
      the annotation of the given class that was associated with this element, or null if there was no annotation for that class.
    • getPossibleValues

      public Set<?> getPossibleValues()
      Returns a collection containing all possible instances for this type. In case the type is not an enumeration, null is returned.
      Returns:
      a collection containing all possible instances for this type
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getDisplayName

      public String getDisplayName()
      Returns a displayable name for this type, suitable for usage in user interfaces.
      Returns:
      a displayable name for the type.
      See Also:
    • getDisplayName

      public String getDisplayName(Object aValue)
      Returns a displayable name for the specified value of this type, suitable for usage in user interfaces.

      If no displayable name is available, aValue.toString() will be returned.

      Parameters:
      aValue - a value within the value domain of this type.
      Returns:
      a displayable name for aValue.
      Throws:
      NullPointerException - if aValue == null.
      IllegalArgumentException - if aValue is not within this type's value domain.
      See Also:
    • hasProperty

      public final boolean hasProperty(TLcdDataProperty aProperty)
      Determines if the given property is a property of this data type, including properties inherited from supertypes.
      Parameters:
      aProperty - the property to validate
      Returns:
      true if the given property is a property of this data type; false otherwise
      Since:
      2014.0
    • hasDeclaredProperty

      public final boolean hasDeclaredProperty(TLcdDataProperty aProperty)
      Determines if the given property has been declared by this data type.
      Parameters:
      aProperty - the property to validate
      Returns:
      true if the given property is declared in this data type; false otherwise
      Since:
      2014.0