Package org.jpos.util

Source Code of org.jpos.util.ISOComponentStringifier

package org.jpos.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jpos.iso.*;
import org.jpos.iso.header.BASE1Header;

/**
* $Revision: 5390 $
* $Date: 2006-08-24 07:30:46 +0000 (Thu, 24 Aug 2006) $
* $Author: ratkins $
*/
public final class ISOComponentStringifier {
   
    public static final Log LOG = LogFactory.getLog(ISOComponentStringifier.class);
   
    private static final String INDENTATION = "  ";

    private ISOComponentStringifier() {
    }
   
    public static String stringify(ISOComponent c) {
        return stringify(c, "");
    }
   
    public static String stringify(ISOComponent c, String indentation) {
       
        if (c instanceof ISOMsg) {
            return stringify((ISOMsg) c, new StringBuffer(indentation).append(INDENTATION).toString());
        } else if (c instanceof ISOField) {
            return stringify((ISOField) c,  new StringBuffer(indentation).append(INDENTATION).toString());
        } else if (c instanceof ISOBinaryField) {
            return stringify((ISOBinaryField) c,  new StringBuffer(indentation).append(INDENTATION).toString());
        } else if (c instanceof ISOBitMap) {
            return stringify((ISOBitMap) c,  new StringBuffer(indentation).append(INDENTATION).toString());
        } else {
            return null;
        }
    }
   
    private static String stringify(byte[] headerBytes, String string) {
        BASE1Header base1Header = new BASE1Header();
        base1Header.unpack(headerBytes);
        return "\nHeader is rejected = [" + base1Header.isRejected() + "]";
    }

    public static String stringify(ISOMsg f) {
        return stringify(f, "");
    }
   
    public static String stringify(ISOMsg m, String indentation) {
        StringBuffer stringifiedISOMsg = new StringBuffer("\n");
        if (m == null) {
            return stringifiedISOMsg.append(indentation).append("ISOMsg(" + null + ")").toString();
        }
        try {
            stringifiedISOMsg.append(indentation).append("ISOMsg(" + (m.isInner() ? m.getKey() : "no field number"+ ") = [");
        } catch (ISOException e) {
        }
        if (m.getHeader() != null) {
            stringifiedISOMsg.append(indentation).append(stringify(m.getHeader(), indentation));
        } else {
            stringifiedISOMsg.append(indentation).append("No header");
        }
        for (int i = -1; i <= m.getMaxField(); i++) {
           
            ISOComponent subfield = m.getComponent(i);
            if (subfield != null) {
                stringifiedISOMsg.append(stringify(subfield, new StringBuffer(indentation).toString()));
            }
        }
        return stringifiedISOMsg.append("\n").append(indentation).append("]").toString();
    }

    public static String stringify(ISOField f) {
        return stringify(f, "");
    }
   
    private static String stringify(ISOField f, String indentation) {
        StringBuffer stringifiedISOField = new StringBuffer();
        stringifiedISOField.append("\n")
                           .append(indentation)
                           .append("ISOField fieldnum = [")
                           .append(f.getKey())
                           .append("], value = [")
                           .append(f.getValue())
                           .append("]");
        return stringifiedISOField.toString();
    }
   
    public static String stringify(ISOBinaryField bf) {
        return stringify(bf, "");
    }
   
    private static String stringify(ISOBinaryField bf, String indentation) {
        StringBuffer stringifiedISOField = new StringBuffer();
        stringifiedISOField.append("\n")
                           .append(indentation)
                           .append("ISOBinaryField fieldnum = [")
                           .append(bf.getKey())
                           .append("], value = [")
                           .append(new String((byte[]) bf.getValue()))
                           .append("]");
        return stringifiedISOField.toString();
    }
   
    public static String stringify(ISOBitMap bm) {
        return stringify(bm, "");
    }
   
    public static String stringify(ISOBitMap bm, String indentation) {
        StringBuffer stringifiedISOField = new StringBuffer();
        stringifiedISOField.append("\n")
                           .append(indentation)
                           .append("ISOBitMap fieldnum = [")
                           .append(bm.getKey())
                           .append("], value = [")
                           .append(bm.getValue())
                           .append("]");
        return stringifiedISOField.toString();
    }
   
}
TOP

Related Classes of org.jpos.util.ISOComponentStringifier

TOP
Copyright © 2018 www.massapi.com. 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.