Search in sources :

Example 1 with ISOBinaryField

use of org.jpos.iso.ISOBinaryField in project jPOS by jpos.

the class TagSequenceBase method writeTo.

@Override
public synchronized void writeTo(ISOMsg isoMsg) throws ISOException {
    int maxField = isoMsg.getMaxField();
    List<TagValue> tagValueList = getOrderedList();
    int fieldNumber = 0;
    for (TagValue tagValue : tagValueList) {
        Object value = tagValue.getValue();
        if (value != null) {
            ISOComponent subField;
            if (value instanceof byte[]) {
                subField = new ISOBinaryField(fieldNumber + maxField + 1, (byte[]) value);
            } else if (value instanceof String) {
                subField = new ISOField(fieldNumber + maxField + 1, (String) value);
            } else if (value instanceof TagSequence) {
                TagSequence subSequence = (TagSequence) tagValue;
                subField = new ISOMsg(fieldNumber + maxField + 1);
                subSequence.writeTo((ISOMsg) subField);
            } else if (value instanceof ISOMsg) {
                ISOMsgTagValue subSequence = (ISOMsgTagValue) tagValue;
                subField = subSequence.getValue();
                subField.setFieldNumber(fieldNumber + maxField + 1);
            } else {
                throw new ISOException("Unknown TagValue subclass: " + tagValue.getClass());
            }
            isoMsg.set(new ISOTaggedField(tagValue.getTag(), subField));
        }
        fieldNumber++;
    }
}
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)

Example 2 with ISOBinaryField

use of org.jpos.iso.ISOBinaryField in project jPOS by jpos.

the class BERTLVPackager method unpackValue.

private ISOComponent unpackValue(String tagNameHex, final byte[] tlvData, int subFieldNumber, int dataLength) throws ISOException, UnknownTagNumberException {
    final int tagNumber = Integer.parseInt(tagNameHex, 16);
    final TLVDataFormat dataFormat = getTagFormatMapper().getFormat(tagNumber);
    ISOComponent value;
    String unpackedValue;
    int uninterpretLength;
    switch(dataFormat) {
        case COMPRESSED_NUMERIC:
            uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterRightPaddedF);
            unpackedValue = bcdInterpreterRightPaddedF.uninterpret(tlvData, 0, uninterpretLength);
            if (unpackedValue.length() > 1 && unpackedValue.charAt(unpackedValue.length() - 1) == 'F') {
                unpackedValue = unpackedValue.substring(0, unpackedValue.length() - 1);
            }
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case PACKED_NUMERIC:
        case PACKED_NUMERIC_DATE_YYMMDD:
        case PACKED_NUMERIC_TIME_HHMMSS:
            uninterpretLength = getUninterpretLength(dataLength, bcdInterpreterLeftPaddedZero);
            unpackedValue = bcdInterpreterLeftPaddedZero.uninterpret(tlvData, 0, uninterpretLength);
            if (unpackedValue.length() > 1 && unpackedValue.charAt(0) == '0') {
                unpackedValue = unpackedValue.substring(1);
            }
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case ASCII_NUMERIC:
        case ASCII_ALPHA:
        case ASCII_ALPHA_NUMERIC:
        case ASCII_ALPHA_NUMERIC_SPACE:
        case ASCII_ALPHA_NUMERIC_SPECIAL:
            uninterpretLength = getUninterpretLength(dataLength, asciiInterpreter);
            unpackedValue = asciiInterpreter.uninterpret(tlvData, 0, uninterpretLength);
            value = new ISOField(subFieldNumber, unpackedValue);
            break;
        case BINARY:
        case PROPRIETARY:
            value = new ISOBinaryField(subFieldNumber, tlvData);
            break;
        case CONSTRUCTED:
            value = new ISOMsg(subFieldNumber);
            unpack(value, tlvData, true);
            break;
        default:
            throw new IllegalArgumentException("Unknown TLVDataFormat: " + dataFormat);
    }
    return value;
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOMsg(org.jpos.iso.ISOMsg) TLVDataFormat(org.jpos.tlv.TLVDataFormat)

Example 3 with ISOBinaryField

use of org.jpos.iso.ISOBinaryField in project jPOS by jpos.

the class MSGTEST1Test method testValidateThrowsISOException.

@Test
public void testValidateThrowsISOException() throws Throwable {
    try {
        new MSGTEST(true).validate(new ISOBinaryField());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Can't call validate on non Composite", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) ISOException(org.jpos.iso.ISOException) Test(org.junit.Test)

Example 4 with ISOBinaryField

use of org.jpos.iso.ISOBinaryField in project jPOS by jpos.

the class VErrorParserTest method testGetVErrors9.

@SuppressWarnings("unchecked")
@Test
public void testGetVErrors9() throws Throwable {
    VErrorParser vErrorParser = new VErrorParser();
    Vector result = vErrorParser.getVErrors(new ISOBinaryField());
    assertEquals("result.size()", 0, result.size());
}
Also used : ISOBinaryField(org.jpos.iso.ISOBinaryField) Vector(java.util.Vector) Test(org.junit.Test)

Example 5 with ISOBinaryField

use of org.jpos.iso.ISOBinaryField in project jPOS by jpos.

the class Base1_BITMAP126Test method testUnpackThrowsNullPointerException.

@Test
public void testUnpackThrowsNullPointerException() throws Throwable {
    Base1_BITMAP126 base1_BITMAP126 = new Base1_BITMAP126(100, "testBase1_BITMAP126Description");
    ISOComponent c = new ISOBinaryField(100);
    try {
        base1_BITMAP126.unpack(c, null, 100);
        fail("Expected NullPointerException to be thrown");
    } catch (NullPointerException ex) {
        assertNull("ex.getMessage()", ex.getMessage());
        assertNull("(ISOBinaryField) c.getBytes()", ((ISOBinaryField) c).getBytes());
    }
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) ISOBinaryField(org.jpos.iso.ISOBinaryField) Test(org.junit.Test)

Aggregations

ISOBinaryField (org.jpos.iso.ISOBinaryField)14 Test (org.junit.Test)11 ISOException (org.jpos.iso.ISOException)7 ISOComponent (org.jpos.iso.ISOComponent)4 ISOField (org.jpos.iso.ISOField)3 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)3 ISOMsg (org.jpos.iso.ISOMsg)3 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Vector (java.util.Vector)1 IFA_LCHAR (org.jpos.iso.IFA_LCHAR)1 IFA_LLBNUM (org.jpos.iso.IFA_LLBNUM)1 TLVDataFormat (org.jpos.tlv.TLVDataFormat)1