Home > Models

Constraints, Triggers and Functions

Facets allow you to define constraints on your Master Data in your schemas. EBX.Platform supports XML Schema facets and provides extended and programmatic facets for advanced data controls.


XML Schema Supported facets

length

min Length

max

Length

pattern

enumeration

white

Space

fraction

Digits

total

Digits

max

Inclusive

max

Exclusive

min

Inclusive

min

Exclusive

string

X

X

X

X

X

(1)

(2)

(2)

(2)

(2)

boolean

X

(1)

decimal

X

X

(1)

X

X

X

X

X

X

dateTime

X

X

(1)

X

X

X

X

time

X

X

(1)

X

X

X

X

date

X

X

(1)

X

X

X

X

anyURI

X

X

X

X

X

(1)

Name

X

X

X

X

X

(1)

(2)

(2)

(2)

(2)

integer

X

X

(1)

X

X

X

X

X

X

resource (3)

Notes:

Example:

<xs:element name="loanRate">
      <xs:simpleType>
            <xs:restriction base="xs:decimal">
                          <xs:minInclusive value="4.5"/>
                          <xs:maxExclusive value="17.5"/>
            </xs:restriction>
      </xs:simpleType>
</xs:element>

Uniqueness constraint

It is possible to define a uniqueness constraint, by using the standard XML Schema element xs:unique . This constraint indicates that a value has to be unique inside a table.

In the example below, a uniqueness constraint is defined on the publisher table, for the target field name (this means that two occurrences of the publisher table cannot have the same name):

<xs:element name="publisher">
    ...
    <xs:complexType>
        <xs:sequence>
            ...
            <xs:element name="nametype="xs:string"/>
            ...
        </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueName">
        <xs:selector xpath="."/>
        <xs:field xpath="name"/>
    </xs:unique>
</xs:element>

A uniqueness constraint has to be defined inside a table and has the following properties:

Property

Description

Mandatory

name attribute

Identifies the constraint in the schema.

Yes

xs:selector element

Indicates the table where the uniqueness applies, using a restricted XPath expression ('..' is forbidden). It can also indicate an element inside the table (without changing the meaning of the constraint).

Yes

xs:field element

Indicates the field in the context whose values must be unique, using a restricted XPath expression.

Yes

Limitations:

  1. The target of the xs:field element has to be in a table.

  2. Uniqueness constraint cannot apply if the field is inside an aggregated list.

  3. The definition of multiple xs:field elements is not supported.

Extended Facets

EBX.Platform provides additional constraints that are not specified in XML Schema, but that are useful for Master Data Management.

In order to guarantee conformance to XML Schema, those Extended Facets are defined under the element annotation/appinfo/otherFacets .

Foreign keys

A reference to a table is defined using the extended facet tableRef . The element must be of type xs:string.

Element

Description

Required

tablePath

XPath expression that specifies the target table.

Yes.

container

Reference of the instance that contains the target table.

Only if element 'branch' is defined. Otherwise, default is current instance.

branch

Reference of the branch that contains the instance container.

No, default is current home.

display

Custom display for presenting the selected foreign key in the current record and the sorted list of possible keys. Two variants can be specified:

  • Default and localized expressions. They are specified by means of the display and pattern elements, for example:

    <display>

    <pattern>Product : ${./ProductID}</pattern>

    <pattern xml:lang="fr-FR">Produit : ${./ProductID}</pattern>

    <pattern xml:lang="en-US">Product : ${./ProductID}</pattern>

    </display>

  • A JavaBean that implements the interface TableRefDisplay . It is specified by means of the attribute osd:class ; for example:

    <display osd:class="com.wombat.MyLabel"></display>

No.

filter

Specifies an additional constraint that filters the occurrences of the target table. Two types of filters are available:

  • An XPath filter is an XPath predicate in the target table context. It is specified by means of the predicate element; for example:

    <filter><predicate>type = ${../refType}</predicate></filter>

  • A programmatic filter is a JavaBean that implements the interface TableRefFilter . It is specified by means of the attribute osd:class ; for example:

    <filter osd:class="com.wombat.MyFilter"></filter>

