public static final class DataType.Builder extends Object implements AutoCloseable
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 and Description |
---|
Builder(DataType.Builder other) |
Modifier and Type | Method and Description |
---|---|
DataType.Builder |
addAnnotation(DataAnnotation annotation)
The annotation to add to the data type under construction.
|
DataType.Builder |
addAnnotation(IDataAnnotationFactory annotationFactory)
Adds an annotation factory that is invoked when build is called.
|
DataType.Builder |
addProperty(DataProperty property)
The property to add to the data type under construction.
|
DataType |
build()
Build the data type, including the properties and annotations that were added to this builder.
|
void |
close() |
protected void |
finalize() |
DataType.Builder |
name(String name)
The name of the new data type.
|
public Builder(@NotNull DataType.Builder other)
public void close()
close
in interface AutoCloseable
@NotNull public DataType build() throws IllegalStateException
After calling this function, this builder should no longer be used.
IllegalStateException
- If not all mandatory parameters are set.@NotNull public DataType.Builder addProperty(@NotNull DataProperty property)
property
- the property to add to the data type under construction.@NotNull public DataType.Builder addAnnotation(@NotNull DataAnnotation annotation) throws NullPointerException
annotation
- the annotation to add to the data type under construction.NullPointerException
- when a null
value is passed.@NotNull public DataType.Builder addAnnotation(@NotNull IDataAnnotationFactory annotationFactory) throws NullPointerException
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();
annotationFactory
- the factory object.NullPointerException
- when a null
value is passed.@NotNull public DataType.Builder name(@NotNull String name)
Calling this function is mandatory.
name
- name of the new data type.