public class TLcdXMLDataModelBuilder extends Object
Class that builds TLcdDataModel
s based on XML schemas. The main responsibility of this class is
to create a data model that maps on the types of an XML schema. Data models created by this
builder are annotated with TLcdXMLSchemaMappingAnnotation
and TLcdXMLSchemaTypeMappingAnnotation
.
The following example shows a typical usage of creating a data model from an XML schema, with some customizations:
TLcdXMLDataModelBuilder xmlBuilder = new TLcdXMLDataModelBuilder();
TLcdDataModelBuilder dataModelBuilder = new TLcdDataModelBuilder( "sample" );
xmlBuilder.buildDataModel( dataModelBuilder, "http://www.luciad.com/samples.xml.customdomainclasses",
Main.class.getResource( "/samples/xml/customdomainclasses/samples.xml.customdomainclasses.xsd" ).toString() );
dataModelBuilder.typeBuilder( "_Model" ).instanceClass( Model.class );
dataModelBuilder.typeBuilder( "AddressType" ).instanceClass( Address.class );
TLcdDataModel dataModel = dataModelBuilder.createDataModel();
Note that this XML builder may override any settings that were already configured on the data model builder
before it is passed to the XML builder. It is strongly advised to perform all customizations of the data model
(e.g. configuration instance classes of types, as in the above example) after it has been
configured by the XML builder.
An XML schema is mapped on a data model according to the following rules.
TLcdDataType.isDataObjectType()
),
simple types on primitive types (see TLcdDataType.isPrimitive()
).TLcdDataProperty.CollectionType.LIST
).xsd:anyType
is ILcdDataObject, for xsd:anySimpleType
String.class.
Next to these basic rules, there are a number of additional rules to handle special cases.
TLcdCoreDataTypes.OBJECT_TYPE
.
type
" is added to carry this information.
The type of this property is TLcdXMLBuiltInDataTypes.QName
.
Object.class
. It typically contains TLcdXLinkSimpleLink
instances.
The second property (called 'linkedObject') is also of type Object.class
. This property will
be populated during XLink resolution with the object to which the XLink points.
Instances of this class are not thread safe.
Constructor and Description |
---|
TLcdXMLDataModelBuilder(ILcdXMLSchemaTypeMapping aSchemaTypeMapping)
Creates a new XML data model builder.
|
TLcdXMLDataModelBuilder(TLcdDataModel... aDataModels)
Creates a new XML data model builder.
|
Modifier and Type | Method and Description |
---|---|
void |
buildDataModel(TLcdDataModelBuilder aModelBuilder,
String aSystemId)
Builds all types for the given model builder based on the schema located at the
given system id.
|
void |
buildDataModel(TLcdDataModelBuilder aModelBuilder,
String aPublicId,
String aSystemId)
Builds all types for the given model builder based on the schema located at the
given system id.
|
protected void |
buildType(TLcdDataTypeBuilder aTypeBuilder,
TLcdXMLSchemaTypeIdentifier aTypeId)
Builds the type for the given XML type identifier.
|
TLcdDataModel |
createDataModel(String aPublicId,
String aSystemId)
Creates a data model that maps on the schema with the given public id and system id.
|
TLcdDataModel |
createDataModel(String aName,
String aPublicId,
String aSystemId)
Creates data model for the schema with the given public id and system id.
|
static TLcdDataTypeBuilder |
createDataObjectTypeForPrimitiveType(TLcdDataModelBuilder aBuilder,
TLcdDataTypeBuilder aPrimitiveType)
Builds a data object type for the given primitive type.
|
static TLcdDataType |
getDataObjectTypeForPrimitiveType(TLcdDataType aPrimitiveType)
In some cases, certain simple XML schema types have to be represented by two types:
one primitive type and one data object type.
|
EntityResolver2 |
getEntityResolver()
Returns the entity resolved that is used to resolve the schemas.
|
ILcdXMLSchemaTypeMapping |
getSchemaTypeMapping()
Returns the schema type mapping associated with this data model builder.
|
protected TLcdDataTypeBuilder |
getTypeBuilder(TLcdDataModelBuilder aBuilder,
TLcdXMLSchemaTypeIdentifier aTypeId)
Returns the type builder for a given XML schema type.
|
void |
setEntityResolver(EntityResolver2 aEntityResolver)
Sets the entity resolver that is used to resolve the schemas.
|
public TLcdXMLDataModelBuilder(TLcdDataModel... aDataModels)
aDataModels
- a list of referenced data modelspublic TLcdXMLDataModelBuilder(ILcdXMLSchemaTypeMapping aSchemaTypeMapping)
aSchemaTypeMapping
- the type mapping that is used to resolve XML schema types withpublic TLcdDataModel createDataModel(String aPublicId, String aSystemId)
Creates a data model that maps on the schema with the given public id and system id. Note that creation of the data model may trigger creation of dependent data models. This occurs when for a certain dependent data model no mapping was given when this object was constructed. The name of the returned data model will be equal to the given public id.
The public identifier, also known as namespace URI, is the globally unique name to identify the schema, and should be a valid URI (e.g. 'http://www.opengis.net/gml/3.2' for the GML schema). The system id points to a resource, usually in the classpath, on the local system, or on the Internet, where the schema can be found (e.g. 'net/opengis/gml/3.2.1/gml.xsd' for a GML schema in the classpath).
Note that the given public id can be null
. In that case,
the name of the returned data model will be equal to the target name
space of the schema with the given system id.
The EntityResolver2
instance of this builder is used to map the schema (public id / system id)
to an InputSource that can be decoded and interpreted by this builder.
aPublicId
- the public id (namespaceURI) of the schema for which a data model is to be builtaSystemId
- the system id (location) of the schema for which a data model is to be builtsetEntityResolver(org.xml.sax.ext.EntityResolver2)
public TLcdDataModel createDataModel(String aName, String aPublicId, String aSystemId)
Creates data model for the schema with the given public id and system id. Note that creation of the data model may trigger creation of dependent data models. This occurs when for a certain dependent data model no mapping was given when this object was constructed.
The public identifier, also known as namespace URI, is the globally unique name to identify the schema, and should be a valid URI (e.g. 'http://www.opengis.net/gml/3.2' for the GML schema). The system id points to a resource, usually in the classpath, on the local system, or on the Internet, where the schema can be found (e.g. 'net/opengis/gml/3.2.1/gml.xsd' for a GML schema in the classpath).
Note that the given public id can be null
. In that case,
the name of the returned data model will be equal to the target name
space of the schema with the given system id.
The EntityResolver2
instance of this builder is used to map the schema (public id / system id)
to an InputSource that can be decoded and interpreted by this builder.
aName
- the name of the data model that is to be builtaPublicId
- the public id (namespaceURI) of the schema for which a data model is to be built.aSystemId
- the system id (location) of the schema for which a data model is to be builtsetEntityResolver(org.xml.sax.ext.EntityResolver2)
public EntityResolver2 getEntityResolver()
setEntityResolver(EntityResolver2)
public void setEntityResolver(EntityResolver2 aEntityResolver)
The EntityResolver2
is responsible for mapping the schema identifier, either public
or system id, to an InputSource that can be decoded and interpreted by this builder.
aEntityResolver
- the entity resolver that is to be used to resolve the XML schemasgetEntityResolver()
public void buildDataModel(TLcdDataModelBuilder aModelBuilder, String aSystemId)
This builder may override any settings that were already configured on aModelBuilder
.
It's strongly advised to perform all customizations of the data model (e.g. configuring instance
classes of types) after this method has been called.
The EntityResolver2
instance of this builder is used to map the schema (public id / system id)
to an InputSource that can be decoded and interpreted by this builder.
aModelBuilder
- the model builder for which to create all the typesaSystemId
- the system id (location) of the schema to buildsetEntityResolver(org.xml.sax.ext.EntityResolver2)
public void buildDataModel(TLcdDataModelBuilder aModelBuilder, String aPublicId, String aSystemId)
This builder may override any settings that were already configured on aModelBuilder
.
It's strongly advised to perform all customizations of the data model (e.g. configuring instance
classes of types) after this method has been called.
The public identifier, also known as namespace URI, is the globally unique name to identify the schema, and should be a valid URI (e.g. 'http://www.opengis.net/gml/3.2' for the GML schema). The system id points to a resource, usually in the classpath, on the local system, or on the Internet, where the schema can be found (e.g. 'net/opengis/gml/3.2.1/gml.xsd' for a GML schema in the classpath).
The EntityResolver2
instance of this builder is used to map the schema (public id / system id)
to an InputSource that can be decoded and interpreted by this builder.
aModelBuilder
- the model builder for which to create all the typesaPublicId
- the public id (namespace) of the schema to buildaSystemId
- the system id (location) of the schema to buildsetEntityResolver(org.xml.sax.ext.EntityResolver2)
protected TLcdDataTypeBuilder getTypeBuilder(TLcdDataModelBuilder aBuilder, TLcdXMLSchemaTypeIdentifier aTypeId)
TLcdDataTypeBuilder
.aBuilder
- the data model builder that can be used to create the type builderaTypeId
- the identifier of the XML schema type for which the type builder is to be returnedbuildType(TLcdDataTypeBuilder, TLcdXMLSchemaTypeIdentifier)
protected void buildType(TLcdDataTypeBuilder aTypeBuilder, TLcdXMLSchemaTypeIdentifier aTypeId)
aTypeBuilder
- the type builder for the type that is to be builtaTypeId
- the XML type identifier of the type that is to be builtpublic ILcdXMLSchemaTypeMapping getSchemaTypeMapping()
public static TLcdDataType getDataObjectTypeForPrimitiveType(TLcdDataType aPrimitiveType)
aPrimitiveType
- a primitive type representing a simple schema type for which to return the corresponding data object typecreateDataObjectTypeForPrimitiveType(TLcdDataModelBuilder, TLcdDataTypeBuilder)
public static TLcdDataTypeBuilder createDataObjectTypeForPrimitiveType(TLcdDataModelBuilder aBuilder, TLcdDataTypeBuilder aPrimitiveType)
aBuilder
- the data model builder for the data modelaPrimitiveType
- a builder for the primitive type for which a data object type is to be createdgetDataObjectTypeForPrimitiveType(TLcdDataType)