View Javadoc

1   /*
2    * $Id: MuleApplicationContext.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.extras.spring.config;
12  
13  import java.io.IOException;
14  
15  import org.springframework.beans.BeansException;
16  import org.springframework.beans.factory.support.DefaultListableBeanFactory;
17  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
18  import org.springframework.context.support.AbstractXmlApplicationContext;
19  import org.springframework.core.io.Resource;
20  
21  /**
22   * <code>MuleApplicationContext</code> is A Simple extension Application context
23   * that allows rosurces to be loaded from the Classpath of file system using the
24   * MuleBeanDefinitionReader.
25   * 
26   * @see MuleBeanDefinitionReader
27   */
28  public class MuleApplicationContext extends AbstractXmlApplicationContext
29  {
30      private final Resource[] configResources;
31      private final String[] configLocations;
32  
33      public MuleApplicationContext(Resource[] configResources)
34      {
35          this(configResources, true);
36      }
37  
38      public MuleApplicationContext(Resource[] configResources, boolean refresh) throws BeansException
39      {
40          this.configResources = configResources;
41          this.configLocations = null;
42          if (refresh)
43          {
44              refresh();
45          }
46      }
47  
48      public MuleApplicationContext(String[] configLocations)
49      {
50          this(configLocations, true);
51      }
52  
53      public MuleApplicationContext(String[] configLocations, boolean refresh) throws BeansException
54      {
55          this.configLocations = configLocations;
56          this.configResources = null;
57          if (refresh)
58          {
59              refresh();
60          }
61      }
62  
63      //@Override
64      protected Resource[] getConfigResources() 
65      {
66          return configResources;
67      }
68      
69      //@Override
70      protected String[] getConfigLocations()
71      {
72          return configLocations;
73      }
74  
75      //@Override
76      protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException 
77      {
78          XmlBeanDefinitionReader beanDefinitionReader = new MuleBeanDefinitionReader(beanFactory,
79              configResources != null ? configResources.length : configLocations.length);
80  
81          initBeanDefinitionReader(beanDefinitionReader);
82          loadBeanDefinitions(beanDefinitionReader);
83      }
84  }