/**
 * The MIT License
 *
 * Copyright (C) 2015 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package de.alpharogroup.bundle.app.spring;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.FactoryConfigurationError;

import org.apache.log4j.xml.DOMConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

import de.alpharogroup.bundle.management.service.locator.ServiceLocator;
import de.alpharogroup.db.resource.bundles.entities.BundleApplications;
import de.alpharogroup.db.resource.bundles.entities.LanguageLocales;
import de.alpharogroup.db.resource.bundles.entities.Languages;
import de.alpharogroup.db.resource.bundles.service.api.BundleApplicationsService;
import de.alpharogroup.db.resource.bundles.service.api.BundleNamesService;
import de.alpharogroup.db.resource.bundles.service.api.LanguageLocalesService;
import de.alpharogroup.db.resource.bundles.service.api.LanguagesService;
import de.alpharogroup.db.resource.bundles.service.api.PropertiesKeysService;
import de.alpharogroup.db.resource.bundles.service.api.ResourcebundlesService;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * The Class SpringApplicationContext.
 */
@Slf4j
public class SpringApplicationContext
{

	/** The instance. */
	private static SpringApplicationContext instance = new SpringApplicationContext();

	/**
	 * Gets the single instance of SpringApplicationContext.
	 *
	 * @return single instance of SpringApplicationContext
	 */
	public static SpringApplicationContext getInstance()
	{
		return instance;
	}

	@Getter
	@Setter
	@Autowired
	private ServiceLocator serviceLocator;

	private BundleNamesService bundleNamesService;

	private BundleApplicationsService bundleApplicationsService;

	private ResourcebundlesService resourcebundlesService;

	private PropertiesKeysService propertiesKeysService;

	/** The application context. */
	@Getter
	private final ApplicationContext applicationContext;

	/**
	 * Instantiates a new spring application context.
	 */
	private SpringApplicationContext()
	{

		final String rootContextDirectoryClassPath = "/ctx";

		final String applicationContextPath = rootContextDirectoryClassPath
			+ "/application-context.xml";

		final ApplicationContext ac = new ClassPathXmlApplicationContext(applicationContextPath);

		final Resource resource = ac.getResource("classpath:conf/log4j/log4jconfig.xml");

		// initDb(ac);

		try
		{
			DOMConfigurator.configure(resource.getURL());
		}
		catch (final FactoryConfigurationError e)
		{
			log.error("FactoryConfigurationError:", e);
		}
		catch (final IOException e)
		{
			log.error("IOException:", e);
		}

		applicationContext = ac;
	}

	public BundleApplicationsService getBundleApplicationsService()
	{
		if (bundleApplicationsService == null)
		{
			bundleApplicationsService = (BundleApplicationsService)applicationContext
				.getBean("bundleApplicationsService");
		}
		return bundleApplicationsService;
	}

	public BundleNamesService getBundleNamesService()
	{
		if (bundleNamesService == null)
		{
			bundleNamesService = (BundleNamesService)applicationContext
				.getBean("bundleNamesService");
		}
		return bundleNamesService;
	}

	protected void initDb(final ApplicationContext ac)
	{
		LanguagesService languagesService = (LanguagesService)ac.getBean("languagesService");
		LanguageLocalesService languageLocalesService = (LanguageLocalesService)ac
			.getBean("languageLocalesService");
		BundleApplicationsService bundleApplicationsService = getBundleApplicationsService();

		final List<Languages> languages = DataObjectFactory.newLanguageList();
		for (final Languages language : languages)
		{
			final Languages found = languagesService.find(language.getName(),
				language.getIso639Dash1());
			if (found == null)
			{
				languagesService.merge(language);
			}
		}
		final List<LanguageLocales> languageLocales = DataObjectFactory.newLanguageLocales();

		for (final LanguageLocales languageLocale : languageLocales)
		{
			final LanguageLocales found = languageLocalesService.find(languageLocale.getLocale());
			if (found == null)
			{
				languageLocalesService.merge(languageLocale);
			}
		}

		BundleApplications baseBundleApplication = bundleApplicationsService
			.find(BundleApplications.BASE_BUNDLE_APPLICATION);
		if (baseBundleApplication == null)
		{
			baseBundleApplication = BundleApplications.builder()
				.name(BundleApplications.BASE_BUNDLE_APPLICATION).build();
			baseBundleApplication = bundleApplicationsService.merge(baseBundleApplication);
		}
	}

	public ResourcebundlesService getResourcebundlesService()
	{
		if (resourcebundlesService == null)
		{
			resourcebundlesService = (ResourcebundlesService)applicationContext
				.getBean("resourcebundlesService");
		}
		return resourcebundlesService;
	}

	public PropertiesKeysService getPropertiesKeysService()
	{
		if (propertiesKeysService == null)
		{
			propertiesKeysService = (PropertiesKeysService)applicationContext
				.getBean("propertiesKeysService");
		}
		return propertiesKeysService;
	}

}

@@ -1329,24 +1329,73 @@
 nfigurator;%0A
+import org.springframework.beans.BeansException;%0A
 import org.s
@@ -2853,16 +2853,399 @@
 ce;%0A%09%7D%0A%0A
+%09 /**%0A %09 * Gets the bean.%0A %09 *%0A %09 * @param %3CT%3E the generic type%0A %09 * @param context the context%0A %09 * @param name the name%0A %09 * @param clazz the clazz%0A %09 * @return the bean%0A %09 * @throws BeansException the beans exception%0A %09 */%0A %09public static %3CT%3E T getBean(ApplicationContext context, String name, Class%3CT%3E clazz) throws BeansException %7B%0A%09%09 return context.getBean(name, clazz);%0A%09 %7D%0A%09%0A
 %09@Getter

Update SpringApplicationContext.java