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

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

public class ComponentRefParameter implements RefParameter {
    private Class type = null;
    /**
     * ComponentName of the ref component
     */
    private ComponentName refCompName;
    private Object value;

    public ComponentRefParameter(ComponentName refComponentName) {
        this.refCompName = refComponentName;
        this.type = refCompName.getImplementation();
    }

    public Class getType() {
        return type;
    }

    public String getLiteralValue() {
        return refCompName.toString();
    }

    public ComponentName getRefComponentName() {
        return refCompName;
    }

    public Object resolveValue(Registry registry) throws ComponentException {
        if(value != null) return value;
        value = registry.getComponentInstance(refCompName);
        return value;
    }

    public String toString() {
        return "ComponentRefParameter{" +
                "type=" + type.getName() +
                ", refCompName='" + refCompName + "'" +
                ", value=" + (value == null ? "NOT RESOVLED" : value.toString()) +
                "}";
    }

    public static void main(String[] args) {

    }

}
