|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
A Constraint can be used to validate any type of non-primitive
Java object. Its use is not reserved for a certain context or set of classes
but may be used independently from the rest of the API whenever certain
conditions on object values must be checked programmatically.
A Constraint is created by passing a String expression to an
instance of class ConstraintParser. After successful parsing, the
parser returns a reference to a compiled Constraint instance.
This instance is immutable (non-modifiable).
All Constraint instances implement the toString()
method by returning a String that may be legally parsed again. This means
that you can assemble existing constraints without knowing their exact
contents by using a logical operator. In the event a parser fails to
compile a Constraint instance, an exception of type
ConstraintParserException is thrown. Representing
constraints by strings is highly beneficial, assembling them is easy and
representing them in memory becomes very compact. Constraint
instances are also pooled.
Constraints can be concatenated into constraint-trees or constraint-
hierarchies. These trees are similiar to expression syntax trees.
A single constraint like the AndConstraint can concatenate two
or more constraints logically and thereby allowing the user to define almost
arbitrary complex restrictions of all possible kinds.
Constraints implement the flyweight pattern. They are
sharable objects with no dynamic intrinsic state. All the dynamic state
is extrinsic and passed into the Constraint by invoking
the validate(Object) method.
ConstraintParser,
Attribute| Method Summary | |
Constraint |
intern()
This method pools the constraint analogous to the String.intern() method. |
void |
trace(java.lang.StringBuffer sb)
This method is called to trace for the last error. |
boolean |
validate(java.lang.Object value)
Validates this contraint against a given value. |
| Method Detail |
public boolean validate(java.lang.Object value)
null.
value - the object to validate. It is not allowed to pass in
null as an argument.
true if this value confirms to this constraints and
false if it doesn't.
InvalidArgumentException - thrown
if the input object is null.public void trace(java.lang.StringBuffer sb)
null.
sb - the StringBuffer to append the error message to.
It is not allowed to pass in null as this
argument.public Constraint intern()
String.intern() method.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||