Notes:
  • Attribute osd:class and the property predicate cannot be set simultaneously.

No.

The example below specifies a reference (foreign key) to an occurrence of catalog element.

<xs:annotation>
        <xs:appinfo>
          <osd:otherFacets>
            <osd:tableRef>
              <tablePath>../catalog</tablePath>
              <label xml:lang="en-US">Product: ${./ProductID}</label>
              <filter>
                <predicate>type = ${../refType} </predicate>
              </filter>
            </osd:tableRef>
          </osd:otherFacets>
        </xs:appinfo>
</xs:annotation>

Note: Multiple variants can be specified to the label of the tableRef. The priority of the tags is the following:

  1. display tag with a programmatic label.

  2. display tag with a localized expression.

  3. display tag with a default expression.

At runtime, the extended facet tableRef is interpreted as an enumeration whose values are formatted foreign keys. Labels may be added to key value by using labelPaths element: each label is specified by the absolute path in the content of an occurrence.

See also:

Dynamic constraints

Those facets retain the XML Schema semantics, but the value attribute is replaced by a path attribute that allows to get the value from another Master Data in the adaptation:

By means of these facets, the data model may be modified dynamically, in the adaptations.

Example:

<xs:element name="amount">
      <xs:annotation>
            <xs:appinfo>
                  <osd:otherFacets>
                                <osd:minInclusive path="/domain/Loan/Pricing/AmountMini/amount"/>
                  </osd:otherFacets>
            </xs:appinfo>
      </xs:annotation>
      ...
</xs:element>

In this example, the boundary of the facet minInclusive is not statically defined. The value of the boundary comes from the node /domain/Loan/Pricing/AmountMini/amount

FacetOResource Constraint

This facet must be defined for each resource type. It has the following attributes:

This facet has the same behavior as an enumeration facet: the values are collected by recursively listing all the files in ‘local path’ from the specified directory ‘resource type’ in the specified ‘module’ .

Example:

<xs:element  name="promotiontype="osd:resource" > 
    <xs:annotation> 
      <xs:appinfo> 
        <osd:otherFacets> 
          <osd:FacetOResource 
                osd:moduleName="wbp
                osd:resourceType="ext-images
                osd:relativePath="promotion/" /> 
        </osd:otherFacets> 
      </xs:appinfo> 
    </xs:annotation > 
</ xs:element> 

An overview of directories structures in an EBX.Platform module (J2EE Web application) is detailed in the section Modules - Structure .

excludeValue constraint

This facet verifies that an instance is different from a specified value.

Example:

<xs:element  name="roleName" > 
    <xs:annotation> 
      <xs:appinfo> 
        <osd:otherFacets> 
          <osd:excludeValue value=""> 
            <osd:defaultErrorMessage> 
              Please select address role(s). 
            </osd:defaultErrorMessage> 
          </osd:excludeValue> 
        </osd:otherFacets> 
      </xs:appinfo> 
    </xs:annotation> 
    <xs:simpleType type="xs:string"/> 
</xs:element >

In this example, the empty string is excluded from the possible values.

excludeSegment constraint

This facet verifies that an instance is not included in a segment of values. Boundaries are excluded.

Example:

<xs:element  name="zipCode"> 
    <xs:annotation> 
      <xs:appinfo> 
        <osd:otherFacets> 
          <osd:excludeSegment minValue="20000maxValue="20999"> 
            <osd:defaultErrorMessage> 
            Postal code not valid. 
            </osd:defaultErrorMessage> 
          </osd:excludeSegment> 
        </osd:otherFacets> 
      </xs:appinfo> 
    </xs:annotation> 
    <xs:simpleType  type="xs:string"/> 
</xs:element>  

In this example, values between 20000 and 20999 are excluded.

Enumeration facet filled by another node

By default, an enumeration facet is described statically in XML Schema.

The content of an enumeration facet can be filled dynamically by another node of the adaptation model.

Filling by a list

With the following information, we indicate that the content of an enumeration facet comes from the node CountryList .

