/************************************************
 * 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.ObjectFactory;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.Parameter;
import org.picocontainer.PicoIntrospectionException;
import org.picocontainer.defaults.AssignabilityRegistrationException;
import org.picocontainer.defaults.CachingComponentAdapter;
import org.picocontainer.defaults.ComponentAdapterFactory;
import org.picocontainer.defaults.NotConcreteRegistrationException;

/**
 * only for stateless components
 *
 * @author Shen Li
 */
public class AspectizedComponentAdapterFactory implements ComponentAdapterFactory {
    private final ObjectFactory objectFactory;

    public AspectizedComponentAdapterFactory(ObjectFactory objectFactory) {
        this.objectFactory = objectFactory;
    }

    public ComponentAdapter createComponentAdapter(Object componentKey,
                                                   Class componentImplementation,
                                                   Parameter[] parameters)
            throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
        return new CachingComponentAdapter(
                new ConstructorInjectionAspectizedComponentAdapter(
                        objectFactory, componentKey, componentImplementation, parameters));
    }
}
