Package com.luciad.datamodels
Class DataType.Builder
java.lang.Object
com.luciad.datamodels.DataType.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
DataType
Builder
that allows DataType
instances to be created.
Typical usage would be create a DataType.Builder
using DataType#newBuilder
, specifying the data type's name. Then add the necessary DataProperty(s) and finally build()
the data type. The following snippet shows how this is done for a simple example data type:
return DataType.newBuilder()
.name("TestDataType")
.addProperty(TestFeatureModelFactory.SomeProperty)
.addProperty(geometryProperty)
.addAnnotation(new GeometryDataAnnotationFactory(geometryProperty))
.build();
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation
(DataAnnotation annotation) The annotation to add to the data type under construction.addAnnotation
(IDataAnnotationFactory annotationFactory) Adds an annotation factory that is invoked when build is called.addProperty
(DataProperty property) The property to add to the data type under construction.build()
Build the data type, including the properties and annotations that were added to this builder.void
close()
protected void
finalize()
The name of the new data type.
-
Constructor Details
-
Builder
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
build
Build the data type, including the properties and annotations that were added to this builder.After calling this function, this builder should no longer be used.
- Returns:
- the data type.
- Throws:
IllegalStateException
- If not all mandatory parameters are set.
-
addProperty
The property to add to the data type under construction.- Parameters:
property
- the property to add to the data type under construction.- Returns:
- this builder.
-
addAnnotation
@NotNull public DataType.Builder addAnnotation(@NotNull DataAnnotation annotation) throws NullPointerException The annotation to add to the data type under construction.- Parameters:
annotation
- the annotation to add to the data type under construction.- Returns:
- this builder.
- Throws:
NullPointerException
- when anull
value is passed.
-
addAnnotation
@NotNull public DataType.Builder addAnnotation(@NotNull IDataAnnotationFactory annotationFactory) throws NullPointerException Adds an annotation factory that is invoked when build is called.The factory is provided with the type that is being built. This can be useful when the created annotation needs access to the type, for instance when the annotation requires a
DataPropertyPath
.An example usage is:
public static final class GeometryDataAnnotationFactory implements IDataAnnotationFactory { private final DataProperty property; public GeometryDataAnnotationFactory(DataProperty property) { this.property = property; } @Override public DataAnnotation createAnnotation(DataType dataType) { return new GeometryDataAnnotation(DataPropertyPath.newBuilder().originType(dataType).property(property).build()); } }
DataProperty geometryProperty = DataProperty.newBuilder().name("geometry").valueType(DataType.getGeometryType()).build(); DataType dataType = DataType.newBuilder() .name("MyType") .addProperty(geometryProperty) .addAnnotation(new GeometryDataAnnotationFactory(geometryProperty)) .build();
- Parameters:
annotationFactory
- the factory object.- Returns:
- this builder.
- Throws:
NullPointerException
- when anull
value is passed.
-
name
The name of the new data type.Calling this function is mandatory.
- Parameters:
name
- name of the new data type.- Returns:
- this builder.
-