package org.torquebox.core.component;

import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.javasupport.JavaEmbedUtils;
import org.jruby.runtime.builtin.IRubyObject;

public class ComponentClass implements ComponentInstantiator {
    
    private String className;
    private String requirePath;

    public ComponentClass() {
        
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public String getClassName() {
        return this.className;
    }
    
    public void setRequirePath(String requirePath) {
        this.requirePath = requirePath;
    }
    
    public String getRequirePath() {
        return this.requirePath;
    }
    
    public RubyModule getComponentClass(Ruby runtime) {
        if (this.requirePath != null) {
            runtime.getLoadService().load( this.requirePath + ".rb", false );
        }

        RubyModule componentClass = (RubyModule) runtime.getClassFromPath( this.className );
        
        if (componentClass == null || componentClass.isNil()) {
            return null;
        }
        
        return componentClass;
    }
    
    public IRubyObject newInstance(Ruby runtime, Object[] initParams) {
        RubyModule rubyClass = getComponentClass( runtime );
        IRubyObject component = (IRubyObject) JavaEmbedUtils.invokeMethod( runtime, this.className, "new", initParams, IRubyObject.class );
        return component;
    }
    
    

}

@@ -1369,30 +1369,25 @@
 untime, 
-this.className
+rubyClass
 , %22new%22,

Instantiate the Ruby class, not the string class name