Package org.jpos.iso

Examples of org.jpos.iso.ISOComponent


        }
    }

    @Test
    public void testValidateThrowsISOVException1() throws Throwable {
        ISOComponent m = new ISOVMsg(new ISOMsg("testMSGTEST02Mti"));
        try {
            new MSGTEST02(true).validate(m);
            fail("Expected ISOVException to be thrown");
        } catch (ISOVException ex) {
            assertEquals("ex.getMessage()", "Error on msg. ", ex.getMessage());
View Full Code Here


    @Test
    public void testValidateThrowsNullPointerException() throws Throwable {
        ISOMsg Source = new ISOMsg("testMSGTEST02Mti");
        Source.setMTI("testMSGTEST02Mti");
        Source.setRetransmissionMTI();
        ISOComponent m = new ISOVMsg(Source);
        try {
            new MSGTEST02().validate(m);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull("ex.getMessage()", ex.getMessage());
View Full Code Here

        }
    }

    @Test
    public void testValidateThrowsNullPointerException2() throws Throwable {
        ISOComponent m = new ISOVMsg(new ISOMsg(100));
        try {
            new MSGTEST02().validate(m);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull("ex.getMessage()", ex.getMessage());
View Full Code Here

        for (Map.Entry<String, List<TagValue>> tagValueEntry : tagValues) {
            List<TagValue> tagValueList = tagValueEntry.getValue();
            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));
                }
View Full Code Here

    @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");
View Full Code Here

    public byte[] pack(ISOComponent m, boolean nested, int startIdx, int endIdx)
            throws ISOException {
        LogEvent evt = new LogEvent(this, "pack");
        try {
            ISOComponent c;
            List<byte[]> l = new ArrayList<byte[]>();
            Map fields = m.getChildren();
            int len = 0;
            for (int i = startIdx; i <= endIdx; i++) {
                c = (ISOComponent) fields.get(i);
                if (c != null) {
                    try {
                        final byte[] b;
                        if (c instanceof ISOTaggedField) {
                            b = packTLV((ISOTaggedField) c);
                        } else {

                            if (c.getValue() == null) {
                                b = new byte[0];
                            } else if (!nested && (i == startIdx || i == endIdx) &&
                                    this.fld.length > i && this.fld[i] != null) {
                                b = this.fld[i].pack(c);
                            } else {
                                throw new ISOException(
                                        "Field: " +
                                                i +
                                                " of type: " +
                                                c.getClass() +
                                                " cannot be packed. Either the object should be of type ISOTagField" +
                                                " OR this should be the first or last sub-field and a packager" +
                                                " should be configured for the same");
                            }
                        }
View Full Code Here

            int consumed = 0;
            int subFieldNumber = 1;
            if (!nested && fld.length > 1) {
                ISOFieldPackager packager = fld[1];
                if (packager != null) {
                    ISOComponent subField = packager.createComponent(1);
                    consumed = consumed + packager.unpack(subField, b, consumed);
                    m.set(subField);
                }
                subFieldNumber++;
            }

            while (consumed < tlvDataLength) {
                ISOFieldPackager packager;
                if (!nested && fld.length > 1 && (packager = fld[fld.length - 1]) != null &&
                        packager.getLength() == tlvDataLength - consumed) {
                    ISOComponent subField = packager.createComponent(fld.length - 1);
                    consumed = consumed + packager.unpack(subField, b, consumed);
                    m.set(subField);
                    subFieldNumber++;
                } else {
                    //Read the Tag per BER
                    UnpackResult tagUnpackResult = unpackTag(b, consumed);
                    consumed = consumed + tagUnpackResult.consumed;
                    final byte[] tagBytes = tagUnpackResult.value;
                    String tag = ISOUtil.byte2hex(tagBytes).toUpperCase();
                    UnpackResult lengthUnpackResult = unpackLength(b, consumed);
                    consumed = consumed + lengthUnpackResult.consumed;
                    int length = ISOUtil.byte2int(lengthUnpackResult.value);

                    final ISOComponent tlvSubFieldData;
                    byte[] value = new byte[length];

                    if (length > 0) {
                        System.arraycopy(b, consumed, value, 0, value.length);
                    }
View Full Code Here

    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);
View Full Code Here

            int subFieldId = 0;
            while (fld.length > subFieldId) {
                if (fld[subFieldId] instanceof TaggedFieldPackager) {
                    break;
                } else if (fld[subFieldId] != null) {
                    ISOComponent subField = fld[subFieldId].createComponent(subFieldId);
                    consumed += fld[subFieldId].unpack(subField, b, consumed);
                    m.set(subField);
                }
                subFieldId++;
            }
View Full Code Here

     */

    public byte[] pack(ISOComponent m) throws ISOException {
        LogEvent evt = new LogEvent(this, "pack");
        try {
            ISOComponent c;
            List<byte[]> l = new ArrayList<byte[]>();
            Map fields = m.getChildren();
            fields.remove(new Integer(-1));
            int len = 0;
            boolean tagsStarted = false;
            Iterator iterator = fields.values().iterator();
            if (m instanceof OffsetIndexedComposite) {
                int offset = ((OffsetIndexedComposite) m).getOffset();
                for (int i = 0; i < offset && iterator.hasNext(); i++) {
                    iterator.next();
                }
            }
            while (iterator.hasNext() && len < this.length) {

                Object obj = iterator.next();
                c = (ISOComponent) obj;

                byte[] b;
                if (c.getValue() != null) {
                    if (c instanceof ISOTaggedField) {
                        tagsStarted = true;
                        String tag = ((ISOTaggedField) c).getTag();
                        if (tag == null) {
                            evt.addMessage("error packing subfield " + c.getKey());
                            evt.addMessage(c);
                            throw new ISOException("Tag should not be null");
                        } else {
                            ISOFieldPackager fieldPackager = (ISOFieldPackager) packagerMap.get(tag);
                            if (fieldPackager == null) {
                                fieldPackager = (ISOFieldPackager) packagerMap.get("default");
                            }
                            if (fieldPackager == null) {
                                throw new ISOException("No default tag packager and no field packager configured for tag: " + tag);
                            }
                            b = fieldPackager.pack(c);
                            if ((len + b.length) > this.length) {
                                break;
                            }
                            len += b.length;
                            l.add(b);
                        }
                    } else if (numericTag) {
                        int tagNumber = (Integer) c.getKey();
                        String tag = ISOUtil.padleft(String.valueOf(tagNumber), this.tag.length(), '0');
                        ISOTaggedField isoTaggedField = new ISOTaggedField(tag, c);
                        if (fld.length > tagNumber) {
                            b = fld[(Integer) c.getKey()].pack(isoTaggedField);
                        } else {
                            ISOFieldPackager fieldPackager = (ISOFieldPackager) packagerMap.get(tag);
                            if (fieldPackager == null) {
                                fieldPackager = (ISOFieldPackager) packagerMap.get("default");
                            }
                            if (fieldPackager == null) {
                                throw new ISOException("No default tag packager and no field packager configured for tag: " + tag);
                            }
                            b = fieldPackager.pack(isoTaggedField);
                            if ((len + b.length) > this.length) {
                                break;
                            }
                        }
                        len += b.length;
                        l.add(b);
                    } else if (!tagsStarted) {
                        if (fld.length > (Integer) c.getKey()) {
                            b = fld[(Integer) c.getKey()].pack(c);
                        } else {
                            throw new ISOException("Non ISOTagField without packager definition. Cannot pack as tag is non-numeric");
                        }
                        len += b.length;
                        l.add(b);
                    } else {
                        evt.addMessage("error packing sub-field " + c.getKey() + ". Sub-field should be of type ISOTaggedField when tag is non-numeric");
                        evt.addMessage(c);
                        throw new ISOException("error packing sub-field " + c.getKey() + ". Sub-field should be of type ISOTaggedField when tag is non-numeric");
                    }
                }
                if (m instanceof OffsetIndexedComposite) {
                    ((OffsetIndexedComposite) m).incOffset();
                }
View Full Code Here

TOP

Related Classes of org.jpos.iso.ISOComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.