<xs:annotation>
    <xs:appinfo>
      <osd:otherFacets>
        <osd:enumeration osd:path="../CountryList"/>
      </osd:otherFacets>
    </xs:appinfo>
</xs:annotation>

The node CountryList

Example:

< xs:element name="FacetEnumBasedOnList"> 
    <xs:complexType> 
      <xs:sequence> 
        <xs:element name="CountryListmaxOccurs="unbounded"> 
          <xs:simpleType> 
            <xs:restriction base="xs:string"> 
              <xs:enumeration value="DEosd:label="Allemagne"/> 
              <xs:enumeration value="ATosd:label="Autriche"/> 
              <xs:enumeration value="BEosd:label="Belgique"/> 
              <xs:enumeration value="JPosd:label="Japon"/> 
              <xs:enumeration value="KRosd:label="Corée"/> 
              <xs:enumeration value="CNosd:label="Chine"/> 
            </xs:restriction> 
          </xs:simpleType> 
        </xs:element> 
        <xs:element name="CountryChoicetype="xs:string"> 
          <xs:annotation> 
            <xs:appinfo> 
              <osd:otherFacets> 
                <osd:enumeration osd:path="../CountryList"/> 
              </osd:otherFacets> 
            </xs:appinfo> 
          </xs:annotation> 
        </xs:element> 
      </xs:sequence> 
    </xs:complexType > 
</xs:element > 


Programmatic Facets

A programmatic constraint can be added on any XML element declaration that refers to a simple type.

In order to guarantee the conformance to XML Schema, those constraints are specified under the element annotation/appinfo/otherFacets .

Programmatic constraints

A programmatic constraint is defined by a Java class that implements the interface Constraint.

Additional parameters can be defined. Consequently, the implemented Java class must conform to the JavaBean protocol. In the example below, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.

Example:

<xs:element name="amount">
        <xs:annotation>
          <xs:appinfo>
            <osd:otherFacets>
              <osd:constraint class="com.foo.CheckAmount">
                <param1>...</param1>
                <param...n>...</param...n>
              </osd:constraint>
            </osd:otherFacets>
          </xs:appinfo>
        </xs:annotation>
        ...
</xs:element>

See also:

Programmatic enumeration constraints

An enumeration constraint adds to a basic programmatic constraint the definition of an ordered list of values. Such a constraint is defined by a Java class that implements the interface ConstraintEnumeration . This facet allows to select a value from a list.

Example:

<xs:element name="amount">
        <xs:annotation>
          <xs:appinfo>
            <osd:otherFacets>
              <osd:constraintEnumeration class="com.foo.CheckAmountInEnumeration">
              <param1>...</param1>
              <param...n>...</param...n>
              </osd:constraintEnumeration>
            </osd:otherFacets>
          </xs:appinfo>
        </xs:annotation>
        ...
</xs:element>

Programmatic nomenclature constraints

A nomenclature constraint adds to a basic programmatic constraint the definition of an ordered list of value-labels (see Nomenclature). Such a constraint is defined by a Java class that implements the interface ConstraintNomenclature . This facet allows to select a value from a list.

Note that an enumeration constraint is more appropriate when display must be localized or when there are many values in the enumeration.

Example:

<xs:element  name="amount">
        <xs:annotation>
          <xs:appinfo>
            <osd:otherFacets>
              <osd:constraintNomenclature class="com.foo.CheckAmountInNomenclature">
              <param1>...</param1>
              <param...n>...</param...n>
              </osd:constraintNomenclature>
            </osd:otherFacets>
          </xs:appinfo>
        </xs:annotation>
        ...
</xs:element >

Constraint on null value

Sometimes, a value is mandatory only if some conditions are verified (for example if another field has some specific value). In this case, the standard XML Schema attribute minOccurs will not help because it is static.

For checking if a value is mandatory or not, according to its context:

  1. a programmatic constraint must be defined by a Java class (see above);

  2. this class must also implement the interface ConstraintOnNull

  3. XML Schema cardinality attributes must specify that the element is optional ( minOccurs="0" and maxOccurs="1" ).

