package cuke4duke.internal.jvmclass;

import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

/**
 * @author Henning Jensen
 */
public class GuiceFactory implements ObjectFactory {

	private final Module module;
    private final List<Class<?>> classes = new ArrayList<Class<?>>();
    private final Map<Class<?>, Object> instanceMap = new HashMap<Class<?>, Object>();
    private Injector injector;

    public GuiceFactory() throws Throwable {
        String moduleClassName = System.getProperty("cuke4duke.guiceModule", null);
        module = (Module) Class.forName(moduleClassName).newInstance();
    }

    public void addClass(Class<?> clazz) {
        classes.add(clazz);
    }

    public void addInstance(Object instance) {
    }

    public void createObjects() {
        injector = Guice.createInjector(module);
		for(Class<?> clazz: classes) {
	        instanceMap.put(clazz, injector.getInstance(clazz));
		}
    }

    public void disposeObjects() {
    }

    public Object getComponent(Class<?> clazz) {
        return instanceMap.get(clazz);
    }

}

@@ -230,16 +230,45 @@
 .Module;
+%0Aimport cuke4duke.StepMother;
 %0A%0A/**%0A *
@@ -877,35 +877,69 @@
  add
-Instance(Object instance) %7B
+StepMother(StepMother mother) %7B%0A        // Not supported yet.
 %0A   

Rename method to inject step mother