Search in sources :

Example 36 with ISOField

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();
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOMsg(org.jpos.iso.ISOMsg) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 37 with ISOField

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");
            }
        }
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 38 with ISOField

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;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 39 with ISOField

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;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Example 40 with ISOField

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());
}
Also used : ISOField(org.jpos.iso.ISOField) ISOTaggedField(org.jpos.tlv.ISOTaggedField)

Aggregations

ISOField (org.jpos.iso.ISOField)50 Test (org.junit.Test)18 ISOException (org.jpos.iso.ISOException)15 ISOTaggedField (org.jpos.tlv.ISOTaggedField)15 IFB_LLNUM (org.jpos.iso.IFB_LLNUM)6 IFE_LLNUM (org.jpos.iso.IFE_LLNUM)6 ISOMsg (org.jpos.iso.ISOMsg)6 ISOMultiFieldPackager (org.jpos.iso.packager.ISOMultiFieldPackager)6 ISOComponent (org.jpos.iso.ISOComponent)5 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)5 ISOVField (org.jpos.iso.ISOVField)5 Vector (java.util.Vector)4 FileInputStream (java.io.FileInputStream)3 Map (java.util.Map)3 ISOBinaryField (org.jpos.iso.ISOBinaryField)3 ByteBuffer (java.nio.ByteBuffer)2 ISOVError (org.jpos.iso.ISOVError)2 GenericPackager (org.jpos.iso.packager.GenericPackager)2 GenericTagSequence (org.jpos.tlv.GenericTagSequence)2 LiteralTagValue (org.jpos.tlv.LiteralTagValue)2