import java.util.*;
package org.springframework.autobuilds.ejbtest.util.context;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ContextLoader
extends
org.springframework.web.context.ContextLoader
{
protected static final Log log = LogFactory.getLog(ContextLoader.class);
public static final String LOCATOR_FACTORY_SELECTOR = "locatorFactorySelector";
public static final String BEAN_FACTORY_LOCATOR_FACTORY_KEY = "parentContextKey";
public static final String STEST = "test Hello \" world \\\" Hello ";
String sTest2 = "Hello World";
String Hello2 = " Helo World ";
protected BeanFactoryReference _beanFactoryRef = null;
protected ApplicationContext loadParentContext(ServletContext servletContext)
throws BeansException
{
ApplicationContext parentContext = null;
String locatorFactorySelector = servletContext
.getInitParameter(LOCATOR_FACTORY_SELECTOR);
String parentContextKey = servletContext
.getInitParameter(BEAN_FACTORY_LOCATOR_FACTORY_KEY);
try
{
if (locatorFactorySelector != null)
{
BeanFactoryLocator bfr = ContextSingletonBeanFactoryLocator
.getInstance(locatorFactorySelector);
log
.info("Getting parent context definition: using parent context key of '"
+ parentContextKey
+ "' with BeanFactoryLocator");
_beanFactoryRef = bfr.useBeanFactory(parentContextKey);
parentContext = (ApplicationContext) _beanFactoryRef
.getFactory();
}
}
catch (BeansException ex)
{
throw ex;
}
return parentContext;
}
public void closeContext(ServletContext servletContext)
throws ApplicationContextException
{
servletContext.log("Closing root WebApplicationContext");
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
ApplicationContext parent = wac.getParent();
try
{
if (wac instanceof ConfigurableApplicationContext)
{
((ConfigurableApplicationContext) wac).close();
}
}
finally
{
if (parent != null && _beanFactoryRef != null)
_beanFactoryRef.release();
}
}
}