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++;
}
}
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;
}
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());
}
}
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());
}
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());
}
}
Aggregations