use of org.jpos.iso.ISOComponent in project jPOS by jpos.
the class CTCSubFieldPackager method unpack.
public int unpack(ISOComponent m, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
int consumed = 0;
for (int i = 0; consumed < b.length; i++) {
ISOComponent c = fld[i].createComponent(i);
consumed += fld[i].unpack(c, b, consumed);
if (logger != null) {
evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
evt.addMessage(" <value>" + c.getValue().toString() + "</value>");
evt.addMessage("</unpack>");
}
m.set(c);
}
Logger.log(evt);
return consumed;
}
use of org.jpos.iso.ISOComponent in project jPOS by jpos.
the class GICCSubFieldPackager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
try {
int len = 0;
byte[] result;
Map tab = c.getChildren();
List list = new ArrayList();
// Handle first IF_CHAR field
ISOField f0 = (ISOField) tab.get(0);
if (f0 != null) {
String s = (String) f0.getValue();
list.add(s.getBytes());
len += s.getBytes().length;
}
for (int i = 1; i < fld.length; i++) {
Object obj = tab.get(i);
if (obj instanceof ISOComponent) {
ISOComponent f = (ISOComponent) obj;
byte[] b = fld[i].pack(f);
list.add(b);
len += b.length;
}
}
result = new byte[len];
int k = 0;
for (int i = 0; i < list.size(); i++) {
byte[] b = (byte[]) list.get(i);
for (int j = 0; j < b.length; j++) result[k++] = b[j];
}
return result;
} catch (Exception ex) {
throw new ISOException(ex);
}
}
use of org.jpos.iso.ISOComponent in project jPOS by jpos.
the class GICCSubFieldPackager method unpack.
public int unpack(ISOComponent m, byte[] b) throws ISOException {
// Unpack the IF_CHAR field
int consumed = 0;
ISOComponent c;
if (fld[0] != null && b[consumed] == 0x20) {
// Hack to support a nine-byte filler
c = fld[0].createComponent(0);
consumed += fld[0].unpack(c, b, consumed);
m.set(c);
}
// Now unpack the IFEP_LLCHAR fields
for (; consumed < b.length; ) {
int fieldNumber = Integer.parseInt(ISOUtil.ebcdicToAscii(b, consumed + 3, 2));
if (fld[fieldNumber] == null)
break;
c = fld[fieldNumber].createComponent(fieldNumber);
consumed += fld[fieldNumber].unpack(c, b, consumed);
m.set(c);
}
return consumed;
}
use of org.jpos.iso.ISOComponent 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.ISOComponent in project jPOS by jpos.
the class VISA1PackagerTest method testUnpack1.
@Test
public void testUnpack1() throws Throwable {
int[] sequence = new int[0];
VISA1Packager vISA1Packager = new VISA1Packager(sequence, 100, "testVISA1PackagerBadResultCode", "testVISA1PackagerOkPattern");
ISOComponent m = new ISOMsg(100);
byte[] b = new byte[0];
int result = vISA1Packager.unpack(m, b);
assertEquals("(ISOVMsg) m.getMaxField()", 100, m.getMaxField());
assertEquals("result", 0, result);
}
Aggregations