use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class ISOFieldValidator method validate.
/**
* Validate a field component. Default for fields only consider
* field length validations.
* @param c ISOField component
* @return an ISOComponent result of validation process. If there area any
* validation error, then an ISOV component replace original c and it's
* returned in case of break-on-error condition is false. If break-on-error
* is false, then an ISOVException containing the ISOV component is raised.
* @throws ISOException if there are some errors during validation.
* It contains an ISOV component inside referencing the errors.
*/
public ISOComponent validate(ISOComponent c) throws ISOException {
ISOField f = (ISOField) c;
Object v = f.getValue();
int l = 0;
if (v instanceof byte[])
l = ((byte[]) v).length;
else if (v instanceof String)
l = ((String) v).length();
if (l < minLen || l > maxLen) {
ISOVError e = new ISOVError("Invalid Length Error. Length must be in [" + minLen + ", " + maxLen + "]. (Current len: " + l + ") ", getRejCode(ISOVError.ERR_INVALID_LENGTH));
if (f instanceof ISOVField)
((ISOVField) f).addISOVError(e);
else
f = new ISOVField(f, e);
if (breakOnError)
throw new ISOVException("Error on field " + f.getKey(), f);
}
return f;
}
Aggregations