/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2004 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas_ejb.lib;


import java.lang.reflect.Field;
import javax.transaction.Status;

/**
 * @author Christophe Ney : Initial developer
 */
public class StatusHelper {
    public static String getStatusName(int status) {
        String statusName = null;
        try {
            Field[] flds = Status.class.getDeclaredFields();
            for (int i = 0; i < flds.length; i++) {
                if (flds[i].getInt(null) == status)
                    statusName = flds[i].getName();
            }
        } catch (Exception e) {
            statusName = "invalid status value!";
        }
        return statusName;
    }

    public static void listStatusValues() {
        System.out.println("ACTIVE=" + Status.STATUS_ACTIVE);
        System.out.println("COMMITTED=" + Status.STATUS_COMMITTED);
        System.out.println("COMMITTING=" + Status.STATUS_COMMITTING);
        System.out.println("MARKED_ROLLBACK=" + Status.STATUS_MARKED_ROLLBACK);
        System.out.println("NO_TRANSACTION=" + Status.STATUS_NO_TRANSACTION);
        System.out.println("PREPARED=" + Status.STATUS_PREPARED);
        System.out.println("PREPARING=" + Status.STATUS_PREPARING);
        System.out.println("ROLLEDBACK=" + Status.STATUS_ROLLEDBACK);
        System.out.println("ROLLING_BACK=" + Status.STATUS_ROLLING_BACK);
        System.out.println("UNKNOWN=" + Status.STATUS_UNKNOWN);
    }
}
