public class TLcdDataModelBuilder extends Object
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.
Modifier and Type | Class and Description |
---|---|
static interface |
TLcdDataModelBuilder.DataModelAnnotationFactory<T extends ILcdAnnotation>
This factory interface offers a convenient way to annotate a data model while it is being
built.
|
Constructor and Description |
---|
TLcdDataModelBuilder(String aName)
Creates a new builder with the given name.
|
TLcdDataModelBuilder(String aName,
ILcdDataObjectFactory aFactory)
Creates a new builder with the given name and
ILcdDataObjectFactory . |
Modifier and Type | Method and Description |
---|---|
TLcdDataModelBuilder |
addDependency(TLcdDataModel aDataModel)
Adds the given data model as a dependency to the data model that this builder is building.
|
TLcdDataModelBuilder |
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.
|
TLcdDataModelBuilder |
annotate(ILcdAnnotation aAnnotation)
Adds an annotation to the data model that is being built.
|
TLcdDataModelBuilder |
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.
|
TLcdDataModel |
createDataModel()
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.
|
TLcdDataModelBuilder |
dataModelBuilder(String aModelName)
Returns the data model builder for the model with the given name.
|
TLcdDataModelBuilder |
dataModelBuilder(String aModelName,
ILcdDataObjectFactory aObjectFactory)
Returns the data model builder for the model with the given name.
|
TLcdDataModelBuilder |
displayNameProvider(ILcdDataModelDisplayNameProvider aProvider)
Sets the display name provider of the data model that is being built to the given
parameter.
|
ILcdDataObjectFactory |
getDataObjectFactory()
Returns the data object factory of this builder.
|
String |
getName()
Returns the name of the this builder.
|
String |
toString() |
TLcdDataTypeBuilder |
typeBuilder(String aName)
Returns a type builder to build a type in this data model with the given name.
|
public TLcdDataModelBuilder(String aName)
aName
- the name of the data model that is to be builtTLcdDataModelBuilder(String, ILcdDataObjectFactory)
public TLcdDataModelBuilder(String aName, ILcdDataObjectFactory aFactory)
ILcdDataObjectFactory
. 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 (see TLcdDataTypeBuilder.dataObjectFactory(ILcdDataObjectFactory)
.aFactory
- the default factory to be used when new instances are to be createdaName
- the name of the data model that is to be builtpublic String getName()
public ILcdDataObjectFactory getDataObjectFactory()
TLcdDataType.newInstance()
public TLcdDataModel createDataModel()
public TLcdDataTypeBuilder typeBuilder(String aName)
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 class TLcdDataObject
.
The name of a type can only contain letters, digits and the '_' character.
aName
- the name of the type that is to be builtIllegalArgumentException
- when the given name contains invalid characterspublic TLcdDataModelBuilder addDependency(TLcdDataModel aDataModel)
aDataModel
- the data model to add as dependencypublic TLcdDataModelBuilder addDependency(TLcdDataModelBuilder aDataModelBuilder)
aDataModelBuilder
- the data model builder to add as dependencypublic TLcdDataModelBuilder dataModelBuilder(String aModelName)
aModelName
- the name of the model that is to be createddataModelBuilder(String, ILcdDataObjectFactory)
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.
aModelName
- the name of the data model for which a builder is to be returnedaObjectFactory
- the object factory that should be used for creating instancespublic 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
using TLcdDataModel.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.
aAnnotationFactory
- a factory that is able to create the value of the annotationpublic static TLcdDataModel createAnonymousDataModel(Collection<TLcdDataModel> aDataModels)
null
) and it
will have a direct dependency on all data models that are passed as argument.aDataModels
- the data models for which an anonymous data model is to be createdpublic static TLcdDataModel createUnionDataModel(Collection<TLcdDataModel> aDataModels)
aDataModels
- a collection of data modelspublic TLcdDataModelBuilder annotate(ILcdAnnotation aAnnotation)
TLcdDataModel.getAnnotation(Class)
.aAnnotation
- the annotation to addpublic TLcdDataModelBuilder displayNameProvider(ILcdDataModelDisplayNameProvider aProvider)
aProvider
- a display name provider to use for the data model that is being built