/************************************************
 * Copyright (c) Shen Li. All rights reserved.  *
 * http://joyaop.sourceforge.net                *
 * -------------------------------------------- *
 * Distributable under LGPL license.            *
 * See terms of license at gnu.org.             *
 ************************************************/
package net.sf.joyaop.extension.picocontainer;

import net.sf.joyaop.impl.DefaultAspectFactory;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;

/**
 * @author Shen Li
 */
public class PicoAspectFactory extends DefaultAspectFactory {
    private final PicoContainer picoContainer;

    public PicoAspectFactory(PicoContainer picoContainer) {
        this.picoContainer = picoContainer;
    }

    public Object newInstance(Class implementationClass) {
        MutablePicoContainer childContainer =
                new DefaultPicoContainer(new AspectAdapterFactory(this), picoContainer);
        childContainer.registerComponentImplementation(implementationClass);
        return childContainer.getComponentInstanceOfType(implementationClass);
    }
}
