use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class GenericValidatingPackager method validate.
public ISOComponent validate(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "validate");
try {
ISOComponent c;
Map<Object, ISOComponent> fields = m.getChildren();
/**
* Field validations *
*/
for (ISOValidator val : fvlds) {
if ((c = fields.get(((ISOFieldValidator) val).getFieldId())) != null) {
try {
m.set(val.validate(c));
} catch (ISOVException e) {
if (!e.treated()) {
m.set(e.getErrComponent());
e.setTreated(true);
}
evt.addMessage("Component Validation Error.");
throw e;
}
}
}
/**
* msg validations *
*/
try {
for (ISOBaseValidator mval : mvlds) m = mval.validate(m);
} catch (ISOVException ex) {
evt.addMessage("Component Validation Error.");
throw ex;
}
return m;
} finally {
Logger.log(evt);
}
}
use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class ISOBaseValidatingPackager method validate.
public ISOComponent validate(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "validate");
try {
ISOComponent c;
Map fields = m.getChildren();
/**
* Field validations *
*/
for (ISOValidator aFldVld : fldVld) {
if (aFldVld != null && (c = (ISOComponent) fields.get(Integer.valueOf(((ISOFieldValidator) aFldVld).getFieldId()))) != null) {
try {
m.set(aFldVld.validate(c));
} catch (ISOVException e) {
if (!e.treated()) {
m.set(e.getErrComponent());
e.setTreated(true);
}
evt.addMessage("Component Validation Error.");
throw e;
}
}
}
/**
* msg validations *
*/
try {
if (msgVld != null) {
for (ISOBaseValidator aMsgVld : this.msgVld) {
if (aMsgVld != null)
m = aMsgVld.validate(m);
}
}
} catch (ISOVException ex) {
evt.addMessage("Component Validation Error.");
throw ex;
}
return m;
} finally {
Logger.log(evt);
}
}
use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class IVA_NUM method validate.
/**
* Validate numeric condition. @see ISOFieldValidator class.
* @param f ISOField to validate
* @return see validate method in ISOFieldValidator class.
* @throws ISOException if any validation error.
*/
public ISOComponent validate(ISOComponent f) throws ISOException {
ISOField c = (ISOField) f;
c = (ISOField) super.validate(c);
if (!ISOUtil.isNumeric((String) c.getValue(), this.radix)) {
ISOVError e = new ISOVError("Invalid Value Error. " + c.getValue() + " is not a numeric value in radix " + this.radix, getRejCode(ISOVError.ERR_INVALID_VALUE));
if (c instanceof ISOVField)
((ISOVField) c).addISOVError(e);
else
c = new ISOVField(c, e);
if (breakOnError)
throw new ISOVException("Error on field " + c.getKey(), c);
}
return c;
}
use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class GenericValidatingPackagerTest method testValidateThrowsISOVException.
@Test
public void testValidateThrowsISOVException() throws Throwable {
GenericValidatingPackager genericValidatingPackager = new GenericValidatingPackager();
ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
msgVlds[0] = new MSGTEST(false);
msgVlds[1] = new MSGTEST(true);
genericValidatingPackager.setMsgValidator(msgVlds);
ISOFieldValidator[] fvlds = new ISOFieldValidator[1];
fvlds[0] = new IVA_ALPHANUM("testGenericValidatingPackagerDescription");
genericValidatingPackager.setFieldValidator(fvlds);
try {
genericValidatingPackager.validate(new ISOMsg(100));
fail("Expected ISOVException to be thrown");
} catch (ISOVException ex) {
assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
assertFalse("ex.treated()", ex.treated());
assertNotNull("ex.getErrComponent()", ex.getErrComponent());
assertNull("ex.getNested()", ex.getNested());
}
}
use of org.jpos.iso.validator.ISOVException in project jPOS by jpos.
the class ISOBaseValidatingPackagerTest method testValidateThrowsISOException6.
@Test
public void testValidateThrowsISOException6() throws Throwable {
ISOFieldValidator iVA_ALPHANUMNOBLANK = new IVA_ALPHANUMNOBLANK(true, "testISOBaseValidatingPackagerDescription");
ISOBaseValidator[] msgVlds = new ISOBaseValidator[3];
msgVlds[0] = new MSGTEST(true);
ISOFieldValidator[] fvlds = new ISOFieldValidator[3];
fvlds[0] = iVA_ALPHANUMNOBLANK;
ISOBaseValidatingPackager iSOBaseValidatingPackager = new ISOBaseValidatingPackager();
iSOBaseValidatingPackager.setFieldValidator(fvlds);
iSOBaseValidatingPackager.setMsgValidator(msgVlds);
try {
iSOBaseValidatingPackager.validate(new ISOMsg());
fail("Expected ISOException to be thrown");
} catch (ISOException ex) {
assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
assertFalse("ex.treated()", ((ISOVException) ex).treated());
assertNotNull("ex.getErrComponent()", ((ISOVException) ex).getErrComponent());
assertNull("ex.getNested()", ex.getNested());
}
}
Aggregations