A validator ensures that the data in a typed data element conforms to the business rules of the data element's business object. The property descriptor definition for the type specifies the validator. If the property descriptor does not specify a validator, all values for the data element are valid.
A validator can have validation parameters. For example, a validator for a date type checks whether the value to be validated lies within limits defined by parameters such as lowerLimit and upperLimit.
A technical developer does not need to implement a validator from scratch. UDTT provides com.ibm.btt.base.types.impl.BaseValidator as the superclass of all validator implementations. A technical developer can extend the class and override the validate method.
Shown below is a sample code of validate method implementation:
public void validate(TimeZone convertedValue, TimeZoneValidationParamBean params) throws DSETypeException { // TODO Auto-generated method stub if(convertedValue != null && params.maxoffset != null && !params.maxoffset.equals("")){ if (TimeZone.getTimeZone(params.maxoffset).getRawOffset() > convertedValue.getRawOffset()){ String msg = "validation failed in " + this.getClass().getName() + ". The offset of TimeZone '" + convertedValue.getID() + "' should be smaller than '" + params.maxoffset + "'"; throw new DSETypeException(DSETypeException.harmless, "", msg); } } if(convertedValue != null && params.minoffset != null && !params.minoffset.equals("")){ if (TimeZone.getTimeZone(params.minoffset).getRawOffset() < convertedValue.getRawOffset()){ String msg = "validation failed in " + this.getClass().getName() + ". The offset of TimeZone '" + convertedValue.getID() + "' should be larger than '" + params.maxoffset + "'"; throw new DSETypeException(DSETypeException.harmless, "", msg); } } }