Class TLcdDataModelBuilder
Builder that allows TLcdDataModel
instances to be created.
A typical usage pattern would be to first create a data model builder. Then use this
data model builder to create a type builder for each type. These type builder can then
be used to set all the properties of the types. The following snippet shows how this
is done for a simple example data model:
TLcdDataModelBuilder builder = new TLcdDataModelBuilder( "Model" );
TLcdDataTypeBuilder typeBuilder = builder.typeBuilder( "Type" );
typeBuilder.addProperty( "name", TLcdCoreDataTypes.STRING_TYPE );
typeBuilder.addProperty( "addresses", TLcdCoreDataTypes.STRING_TYPE ).collectionType(List);
TLcdDataModel model = builder.createDataModel();
Once the type building phase is over,
the builder can be asked to create a data model (see createDataModel()
).
Only from that point on, the data model, all its corresponding types and properties become
accessible. At the same time, no further modifications can be done. As a result, data model,
type and property instances
are immutable. Once created, they can no longer be changed. Trying to do so
using one or more of the data model / type / property builders will
cause exceptions to be thrown.
In order to be able to create cyclic dependencies between data models, multiple data models need to be created at the same time. This is possible by creating dependent data model builders using the dataModelBuilder(String) method. When a data model is created, all data models of the dependent builders are created as well.
- Since:
- 10.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
This factory interface offers a convenient way to annotate a data model while it is being built. -
Constructor Summary
ConstructorDescriptionTLcdDataModelBuilder
(String aName) Creates a new builder with the given name.TLcdDataModelBuilder
(String aName, ILcdDataObjectFactory aFactory) Creates a new builder with the given name andILcdDataObjectFactory
. -
Method Summary
Modifier and TypeMethodDescriptionaddDependency
(TLcdDataModel aDataModel) Adds the given data model as a dependency to the data model that this builder is building.addDependency
(TLcdDataModelBuilder aDataModelBuilder) Adds the data model that is built by the given data model builder as a dependency to the data model that this builder is building.annotate
(ILcdAnnotation aAnnotation) Adds an annotation to the data model that is being built.annotateFromFactory
(TLcdDataModelBuilder.DataModelAnnotationFactory<?> aAnnotationFactory) Annotates the data model that is being built.static TLcdDataModel
createAnonymousDataModel
(Collection<TLcdDataModel> aDataModels) Creates an anonymous data model for the given collection of data models.Creates a new data model, including all types and properties that were built using this builder.static TLcdDataModel
createUnionDataModel
(Collection<TLcdDataModel> aDataModels) Returns a data model that is the union of all given data models.dataModelBuilder
(String aModelName) Returns the data model builder for the model with the given name.dataModelBuilder
(String aModelName, ILcdDataObjectFactory aObjectFactory) Returns the data model builder for the model with the given name.Sets the display name provider of the data model that is being built to the given parameter.Returns the data object factory of this builder.getName()
Returns the name of the this builder.toString()
typeBuilder
(String aName) Returns a type builder to build a type in this data model with the given name.
-
Constructor Details
-
TLcdDataModelBuilder
Creates a new builder with the given name. The data model that will be created will have the same name as the builder. To create new instances of a certain type, the implementation uses Java reflection to call either the public default constructor or the public constructor that takes a TLcdDataTypeBuilder- Parameters:
aName
- the name of the data model that is to be built- See Also:
-
TLcdDataModelBuilder
Creates a new builder with the given name andILcdDataObjectFactory
. The data model that will be created will have the same name as the builder. The factory argument defines how by default new instances of the to be created types are created. This default can be overridden by associating specific object factories with a type (seeTLcdDataTypeBuilder.dataObjectFactory(ILcdDataObjectFactory)
.- Parameters:
aName
- the name of the data model that is to be builtaFactory
- the default factory to be used when new instances are to be created
-
-
Method Details
-
getName
Returns the name of the this builder. This is by definition also the name of the data model that is being built- Returns:
- the name of this builder
-
getDataObjectFactory
Returns the data object factory of this builder. Types created by this builder will use this factory to create new instances.- Returns:
- a the data object factory of this builder
- See Also:
-
createDataModel
Creates a new data model, including all types and properties that were built using this builder. Once the data model has been built, this builder and all dependent builders will no longer support modifications.- Returns:
- a new data model containing all types and properties that were built using this builder
-
typeBuilder
Returns a type builder to build a type in this data model with the given name. When this method is called more than once with the same name, the same type builder will be returned.
The type builder returned by this method is set up to build a non-abstract type extending from
TLcdCoreDataTypes.DATA_OBJECT_TYPE
with instance classTLcdDataObject
.The name of the type can only contain letters, digits, periods ('.'), dashes ('-'), and underscores ('_').
- Parameters:
aName
- the name of the type that is to be built- Returns:
- a type builder to build a type in this data model with the given name
- Throws:
IllegalArgumentException
- when the given name contains invalid characters
-
addDependency
Adds the given data model as a dependency to the data model that this builder is building. The following data models are added automatically as dependencies by the builder.- the data model of the supertypes of the types declared in this data model
- the data model of the types of the properties of the types declared in this data model
- Parameters:
aDataModel
- the data model to add as dependency- Returns:
- this
-
addDependency
Adds the data model that is built by the given data model builder as a dependency to the data model that this builder is building. The following data models are added automatically as dependencies by the builder.- the data model of the supertypes of the types declared in this data model
- the data model of the types of the properties of the types declared in this data model
- Parameters:
aDataModelBuilder
- the data model builder to add as dependency- Returns:
- this
-
dataModelBuilder
Returns the data model builder for the model with the given name. If no such builder was created before by this builder or one of its dependent builders, a new one is created.- Parameters:
aModelName
- the name of the model that is to be created- Returns:
- the data model builder for the model with the given name
- See Also:
-
dataModelBuilder
public TLcdDataModelBuilder dataModelBuilder(String aModelName, ILcdDataObjectFactory aObjectFactory) Returns the data model builder for the model with the given name. If no such builder was created before by this builder or one of its dependent builders, a new one is created with the given object factory. The returned builder will have the same life cycle as this instance. This means that when the data model of one of the builders is created, the data models of all other builders are created as well. Using this method is typically done when mutually dependent data models are to be created.
When this method is called more than once with the same name, the same data model builder will be returned. Calling dataModelBuilder( getName() ) returns this.
Creating a data model builder in this way does not have any implications about dependencies between this data model and the data model of the returned builder. Dependencies are only created when types refer to other types or when a dependency is created manually using the
addDependency(TLcdDataModelBuilder)
method.- Parameters:
aModelName
- the name of the data model for which a builder is to be returnedaObjectFactory
- the object factory that should be used for creating instances- Returns:
- a builder that is used to create a model with the given name
-
annotateFromFactory
public TLcdDataModelBuilder annotateFromFactory(TLcdDataModelBuilder.DataModelAnnotationFactory<?> aAnnotationFactory) Annotates the data model that is being built. The actual annotation is the return value of
TLcdDataModelBuilder.DataModelAnnotationFactory.createAnnotation(TLcdDataModel)
. Once the data model is created, the annotation can be retrieved usingTLcdDataModel.getAnnotation(Class)
.The use of the factory makes it possible to refer to the data model from inside the annotation. The actual annotation value will be created at the end of the initialization of the data model.
- Parameters:
aAnnotationFactory
- a factory that is able to create the value of the annotation- Returns:
- this
-
toString
-
createAnonymousDataModel
Creates an anonymous data model for the given collection of data models. The returned data model will be an anonymous data model (its name isnull
) and it will have a direct dependency on all data models that are passed as argument.- Parameters:
aDataModels
- the data models for which an anonymous data model is to be created- Returns:
- an anonymous data model that depends on all the given data models
-
createUnionDataModel
Returns a data model that is the union of all given data models. Thus all data models in the given collection are in the set of the dependencies of the returned data model. In case there is a data model in the given collection on which all other data models in the collection depend, that data model is returned.- Parameters:
aDataModels
- a collection of data models- Returns:
- a data model that is equal to or depends on all given data models
-
annotate
Adds an annotation to the data model that is being built. The annotation can be retrieved on the data model usingTLcdDataModel.getAnnotation(Class)
.- Parameters:
aAnnotation
- the annotation to add- Returns:
- this instance
-
displayNameProvider
Sets the display name provider of the data model that is being built to the given parameter.- Parameters:
aProvider
- a display name provider to use for the data model that is being built- Returns:
- this instance
-