All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpos.util.SimpleMsg Maven / Gradle / Ivy

Go to download

jPOS is an ISO-8583 based financial transaction library/framework that can be customized and extended in order to implement financial interchanges.

There is a newer version: 3.0.0
Show newest version
/*
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2017 jPOS Software SRL
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package  org.jpos.util;

import org.jpos.iso.ISOUtil;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Collection;

/**
 * 

* A simple general purpose loggeable message. *

* @author Hani S. Kirollos * @version $Revision$ $Date$ */ public class SimpleMsg implements Loggeable { String tagName; String msgName; Object msgContent; public SimpleMsg (String tagName, String msgName, Object msgContent) { this.tagName = tagName; this.msgName = msgName; if(msgContent instanceof byte[]) this.msgContent = ISOUtil.hexString((byte[])msgContent); else this.msgContent = msgContent; } public SimpleMsg (String tagName, Object msgContent) { this(tagName, null, msgContent); } /** * dumps message * @param p a PrintStream usually supplied by Logger * @param indent indention string, usually suppiled by Logger * @see org.jpos.util.Loggeable */ @Override public void dump (PrintStream p, String indent) { String inner = indent + " "; p.print(indent + "<" + tagName); if (msgName != null) p.print(" name=\"" + msgName + "\""); Collection cl = null; if (msgContent instanceof Object[]) cl = Arrays.asList((Object[]) msgContent); else if (msgContent instanceof Collection) cl = (Collection) msgContent; else if (msgContent instanceof Loggeable) cl = Arrays.asList(msgContent); else if (msgName != null && msgContent == null){ p.println("/>"); return; } else if (msgName != null) cl = Arrays.asList(msgContent); else if (msgContent != null) p.print(">" + msgContent); else { p.println("/>"); return; } if (cl != null) { p.println(">"); for (Object o : cl) { if (o instanceof Loggeable) ((Loggeable) o).dump(p, inner); else p.println(inner + o); } p.print(indent); } p.println(""); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy