package dst.ass2.di;

import dst.ass2.di.impl.InjectionControllerImpl;

/**
 * Creates and provides {@link IInjectionController} instances.
 */
public class InjectionControllerFactory {
    private static IInjectionController standalone = null;
    private static IInjectionController transparent = null;

    /**
     * Returns the singleton {@link IInjectionController} instance.<br/>
     * If none is available, a new one is created.
     *
     * @return the instance
     */
    public static synchronized IInjectionController getStandAloneInstance() {
        if (standalone == null) {
            standalone = getNewStandaloneInstance();
        }
        return standalone;
    }

    /**
     * Returns the singleton {@link IInjectionController} instance for processing objects modified by an
     * {@link dst.ass2.di.agent.InjectorAgent InjectorAgent}.<br/>
     * If none is available, a new one is created.
     *
     * @return the instance
     */
    public static synchronized IInjectionController getTransparentInstance() {
        if (transparent == null) {
            transparent = getNewTransparentInstance();
        }
        return transparent;
    }

    /**
     * Creates and returns a new {@link IInjectionController} instance.
     *
     * @return the newly created instance
     */
    public static IInjectionController getNewStandaloneInstance() {
        return new InjectionControllerImpl(false);
    }

    /**
     * Creates and returns a new {@link IInjectionController} instance for processing objects modified by an
     * {@link dst.ass2.di.agent.InjectorAgent InjectorAgent}.<br/>
     *
     * @return the instance
     */
    public static IInjectionController getNewTransparentInstance() {
        return new InjectionControllerImpl(true);
    }
}
