/* 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 MethodTransaction implements Comparable {
    private MethodDescriptor methodDesc;
    private byte transactionAttr = TransactionAttribute.TX_BEAN_MANAGED;

    public MethodTransaction() {

    }

    public MethodDescriptor getMethod() {
        return methodDesc;
    }

    public void setMethod(MethodDescriptor methodDesc) {
        this.methodDesc = methodDesc;
    }

    public byte getTransactionAttr() {
        return transactionAttr;
    }

    public String getTransactionAttributeString() {
        return TransactionAttribute.getTransactionAttrString(transactionAttr);
    }

    public void setTransactionAttr(byte i) {
        switch(i) {
            case TransactionAttribute.TX_NOT_SUPPORTED: // '\0'
            case TransactionAttribute.TX_SUPPORTS: // '\002'
            case TransactionAttribute.TX_REQUIRED: // '\003'
            case TransactionAttribute.TX_REQUIRES_NEW: // '\004'
            case TransactionAttribute.TX_MANDATORY: // '\005'
            case TransactionAttribute.TX_NEVER: // '\006'
                transactionAttr = i;
                break;

            case 1: // '\001'
            default:
                throw new IllegalArgumentException("Invalid transaction attribute: " + i);
        }
    }

    public void setTransactionAttributeString(String transactionAttrString) {
        transactionAttr = TransactionAttribute.getTransactionAttribute(transactionAttrString);
    }

    public int compareTo(Object obj) {
        MethodTransaction mtd = (MethodTransaction) obj;
        return methodDesc.compareTo(mtd.methodDesc);
    }

    public boolean equals(Object obj) {
        if(obj != null && (obj instanceof MethodTransaction)) {
            MethodTransaction containertransaction = (MethodTransaction) obj;
            return methodDesc.equals(containertransaction.methodDesc);
        }
        else {
            return false;
        }
    }

    public int hashCode() {
        return methodDesc.hashCode();
    }

    public static void main(String[] args) {

    }
}

