/*
 * Copyright (C) 2010-2014 Hamburg Sud and the contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.aludratest.config;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;

import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/** Helper class and entry point to AludraTest Configuration Service.
 * 
 * @author falbrech */
public class ComponentConfigurator {

    private static final Logger LOGGER = LoggerFactory.getLogger(ComponentConfigurator.class);

    private static Configurator configurator;

    private ComponentConfigurator() {
    }

    private static Configurator getConfigurator() {
        if (configurator == null) {
            // use on-the-fly Plexus to get instance
            DefaultPlexusContainer container = null;
            try {
                container = new DefaultPlexusContainer();
                configurator = container.lookup(Configurator.class);
            }
            catch (PlexusContainerException e) {
                LOGGER.error("Could not create on-the-fly IoC container", e);
            }
            catch (ComponentLookupException e) {
                LOGGER.error("Could not find configurator implementation", e);
            }
            finally {
                if (container != null) {
                    container.dispose();
                }
            }
        }
        return configurator;
    }

    /** Configures the given configurable object.
     * 
     * @param configurable Object to configure.
     * 
     * @deprecated Please prefer one of these methods to configure your objects:
     *             <ol>
     *             <li>Retrieve your objects via <code>AludraServiceManager</code>, <code>AludraTestContext</code> or
     *             <code>AludraServiceContext</code>, and their methods to instantiate new objects. These will automatically
     *             configure the objects.</li>
     *             <li>If you require to directly configure an object, retrieve an {@link Configurator} instance from one of the
     *             mentioned classes, and use it to configure your object.</li>
     *             </ol> */
    @Deprecated
    public static void configure(Configurable configurable) {
        getConfigurator().configure(configurable);
    }

    /** Configures the given configurable object, instantiated for the given instance name.
     * 
     * @param instanceName Name of the instance, which is used for configuration lookup.
     * @param configurable Object to configure.
     * 
     * @deprecated Please prefer one of these methods to configure your objects:
     *             <ol>
     *             <li>Retrieve your objects via <code>AludraServiceManager</code>, <code>AludraTestContext</code> or
     *             <code>AludraServiceContext</code>, and their methods to instantiate new objects. These will automatically
     *             configure the objects.</li>
     *             <li>If you require to directly configure an object, retrieve an {@link Configurator} instance from one of the
     *             mentioned classes, and use it to configure your object.</li>
     *             </ol> */
    @Deprecated
    public static void configure(String instanceName, Configurable configurable) {
        getConfigurator().configure(instanceName, configurable);
    }

    /** Fills the given Preferences object with the Properties loaded from a given resource name. This is useful to implement
     * {@link Configurable#fillDefaults(MutablePreferences)}.
     * 
     * @param preferences Preferences object to fill.
     * @param resourceName Resource name to load as a Properties file.
     * @param classLoader ClassLoader to use to look for the resource.
     * 
     * @throws IOException If the resource could not be loaded. */
    public static void fillPreferencesFromPropertiesResource(MutablePreferences preferences, String resourceName,
            ClassLoader classLoader) throws IOException {
        Enumeration<URL> urls = classLoader.getResources(resourceName);

        while (urls.hasMoreElements()) {
            InputStream in = urls.nextElement().openStream();
            try {
                Properties p = new Properties();
                p.load(in);

                // copy to Preferences
                Enumeration<?> keyNames = p.propertyNames();
                while (keyNames.hasMoreElements()) {
                    String key = keyNames.nextElement().toString();
                    preferences.setValue(key, p.getProperty(key));
                }
            }
            finally {
                try {
                    in.close();
                }
                catch (IOException e2) { // NOSONAR
                }
            }
        }
    }

}

@@ -788,3318 +788,181 @@
 s;%0A%0A
-import org.codehaus.plexus.DefaultPlexusContainer;%0Aimport org.codehaus.plexus.PlexusContainerException;%0Aimport org.codehaus.plexus.component.repository.exception.ComponentLookupException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A%0A/** Helper class and entry point to AludraTest Configuration Service.%0A * %0A * @author falbrech */%0Apublic class ComponentConfigurator %7B%0A%0A    private static final Logger LOGGER = LoggerFactory.getLogger(ComponentConfigurator.class);%0A%0A    private static Configurator configurator;%0A%0A    private ComponentConfigurator() %7B%0A    %7D%0A%0A    private static Configurator getConfigurator() %7B%0A        if (configurator == null) %7B%0A            // use on-the-fly Plexus to get instance%0A            DefaultPlexusContainer container = null;%0A            try %7B%0A                container = new DefaultPlexusContainer();%0A                configurator = container.lookup(Configurator.class);%0A            %7D%0A            catch (PlexusContainerException e) %7B%0A                LOGGER.error(%22Could not create on-the-fly IoC container%22, e);%0A            %7D%0A            catch (ComponentLookupException e) %7B%0A                LOGGER.error(%22Could not find configurator implementation%22, e);%0A            %7D%0A            finally %7B%0A                if (container != null) %7B%0A                    container.dispose();%0A                %7D%0A            %7D%0A        %7D%0A        return configurator;%0A    %7D%0A%0A    /** Configures the given configurable object.%0A     * %0A     * @param configurable Object to configure.%0A     * %0A     * @deprecated Please prefer one of these methods to configure your objects:%0A     *             %3Col%3E%0A     *             %3Cli%3ERetrieve your objects via %3Ccode%3EAludraServiceManager%3C/code%3E, %3Ccode%3EAludraTestContext%3C/code%3E or%0A     *             %3Ccode%3EAludraServiceContext%3C/code%3E, and their methods to instantiate new objects. These will automatically%0A     *             configure the objects.%3C/li%3E%0A     *             %3Cli%3EIf you require to directly configure an object, retrieve an %7B@link Configurator%7D instance from one of the%0A     *             mentioned classes, and use it to configure your object.%3C/li%3E%0A     *             %3C/ol%3E */%0A    @Deprecated%0A    public static void configure(Configurable configurable) %7B%0A        getConfigurator().configure(configurable);%0A    %7D%0A%0A    /** Configures the given configurable object, instantiated for the given instance name.%0A     * %0A     * @param instanceName Name of the instance, which is used for configuration lookup.%0A     * @param configurable Object to configure.%0A     * %0A     * @deprecated Please prefer one of these methods to configure your objects:%0A     *             %3Col%3E%0A     *             %3Cli%3ERetrieve your objects via %3Ccode%3EAludraServiceManager%3C/code%3E, %3Ccode%3EAludraTestContext%3C/code%3E or%0A     *             %3Ccode%3EAludraServiceContext%3C/code%3E, and their methods to instantiate new objects. These will automatically%0A     *             configure the objects.%3C/li%3E%0A     *             %3Cli%3EIf you require to directly configure an object, retrieve an %7B@link Configurator%7D instance from one of the%0A     *             mentioned classes, and use it to configure your object.%3C/li%3E%0A     *             %3C/ol%3E */%0A    @Deprecated%0A    public static void configure(String instanceName, Configurable configurable) %7B%0A        getConfigurator().configure(instanceName, configurable);
+%0A/** Helper class and entry point to AludraTest Configuration Service.%0A * %0A * @author falbrech */%0Apublic class ComponentConfigurator %7B%0A%0A    private ComponentConfigurator() %7B
 %0A   

Remove deprecated code