Constraint ValidationThis subsystem supports the WORDS scripting and command language. It validates incremental run-time mutations of a topic map already validated by TMCL or a comparable mechanism, with special focus on the Strings in occurrences and the RolePlayer topics in associations. In both cases, ResourceData embedded in related topics holds annotated pointers to symbolic constraints on these String and Topic values. Similar mechanisms can declare datatypes, naming patterns, cardinality, and behavioral options that keep many TM elements immutable. Three main elements comprise this design, which logically extends a TM engine:
|
||||
Step 1. Define at a PSI an array of planned Constraint TypesThis might be based on the union of constraints found in several diverse specs:
This design thus envisions Constraints[], a published array, yet tries to stay insensitive to its details. It imposes only this documentation rule, so indices into the array can link to predicates at steps 2-6: once a constraint type is posted, it cannot be deleted or moved. At some point, the PSI array (at least its lower elements) must drive
working code or the whole design is pointless. Specific predicates
to be built early are discussed below. |
||||
Step 2. Define a matching array of Member-validation predicatesMany of the most interesting predicates will (can) have a signature like this example, where ## is the index into Constraints[], and REQ is a (packed) String which further describes (##-specific) requirements which must be satisfied by the mix of remaining arguments: predicate_##(String REQ,
// encoded requirements
Each such predicate must decide (by using REQ) if the given player is acceptable as a value for roleSpec within the given assoc. If so, it need do nothing. If not, it must throw a Java exception that complains about the problem and includes specific details via ## and REQ. Each kind of constraint (##) gets its own separate predicate, plus fine-tuning (REQ).that varies with topics.
Many distinct problems could cause exceptions -- wrong cardinality, wrong
domain, wrong range, etc.. Each constraint type gets unique logic,
but one method signature. This lets them be built
faster (factory-like), then called through one API. |
||||
Step 3. Define a matching array of String-validation predicatesMany elements of Constraints[] will involve Strings, not associations. They can be handled by other predicates of this similar signature, focused on occurrences: predicate_##(String REQ,
// encoded requirements
Each such predicate must decide by using REQ if the given resource
is acceptable as a value for propType within the given topic.
If so, it need do nothing. If not, if must throw a Java exception
that complains about the problem and gives specific details via ## and
REQ. Many of these predicates will involve validating
XML schema
types of resources.
|
||||
Step 4. Define Extra Predicate Signatures for Multiple valuesMany predicates will need extra signatures to address multiple players or resources. This is not hard, but does involve several issues. Ideally, it could merely require substitution of a Set in the final argument of both signatures above, plus an added internal iteration loop.If the cardinality for a given roleSpec or propType is multiple, we might always require the multiple-value signature to be called. Or maybe not. Such rules may take some debate. A bigger issue for multiple values is the nature of their Collection. Sometimes it helps to preserve order, so perhaps a List or Array version of the signature would also be needed. Such details are not show stoppers, but they need to be resolved cleanly
and consistently. Consensus may be hard to reach if some constraint - like
a List argument - implies related changes to TM engine code, or to other
basic resources of the TM community.
|
||||
Step 5. Define Predicates to handle Scope, Typing, NamesWORDS handles scopes and typing in its interpreter code. End users and scripts see them as immutable, so no constraints and predicates are required. (This could be relaxed later, after TMCL better defines how they might best be handled in general.)Meanwhile, TMCL can help out by validating a WORDS topic map as or before it loads into an engine, and by establishing a more general set of design patterns. To implement them later, we conceptually reserve special occurrences as storage space in each topic for related constraint references and their REQ data, plus similar character string codes. BaseNames and variantNames are special cases, mutable by WORDS users. We could
define new predicates to validate names, but an early shortcut may be to reuse the signature of step 3, citing propTypes for reserved
"baseName"
and "variantName" Topics that signal the need to retrieve a related constraint
String from an atypical place in the TM. |
||||
Step 6. Assembling the above into a WORDS Constraint LanguageUnder this design, a simple spec can emerge for a constraint language: define its core form as a comma-separated list of sub-Strings stored in occurrences of closely related topics:
|
||||
|
|