/* 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;

import java.lang.reflect.Method;
import javax.ejb.EnterpriseBean;

/**
 * 表示一个远程方法调用
 *
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class InvocationImpl implements Invocation {
    private EJBObjectId objectId = null;
    private String methodHash = null;
    private Object[] args = null;
    /**
     * method 由 bucket 在服务端设置，不传到客户端
     */
    private transient Method method = null;
    private transient EnterpriseBean bean = null;

    public InvocationImpl(EJBObjectId objectId, String methodHash, Object[] args) {
        this.objectId = objectId;
        this.methodHash = methodHash;
        this.args = args;
    }

    public EJBObjectId getObjectId() {
        return objectId;
    }

    public String getMethodHash() {
        return methodHash;
    }

    public Object[] getArgs() {
        return args;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public void setBean(EnterpriseBean instance) {
        bean = instance;
    }

    public EnterpriseBean getBean() {
        return bean;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        sb.append("ObjectId => ").append(objectId.toString()).append(", MethodHash => ").append(methodHash).append(", Args => ");
        sb.append("[");
        if(args != null) {
            for(int i = 0; i < args.length; i++) {
                sb.append(args[i].toString());
                if(i != args.length - 1) sb.append(",");
            }
        }
        sb.append("]");
        sb.append("]");
        return sb.toString();
    }

}
