View Javadoc

1   /*
2    * Copyright 2004-2005 Dan Washusen
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.reactive.configuration;
18  
19  import org.apache.commons.configuration.ConfigurationFactory;
20  import org.springframework.core.io.Resource;
21  
22  import java.io.IOException;
23  
24  /***
25   * An extension of the org.apache.commons.configuration.ConfigurationFactory that takes a spring
26   * org.springframework.core.io.Resource.
27   *
28   * <p>An example of the bean factory configuration required for Commons Configuration</p>
29   * <pre>
30   * &lt;bean id="commonsConfigurationFactory" class="org.reactive.configuration.CommonsConfigurationFactory" singleton="true"&gt;
31   *      &lt;property name="configurationResource"&gt;
32   *          &lt;value&gt;classpath:/org/reactive/beans/factory/config/ConfigurationPlaceholderProcessorTest_configuration.xml&lt;/value&gt;
33   *      &lt;/property&gt;
34   *  &lt;/bean&gt;
35   *
36   *  &lt;bean id="configuration" factory-bean="commonsConfigurationFactory" factory-method="getConfiguration" /&gt;
37   *
38   *  &lt;bean id="configurationPlaceholderProcessor" class="org.reactive.beans.factory.config.ConfigurationPlaceholderProcessor"&gt;
39   *      &lt;property name="placeholderEvaluator"&gt;
40   *          &lt;bean class="org.reactive.beans.factory.config.commons.CommonsPlaceholderEvaluator"&gt;
41   *              &lt;property name="configuration"&gt;
42   *                  &lt;ref bean="configuration"/&gt;
43   *              &lt;/property&gt;
44   *          &lt;/bean&gt;
45   *      &lt;/property&gt;
46   *  &lt;/bean&gt;
47   * </pre>
48   *
49   * @author Dan Washusen
50   * @version $Id: CommonsConfigurationFactory.java,v 1.1 2004/12/26 23:42:29 dan_washusen Exp $
51   * @since 16.12.2004
52   * @see org.springframework.core.io.DefaultResourceLoader
53   */
54  public class CommonsConfigurationFactory
55          extends ConfigurationFactory {
56      /***
57       * Set the resource that the configuration factory will use to instantiate instances of
58       * org.apache.commons.configuration.Configuration.  This method simple calls
59       * org.apache.commons.configuration.ConfigurationFactory.setConfigurationURL(resource.getURL()).
60       * <p>An example might be "classpath:/configuration.xml" to load the configuration.xml file from
61       * the root of the classpath.</p>
62       * @param resource The resource that the configuration factory will use to instantiate instances of
63       * org.apache.commons.configuration.Configuration
64       * @throws IOException If an error occurs while attempting to create a URL for the resource.
65       */
66      public void setConfigurationResource(Resource resource)
67              throws IOException {
68          super.setConfigurationURL(resource.getURL());
69      }
70  }