Note: By default, constraint on null value is not checked on user input. In order to enable this check, the 'checkNullInput' property must be set and if the element is terminal, the adaptation instance must also be activated.

Example:

<xs:element  name="amountminOccurs="0maxOccurs="1>
        <xs:annotation>
          <xs:appinfo>
            <osd:otherFacets>
              <osd:constraint class="com.foo.CheckIfNull">
              <param1>...</param1>
              <param...n>...</param...n>
              </osd:constraint>
            </osd:otherFacets>
          </xs:appinfo>
        </xs:annotation>
        ...
</xs:element >

Constraints on table

A constraint on table is defined by a Java class that implements the interface ConstraintOnTable

A constraint on table can only be defined on a table node.

Additional parameters can be defined. Consequently, the implemented Java class must conform to the JavaBean protocol. In the example below, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.

Example:

<xs:element name="myTabletype="MyTableTypeminOccurs="0maxOccurs="unbounded">
   <xs:annotation>
      <xs:appinfo>
            <osd:table>
               <primaryKeys>/key</primaryKeys>
            </osd:table>
            <osd:otherFacets>
              <osd:constraint class="com.foo.checkTable">
                <param1>...</param1>
                <param...n>...</param...n>
              </osd:constraint>
            </osd:otherFacets>
      </xs:appinfo>
   </xs:annotation>
</xs:element>

Important: Regarding the validation process, constraints on tables are only checked when calling a validation report of an adaptation instance/table. This means, for performance purposes, these constraints are not checked when updates (such as occurrence insertion, deletion or modification) on tables occur. However the internal incremental validation framework will optimize the validation cost of these constraints if dependencies are defined. For more information, see performance section.

See also:

Triggers and Functions

Computed values

By default, Master Data are read and persisted in the XML repository. Nevertheless, they may be the result of a specific computation and/or access an external database (a RDBMS, a central system...).

EBX.Platform even allows to take into account other Master Data in the current adaptation context.

This is made possible by defining functions .

A function is specified in the XML Schema document by using the osd:function element (see example below).

Example:

<xs:element name="computedValue">
        <xs:annotation>
          <xs:appinfo>
            <osd:function class="com.foo.ComputeValue">
              <param1>...</param1>
              <param...n>...</param...n>
            </osd:function>
          </xs:appinfo>
        </xs:annotation>
        ...
</xs:element>

Triggers

Adaptation instances or table occurrences can be associated with methods that are automatically executed when some operations are performed: creation, update, delete, etc.

In the XML Schema document, these triggers must be declared under the annotation/appinfo element using the osd:trigger tag.

For adaptation instances triggers, we have to define, inside the osd:trigger tag, a Java class that extends the abstract class InstanceTrigger

Note that in the case of adaptation instance triggers, it is advised to define annotation/appinfo/osd:trigger tags just under the root element of the considered XML schema.

Example:

<xs:element name="rootosd:access="--">

   <xs:annotation>
       <xs:appinfo>
          <osd:trigger class="com.foo.MyInstanceTrigger">    
             <param1>...</param1> 
             <param...n>...</param...n> 
          </osd:trigger>    
       </xs:appinfo>
   </xs:annotation>

   <xs:complexType>
      <xs:sequence>
         ...
      </xs:sequence>
   </xs:complexType>

</xs:element>

For the definition of tables occurrences triggers, we have to define, inside the osd:trigger tag, a Java class that extends the abstract class TableTrigger

In the case of table occurrences triggers, it is advised to define the annotation/appinfo/osd:trigger tags just under the element describing the considered table or table type.

Examples:

On a table element:

<xs:element name="myTabletype="MyTableTypeminOccurs="0maxOccurs="unbounded">
   <xs:annotation>
      <xs:appinfo>

         <osd:table>
            <primaryKeys>/key</primaryKeys>
         </osd:table>

         <osd:trigger class="com.foo.MyTableTrigger"/>

      </xs:appinfo>
   </xs:annotation>
</xs:element>

or on a table type element:

