A schema composition refers to a restricted set of elements taken from the model that together describe a unique entity that has no equivalent in the model. Commonly, schema compositions are used to generate schema files such as XSD files. In contrast, model compositions are used to configure the material as the basis of a subset 'transform' - for example when creating a NIEM model subset.
Define Schema Content
These steps walk you through the basic procedure of composing types in a Schema profile and show how you can restrict the content of elements to meet the message requirements.
Drag the required Class elements from the Project Browser into the 'Classes' panel. As you add a Class:
- Its ancestry is listed in the 'Inheritance' section in the middle panel
- Its attributes are listed under the 'Inheritance' section, with a blank checkbox against each one; Association and Aggregation entries are named according to the role name on the connector
- Its model structure path is shown underneath the 'Classes' panel
Any time you select a Class in the 'Classes' list, its attributes and model ancestry are listed in the 'Attributes' list. Select the checkbox against each attribute to define the elements of this type. When chosen, the attribute's type is added automatically to the schema, appearing in the 'Classes' list and the 'Schema' panel to the right.
When an attribute is unchecked, the type is not automatically removed. Types can be removed using the Class context menu. It is worth noting that each time a Class is selected, all references to the Class are displayed in the status panel, enabling you to quickly review any Class usage.
If you favor or foresee a need for inheritance in the schema you are preparing, it would make sense to begin the composition with ancestors first, then re-use these as child Classes are added. The method is not set in stone. You can switch from an inheritance model to an aggregated composition or vice-versa at any time. Here is a brief description of the provision of inheritance in the Schema Composer.
The Schema Composer offers flexibility in dealing with inheritance. For example, you can choose to aggregate selected attributes from the Class and its parent, while choosing to inherit the grandparent. However, when you choose to use inheritance, you choose to inherit the restricted form of that type as well. When an ancestor is selected in this list, the generated XML schema would show an extension element identifying this ancestor. Only one ancestor can be selected.
Click on theto validate and save your schema profile.
If there are any problems with the profile, they are identified in the status panel in the top right of the screen.
One of the common issues with schema composition is the requirement to be able to vary a type description to meet various demands of the instances a schema describes. A vehicle, for example, might be described by its brand, model and price by an element of a Truck type, but by its year, model and color by an element of a Sedan type. The issue is that we might only have one actual Vehicle Class at our disposal. To address this the Schema Composer allows you to clone the Vehicle Class and give it another name. You can then assign this version of Vehicle to any property that has Vehicle as its type. The type created is only available within the domain of the schema - the model is untouched.
To create a new definition of a type, select the Class first in the 'Classes' list, then right-click on it and choose the 'Redefine Type' option. Enter a unique name for this type and press the. You can then define or restrict this type independently, the way you would for any Class.
When the schema is generated, a single top level element representing the message is generated. The body or elements of this top level element are the Classes marked as root elements. The cardinality of these root elements can be adjusted. To mark a Class as a root element or restrict its cardinality, right-click on the Class in the list and use these context menu options:
- Set element as root - root elements form the body of the top level element representing the message / profile
- Edit root element cardinality - set the minimum and maximum number of instances
- Remove root attribute from element - removes the root mark from the Class
- Remove the selected element - delete the selected element from the schema
- Find in Project Browser - locate and highlight the element in the Project Browser
In the 'Attributes' list, right-click on a selected property and use the context menu to add, edit or remove a property restriction. Use this feature to:
- Modify the property cardinality
- Redefine the type of the property
- Enable and limit the choices available for this property
- Mark a property to be emitted as an inline element definition
- Mark a property to be emitted 'By Reference'
The cardinality of a property can be further restricted from its model counterpart, but it cannot be less restrictive. The cardinality can be changed for any root element Class and any Class property.
When a Class is redefined within the Schema Composer it creates a new type. The new type is a clone of the original, but has a name that is unique to the schema. A Payment enumeration type, for example, might be redefined as a CardPayment to better suit the schema purpose. The new type is a restriction of the original in that no new attributes can be added to it. Other properties that share this type and be similarly restricted by specifying the new type in their restriction dialog. Redefined types such as sub types can be offered as additional choice elements in the restriction of other properties.
Where specializations of a property's type are present, those subtypes will be available in the 'Restriction' dialog. When more than one specialization is selected, these will appear as choice elements in the schema. When only one is chosen, the property will exhibit this subtype in the schema.
A property type will be emitted as an inline definition when this box is checked.
A property will take the 'By reference' form when emitted in the schema. The 'By reference' form emits an inline complexType that defines a single attribute named 'ref' of type 'string'.
Property Constraints - Facets
Facets are supported in the Schema Composer Generic Profile. The sources of facets are the Tagged Values on a property. Tagged Values are recognized as facets if they name a constraining facet from the XML Schema specification; JSON validation keywords are also recognized.
Constraining Facets from XML Schema:
Validation keywords in JSON:
- Number and integer