/*
 * Copyright 2008-2013 Red Hat, Inc, and individual contributors.
 * 
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.torquebox.core.component;

import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;
import org.torquebox.core.util.RuntimeHelper;

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 IRubyObject newInstance(Ruby runtime, Object[] initParams) {
        if (this.requirePath != null) {
            runtime.getLoadService().load( this.requirePath + ".rb", false );
        }
        
        return RuntimeHelper.instantiate( runtime, this.className, initParams );
    }
    
    public String toString() {
        return this.className;
    }

}

@@ -1576,24 +1576,101 @@
 itParams) %7B%0A
+        synchronized((%22ComponentClassLock%22 + this.className).intern()) %7B%0A    
         if (
@@ -1709,16 +1709,20 @@
         
+   
+ 
 runtime.
@@ -1743,17 +1743,16 @@
 ().load(
- 
 this.req
@@ -1774,17 +1774,16 @@
 %22, false
- 
 );%0A     
@@ -1789,19 +1789,19 @@
     
-%7D%0A
     
+%7D%0A%0A
     
-%0A
     
@@ -1837,17 +1837,16 @@
 antiate(
- 
 runtime,
@@ -1876,12 +1876,21 @@
 rams
- 
 );%0A
+        %7D%0A
     

Fix a race condition for multiple services of the same class (TORQUE-1058)