1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.spring.context;
21  
22  import com.liferay.portal.bean.BeanLocatorImpl;
23  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  
27  import java.io.FileNotFoundException;
28  
29  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
30  import org.springframework.context.ApplicationContext;
31  import org.springframework.web.context.support.XmlWebApplicationContext;
32  
33  /**
34   * <a href="TunnelApplicationContext.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class TunnelApplicationContext extends XmlWebApplicationContext {
40  
41      public void setParent(ApplicationContext parent) {
42          if (parent == null) {
43              BeanLocatorImpl beanLocatorImpl =
44                  (BeanLocatorImpl)PortalBeanLocatorUtil.getBeanLocator();
45  
46              parent = beanLocatorImpl.getApplicationContext();
47          }
48  
49          super.setParent(parent);
50      }
51  
52      protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
53          String[] configLocations = getConfigLocations();
54  
55          if (configLocations == null) {
56              return;
57          }
58  
59          for (String configLocation : configLocations) {
60              try {
61                  reader.loadBeanDefinitions(configLocation);
62              }
63              catch (Exception e) {
64                  Throwable cause = e.getCause();
65  
66                  if (cause instanceof FileNotFoundException) {
67                      if (_log.isWarnEnabled()) {
68                          _log.warn(cause.getMessage());
69                      }
70                  }
71                  else {
72                      _log.error(e, e);
73                  }
74              }
75          }
76      }
77  
78      private static Log _log =
79           LogFactoryUtil.getLog(TunnelApplicationContext.class);
80  
81  }