com.softwareag.mdm.schema
Interface Constraint

All Known Subinterfaces:
ConstraintEnumeration, ConstraintNomenclature

public interface Constraint

Specifies a constraint that may be contextual and dynamic. Regarding XML Schema, it may be considered as a programmatic extended facet.

Schema definition

The constraint must be declared under the element xs:annotation/xs:appinfo/mdm:otherFacets:

 <mdm:constraint class="com.foo.MyConstraint" />
where com.foo.MyConstraint is the fully qualified name of the class implementing this interface. It is also possible to set additional JavaBean properties:
 <mdm:constraint class="com.foo.MyConstraint">
 	 <param1>...</param1>
 	 <param2>...</param2>
 </mdm:constraint>
where param1 and param2 are JavaBean properties of the class specified.

For more information, read JavaBeans specification.

Life-cycle

  1. When the schema is loaded:
    1. the class specified is instantiated through its default constructor and the JavaBean properties' setters are called (in the example above, setParam1(...) and setParam2(...));
    2. the method setup(ConstraintContext) is called on the new instance.
  2. In operational phase: the method checkOccurrence(Object, ValueContextForValidation) is called each time an associated element or attribute has to be validated.

Performance warning

See checkOccurrence(Object, ValueContextForValidation).

See Also:
ConstraintEnumeration, ConstraintNomenclature, ConstraintOnNull

Method Summary
 void checkOccurrence(Object aValue, ValueContextForValidation aValidationContext)
          This method checks the value specified.
 void setup(ConstraintContext aContext)
          This method is called when the schema is loaded, for checking and preparing this instance.
 String toUserDocumentation(Locale userLocale, ValueContext aContext)
          Returns a final user documentation about this constraint.
 

Method Detail

checkOccurrence

public void checkOccurrence(Object aValue,
                            ValueContextForValidation aValidationContext)
                     throws InvalidSchemaException
This method checks the value specified. If aValue is not valid, it must add an error message.

The value given as argument by the container is an occurrence. It means that if the associated node is a multi-occurrenced element declaration (that is, maxOccurs > 1), this method is called for each occurrence of the element.

Performance warning

If the constraint is attached to a table with N occurrences, the full validation will call this method N times.

Hence for a table with large volumes of occurrences, it may be necessary to optimize the implementation (for example, by ensuring some caching in this instance).

Multi-threading

For a single instance of this interface, this method may be called concurrently by several threads.

Throws:
InvalidSchemaException - if some schema's dynamic condition prevents the execution of this method.

setup

public void setup(ConstraintContext aContext)
This method is called when the schema is loaded, for checking and preparing this instance.

This method must also declare the dependencies of the constraint, if any, so that validation is notified when a value is updated.

See Also:
ConstraintContext.addDependency(Path)

toUserDocumentation

public String toUserDocumentation(Locale userLocale,
                                  ValueContext aContext)
                           throws InvalidSchemaException
Returns a final user documentation about this constraint.

Multi-threading

For a single instance of this interface, this method may be called concurrently by several threads.

Throws:
InvalidSchemaException - if some schema's dynamic condition prevents the execution of this method.


(report a bug)
webMethods MDM 4.2.8 [0558]
Copyright Software AG 2000-2007. All rights reserved.