/************************************************
 * 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.impl;

import net.sf.joyaop.framework.Aspect;
import net.sf.joyaop.framework.RuntimeAspect;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Shen Li
 */
class RuntimeAspectInstanceFactory {
    private final Map aspectInstances = new HashMap();
    private final Class originalClass;

    public RuntimeAspectInstanceFactory(Class originalClass) {
        this.originalClass = originalClass;
    }

    public RuntimeAspectInstance getRuntimeAspectInstance(RuntimeAspect aspect) {
        RuntimeAspectInstance aspectInstance = (RuntimeAspectInstance) aspectInstances.get(aspect.getAspectClass());
        if (aspectInstance == null) {
            aspectInstance = new RuntimeAspectInstance(aspect, originalClass);
            aspectInstances.put(aspect.getAspectClass(), aspectInstance);
        }
        return aspectInstance;
    }
}