/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.ejb.meta;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class TransactionAttribute {
    public static final byte TX_NOT_SUPPORTED = 0;
    public static final byte TX_BEAN_MANAGED = 1;
    public static final byte TX_SUPPORTS = 2;
    public static final byte TX_REQUIRED = 3;
    public static final byte TX_REQUIRES_NEW = 4;
    public static final byte TX_MANDATORY = 5;
    public static final byte TX_NEVER = 6;

    public static String getTransactionAttrString(byte transactionAttr) {
        switch(transactionAttr) {
            case TransactionAttribute.TX_NOT_SUPPORTED: // '\0'
                return "NotSupported";

            case TransactionAttribute.TX_SUPPORTS: // '\002'
                return "Supports";

            case TransactionAttribute.TX_REQUIRED: // '\003'
                return "Required";

            case TransactionAttribute.TX_REQUIRES_NEW: // '\004'
                return "RequiresNew";

            case TransactionAttribute.TX_MANDATORY: // '\005'
                return "Mandatory";

            case TransactionAttribute.TX_NEVER: // '\006'
                return "Never";

            case 1: // '\001'
            default:
                return "Unknown!!";
        }

    }

    public static byte getTransactionAttribute(String transactionAttrString) {
        if(transactionAttrString.equals("NotSupported"))
            return TransactionAttribute.TX_NOT_SUPPORTED;
        else if(transactionAttrString.equals("Supports"))
            return TransactionAttribute.TX_SUPPORTS;
        else if(transactionAttrString.equals("Required"))
            return TransactionAttribute.TX_REQUIRED;
        else if(transactionAttrString.equals("RequiresNew"))
            return TransactionAttribute.TX_REQUIRES_NEW;
        else if(transactionAttrString.equals("Mandatory"))
            return TransactionAttribute.TX_MANDATORY;
        else if(transactionAttrString.equals("Never"))
            return TransactionAttribute.TX_NEVER;
        else
            throw new IllegalArgumentException("Unknwon transaction attribute: " + transactionAttrString);
    }

    public static void main(String[] args) {

    }
}

