001
014
015 package com.liferay.portal.spring.context;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.util.PropsValues;
020
021 import java.io.FileNotFoundException;
022
023 import javax.servlet.ServletContext;
024
025 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
026 import org.springframework.context.ApplicationContext;
027 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
028 import org.springframework.web.context.support.XmlWebApplicationContext;
029
030
041 public class PortalApplicationContext extends XmlWebApplicationContext {
042
043 public static final String PARENT_APPLICATION_CONTEXT =
044 PortalApplicationContext.class.getName() +
045 "#PARENT_APPLICATION_CONTEXT";
046
047 @Override
048 public ApplicationContext getParent() {
049 return _parentApplicationContext;
050 }
051
052 @Override
053 public void setServletContext(ServletContext servletContext) {
054 super.setServletContext(servletContext);
055
056 _parentApplicationContext =
057 (ApplicationContext)servletContext.getAttribute(
058 PARENT_APPLICATION_CONTEXT);
059
060 setParent(_parentApplicationContext);
061 }
062
063 @Override
064 protected void loadBeanDefinitions(
065 XmlBeanDefinitionReader xmlBeanDefinitionReader) {
066
067 try {
068 super.loadBeanDefinitions(xmlBeanDefinitionReader);
069 }
070 catch (Exception e) {
071 if (_log.isWarnEnabled()) {
072 _log.warn(e, e);
073 }
074 }
075
076 xmlBeanDefinitionReader.setResourceLoader(
077 new PathMatchingResourcePatternResolver());
078
079 if (PropsValues.SPRING_CONFIGS == null) {
080 return;
081 }
082
083 for (String configLocation : PropsValues.SPRING_CONFIGS) {
084 try {
085 xmlBeanDefinitionReader.loadBeanDefinitions(configLocation);
086 }
087 catch (Exception e) {
088 Throwable cause = e.getCause();
089
090 if (cause instanceof FileNotFoundException) {
091 if (_log.isWarnEnabled()) {
092 _log.warn(cause.getMessage());
093 }
094 }
095 else {
096 _log.error(e, e);
097 }
098 }
099 }
100 }
101
102 private static final Log _log = LogFactoryUtil.getLog(
103 PortalApplicationContext.class);
104
105 private ApplicationContext _parentApplicationContext;
106
107 }