/* 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.framework.extra;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.jfox.framework.util.Methods;

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

public class ManagementOperationInfo implements Serializable, Comparable {
    private String description;
    private Method method;
    private String hash = null;

    public ManagementOperationInfo(Method method) {
        this(method, method.getName());
    }

    public ManagementOperationInfo(Method method, String description) {
        this.method = method;
        this.description = description;
    }

    public String getName() {
        return method.getName();
    }

    public String getDescription() {
        return description;
    }

    public Class[] getParameterTypes() {
        return method.getParameterTypes();
    }

    public Class getReturnType() {
        return method.getReturnType();
    }

    public String getMethodHashCode() {
        if(hash == null) {
            hash = "" + Methods.getMethodHash(method);
        }
        return hash;
    }


    public String toString() {
        return "ManagementOperationInfo{" +
                "hash='" + hash + "'" +
                ", description='" + description + "'" +
                ", method=" + method +
                "}";
    }

    public int compareTo(Object o) {
        if(o instanceof ManagementOperationInfo) {
            return getName().compareTo(((ManagementOperationInfo) o).getName());
        }
        return 0;
    }

    public boolean isGetter() {
        return Methods.isGetMethod(method);
    }

    public Method getMethod() {
        return method;
    }

    public static void main(String[] args) {

    }
}