<xs:complexType name="MyTableType">

   <xs:annotation>
       <xs:appinfo>
          <osd:trigger class="com.foo.MyTableTrigger">    
             <param1>...</param1> 
             <param...n>...</param...n> 
          </osd:trigger>    
       </xs:appinfo>
   </xs:annotation>

   <xs:sequence>
      ...
   </xs:sequence>
   
</xs:complexType>

Note that additional parameters can be defined. Consequently, the Java class implemented must conform to the JavaBean protocol. In the example above, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.

Auto incremented values

It is possible to define auto-incremented values. Auto-incremented values are only allowed inside a table, and they must be of type xs:int or xs:integer

An auto-increment is specified in the XML Schema document by using the osd:autoIncrement element under the annotation/appinfo element tag.

Example:

<xs:element name="autoIncrementedValuetype="xs:integer"> 
        <xs:annotation> 
          <xs:appinfo> 
              <osd:autoIncrement /> 
          </xs:appinfo> 
        </xs:annotation> 
</xs:element> 

There are two optional elements start and step .

Example:

< xs:element  name="autoIncrementedValuetype="xs:integer"> 
        <xs:annotation> 
          <xs:appinfo> 
              <osd:autoIncrement> 
                <start>100</start> 
                <step>5</step> 
              </osd:autoIncrement> 
          </xs:appinfo> 
        </xs:annotation> 
</xs:element> 

The start attribute specifies the first value for this auto-increment. If this attribute is not specified, then the value 1 is set by default.

The step attribute specifies the step for the next value to be generated by the auto-increment. If this attribute is not specified, then the value 1 is set by default.

A field specifying an osd:autoIncrement has the following behaviour:

Internally, the auto-increment value is stored in 'Auto Increments' table of ebx-repository adaptation. This field is automatically updated, so that it defines the greatest value ever set on the associated osd:autoIncrement field, in any instance and any branch in the repository. This value is computed, taking into account the max value found in the table being updated.

In some particular case, for example when multiple environments have to be managed (development, test, production), each having different auto-increment ranges, it may be required to avoid this "max value" check. This particular behavior can be achieved, thanks to the disableMaxTableCheck property:

Note that it is generally not recommended to enable this property, as this could generate conflicts in the auto-increment values.

User Input Control

Check null input

According to EBX.Manager default validation policy, in order to allow a temporary incomplete input, the control whether an element is defined when it is mandatory is not performed on user input, but on adaptation validation only. If the 'mandatory feature' must be checked immediately on user input, the element must additionally specify: osd:checkNullInput="true" .

Note: A value is mandatory if the schema specifies that the element is mandatory, either statically ( minOccurs="1") or dynamically (by means of a Constraint on null). For terminal elements mandatory values are checked only for an activated adaptation instance. For not terminal elements the adaptation instance does not need to be activated.

Example:

<xs:element  name="amountosd:checkNullInput="trueminOccurs="1"   >
        ...
</xs:element >

See also:

EBX.Platform whitespaces management for Data Types

According to XML Schema ( cf. http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace ), whitespaces handling must follow one of preserve, replace or collapse procedures:

EBX.Platform general management

EBX.Platform complies with XML Schema recommendation:

Exceptions: For nodes of type osd:html or osd:password , whitespaces are always preserved and an empty string is converted to null . For nodes of type xs:string defining property osd:checkNullInput="true" an empty string is interpreted as null at user input in EBX.Manager.

Specific case for handling whitespaces on a primary key of type string

For primary key columns of type xs:string , a default EBX.Platform constraint is defined. This constraint forbids empty strings and non collapsed whitespaces values at validation level.

However, if the primary key node specifies its own xs:pattern facet, this last one overrides the default EBX.Platform constraint. For example, the specific pattern .* would accept any strings (note that we do not recommend this).

The default constraint allows to handle some ambiguities. For example, it would be difficult for a user to distinguish between the following strings: "12 34" and "12  34". For usual values, it does not create conflicts but for primary keys, it could create errors.

Note: EBX.Platform provides a complete Tables specification , that allows to organize and manage your Master Data as in relational databases.

Home > Models