1
19
20 package com.liferay.portal.spring.context;
21
22 import com.liferay.portal.kernel.configuration.Configuration;
23 import com.liferay.portal.kernel.configuration.ConfigurationFactoryUtil;
24 import com.liferay.portal.kernel.log.Log;
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
26 import com.liferay.portal.kernel.portlet.PortletClassLoaderUtil;
27 import com.liferay.portal.kernel.util.AggregateClassLoader;
28 import com.liferay.portal.kernel.util.ArrayUtil;
29 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
30 import com.liferay.portal.util.PropsKeys;
31
32 import java.io.FileNotFoundException;
33
34 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
35 import org.springframework.web.context.support.XmlWebApplicationContext;
36
37
49 public class PortletApplicationContext extends XmlWebApplicationContext {
50
51 protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
52 reader.setBeanClassLoader(
53 new AggregateClassLoader(
54 PortletClassLoaderUtil.getClassLoader(),
55 PortalClassLoaderUtil.getClassLoader()));
56 }
57
58 protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
59 String[] configLocations = getPortletConfigLocations();
60
61 if (configLocations == null) {
62 return;
63 }
64
65 for (String configLocation : configLocations) {
66 try {
67 reader.loadBeanDefinitions(configLocation);
68 }
69 catch (Exception e) {
70 Throwable cause = e.getCause();
71
72 if (cause instanceof FileNotFoundException) {
73 if (_log.isWarnEnabled()) {
74 _log.warn(cause.getMessage());
75 }
76 }
77 else {
78 _log.error(e, e);
79 }
80 }
81 }
82 }
83
84 protected String[] getPortletConfigLocations() {
85 String[] configLocations = getConfigLocations();
86
87 ClassLoader classLoader = PortletClassLoaderUtil.getClassLoader();
88
89 Configuration serviceBuilderPropertiesConfiguration = null;
90
91 try {
92 serviceBuilderPropertiesConfiguration =
93 ConfigurationFactoryUtil.getConfiguration(
94 classLoader, "service");
95 }
96 catch (Exception e) {
97 if (_log.isDebugEnabled()) {
98 _log.debug("Unable to read service.properties");
99 }
100
101 return configLocations;
102 }
103
104 return ArrayUtil.append(
105 configLocations,
106 serviceBuilderPropertiesConfiguration.getArray(
107 PropsKeys.SPRING_CONFIGS));
108 }
109
110 private static Log _log =
111 LogFactoryUtil.getLog(PortletApplicationContext.class);
112
113 }