1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.spring.context;
16  
17  import com.liferay.portal.bean.BeanLocatorImpl;
18  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  
22  import java.io.FileNotFoundException;
23  
24  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
25  import org.springframework.context.ApplicationContext;
26  import org.springframework.web.context.support.XmlWebApplicationContext;
27  
28  /**
29   * <a href="TunnelApplicationContext.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class TunnelApplicationContext extends XmlWebApplicationContext {
34  
35      public void setParent(ApplicationContext parent) {
36          if (parent == null) {
37              BeanLocatorImpl beanLocatorImpl =
38                  (BeanLocatorImpl)PortalBeanLocatorUtil.getBeanLocator();
39  
40              parent = beanLocatorImpl.getApplicationContext();
41          }
42  
43          super.setParent(parent);
44      }
45  
46      protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
47          String[] configLocations = getConfigLocations();
48  
49          if (configLocations == null) {
50              return;
51          }
52  
53          for (String configLocation : configLocations) {
54              try {
55                  reader.loadBeanDefinitions(configLocation);
56              }
57              catch (Exception e) {
58                  Throwable cause = e.getCause();
59  
60                  if (cause instanceof FileNotFoundException) {
61                      if (_log.isWarnEnabled()) {
62                          _log.warn(cause.getMessage());
63                      }
64                  }
65                  else {
66                      _log.error(e, e);
67                  }
68              }
69          }
70      }
71  
72      private static Log _log = LogFactoryUtil.getLog(
73          TunnelApplicationContext.class);
74  
75  }