Inspects the elements gathered by a builder and confirms an object's constraints are satisfied before the immutable instance is produced.
Each OsidObject has a corresponding
OsidObjectValidator that
inspects and checks the compliance of an OsidObject. It is used by
default in the builder pattern but can be used for any
OsidObject before releasing it to an OSID Consumer.
Which checks a validator runs is selected by an
EnumSet<Validation>. ALL is the
default. The Validation enum enumerates the available
check types; passing no enum set applies a default validation.
Each constant of the Validation enum names one class
of check a validator may apply. ALL and NONE select every check
or none; the remainder can be combined in any EnumSet.
| Value | Definition |
|---|---|
ALL | all checks |
NONE | the opposite of ALL |
NULL | check for any nulls |
NIL_ID | check for any nil implementations of Id |
NIL_TYPE | check for any nil implementations of Type |
NIL_OBJECT | check for any nil implementations of objects (not implemented) |
RANGE | check that low/high and min/max ranges are in the right order |
CARDINAL | check that cardinal numbers are non-negative |
TYPE_SUPPORT | cross-reference type support |
EMPTY_STRING | listed in the enumeration but not a check |
ID_CONSISTENCY | check for consistent Ids |
METHOD_SUPPORT | check for proper method states (basic isActive() and isEnabled() boolean checks) |
TRAVERSE | traverse nested OsidObjects |
RECORDS | check for existence of OsidRecords by Type |
net.okapia.osid.jamocha.builder.validator
| Parameter | Type | Description |
|---|---|---|
validation |
EnumSet<Validation> |
the set of checks to perform; an overload without this argument applies a default validation |
object |
OsidObject |
the object to validate |
Returns the validated OsidObject unchanged — throws InvalidReturnException, NullReturnException, BadLogicException, or NullArgumentException when a constraint is violated
public org.osid.repository.Asset getAsset(org.osid.id.Id assetId)
throws org.osid.NotFoundException,
org.osid.OperationFailedException,
org.osid.PermissionDeniedFailedException {
var data = fetch(assetId);
return (new (AssetValidator.validate(new MyAsset(data));
}
Yes, I run them inline where possible. In most cases it is worth it to blow up where the problem was caused.