use of org.jpos.iso.ISOField in project jPOS by jpos.
the class TaggedFieldPackagerBaseTest method testPack.
@Test
public void testPack() throws Exception {
String path = "build/resources/test/org/jpos/iso/packagers/";
GenericPackager genericPackager = new GenericPackager(new FileInputStream(path + "ISO93TLVPackager.xml"));
ISOMsg msg = new ISOMsg();
msg.setMTI("1100");
msg.set(new ISOField(2, "123456"));
ISOMsg subFieldsContainer = new ISOMsg(48);
ISOField tlvField = new ISOField(1);
tlvField.setValue("48TagA1");
subFieldsContainer.set(tlvField);
ISOField tlvField2 = new ISOField(3);
tlvField2.setValue("48TagA3");
subFieldsContainer.set(tlvField2);
msg.set(subFieldsContainer);
ISOMsg subFieldsContainer2 = new ISOMsg(60);
ISOField tlvField3 = new ISOField(1);
tlvField3.setValue("60TagA1");
subFieldsContainer2.set(tlvField3);
msg.set(subFieldsContainer2);
msg.setHeader("HEADER ".getBytes());
msg.setPackager(genericPackager);
byte[] packed = msg.pack();
assertNotNull(packed);
FileOutputStream fos = new FileOutputStream(path + "ISO93TLVPackager.bin");
try {
fos.write(packed);
} finally {
fos.close();
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class TagSequenceBase method readFrom.
@Override
public synchronized void readFrom(ISOMsg isoMsg) throws ISOException {
int maxField = isoMsg.getMaxField();
int minField = -1;
for (int i = 0; i <= maxField; i++) {
ISOComponent child = isoMsg.getComponent(i);
if (child instanceof ISOTaggedField) {
minField = i;
break;
}
}
if (minField == -1) {
// No TaggedFields to read
return;
}
for (int i = minField; i <= maxField; i++) {
ISOComponent child = isoMsg.getComponent(i);
if (child != null) {
if (child instanceof ISOTaggedField) {
TagValue tagValue;
ISOTaggedField taggedSubField = (ISOTaggedField) child;
ISOComponent delegate = taggedSubField.getDelegate();
if (delegate instanceof ISOMsg) {
Map subChildren = delegate.getChildren();
boolean allTaggedValue = true;
for (Object subChild : subChildren.values()) {
if (!(subChild instanceof ISOTaggedField)) {
allTaggedValue = false;
break;
}
}
if (allTaggedValue) {
tagValue = createTagValueSequence(taggedSubField.getTag());
((TagSequence) tagValue).readFrom((ISOMsg) delegate);
} else {
tagValue = new ISOMsgTagValue(getTag(), isoMsg);
}
} else if (delegate instanceof ISOBinaryField) {
tagValue = createBinaryTagValuePair(taggedSubField.getTag(), taggedSubField.getBytes());
} else if (delegate instanceof ISOField) {
tagValue = createLiteralTagValuePair(taggedSubField.getTag(), taggedSubField.getValue().toString());
} else {
throw new ISOException("Unknown ISOComponent subclass in ISOTaggedField: " + delegate.getClass());
}
this.add(tagValue);
} else {
throw new ISOException("Children after first ISOTaggedField should be instance of ISOTaggedField." + " Field " + i + " is not an ISOTaggedField");
}
}
}
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IFTA_LLBINARY method unpackTag.
protected int unpackTag(ISOComponent c, byte[] tagBytes, int offset) throws ISOException {
ISOField tagField = new ISOField((Integer) c.getKey());
int consumed = getTagPackager().unpack(tagField, tagBytes, offset);
((ISOTaggedField) c).setTag(tagField.getValue().toString());
return consumed;
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IFTA_LLCHAR method unpackTag.
protected int unpackTag(ISOComponent c, byte[] tagBytes, int offset) throws ISOException {
ISOField tagField = new ISOField((Integer) c.getKey());
int consumed = getTagPackager().unpack(tagField, tagBytes, offset);
((ISOTaggedField) c).setTag(tagField.getValue().toString());
return consumed;
}
use of org.jpos.iso.ISOField in project jPOS by jpos.
the class IFTA_LLCHAR method unpackTag.
protected void unpackTag(ISOComponent c, InputStream in) throws ISOException, IOException {
ISOField tagField = new ISOField((Integer) c.getKey());
getTagPackager().unpack(tagField, in);
((ISOTaggedField) c).setTag(tagField.getValue().toString());
}
Aggregations