View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.resources.impl;
19  
20  import org.apache.commons.resources.Resources;
21  import org.apache.commons.resources.ResourcesException;
22  
23  /**
24   * <p>Concrete implementation of
25   * {@link org.apache.commons.resources.ResourcesFactory} that creates
26   * {@link org.apache.commons.resources.Resources} instances that wraps
27   * a JDBC database connection and retrieves values for the given
28   * <code>Locale</code> and have name suffixes reflecting the
29   * <code>Locale</code> for which the document's messages apply.
30   * For this specific implementation, resources are looked up in
31   * a hierarchy of database values in a manner identical to that
32   * performed by <code>java.util.ResourceBundle.getBundle().</code>.
33   *
34   * @author James Mitchell
35   * @version $Revision: 775615 $
36   */
37  public class JDBCResourcesFactory extends ResourcesFactoryBase {
38  
39  
40      // ------------------------------------------------------ Protected Methods
41  
42  
43      /**
44       * <p>Create and return a new {@link org.apache.commons.resources.Resources}
45       * instance with the specified logical name, after calling its <code>init()</code>
46       * method and delegating the relevant properties.</p>
47       *
48       * @param name Logical name of the {@link org.apache.commons.resources.Resources}
49       * instance to create
50       *
51       * @param config Configuration string for this resource (if any)
52       * @return The new Resources instance.
53       *
54       * @exception ResourcesException if a {@link org.apache.commons.resources.Resources}
55       * instance of the specified logical name cannot be created.
56       */
57      protected Resources createResources(String name, String config) {
58  
59          Resources res = new JDBCResources(name, config);
60          res.setReturnNull(isReturnNull());
61          res.init();
62          return (res);
63  
64      }
65  
66  
67  }