Coverage details for org.chwf.config.PolymorphicConfig

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.config;
34  
35 import java.util.Locale;
36 import java.util.Map;
37 import java.util.WeakHashMap;
38  
39 /**
40  * <p>A subclass of <code>Config</code> that adds the superclass configuration
41  * to the configuration search path. Other than the factory method, it may
42  * be used in every respect like the {@link Config} class.</p>
43  *
44  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
45  */
460public class PolymorphicConfig extends ConfigImpl {
47  
48   /**
49    * A map for storing Config objects. This map holds its
50    * contents via weak references so that references can be
51    * deleted if application memory becomes an issue. The
52    * deleted Config object will be reloaded when requested.
53    */
541  private static final Map CONFIG_MAP = new WeakHashMap();
55  
56   /**
57    * Factory method for PolymorphicConfig class.<p>
58    *
59    * @param contextClass The context class for the configuration.
60    * @return The Config object for the given class.
61    * @throws ConfigurationException For errors in loading configuration data.
62    */
63   public static Config getConfig(Class contextClass)
64     throws ConfigurationException {
65232    return getConfig(contextClass, null);
66   }
67  
68   /**
69    * Factory method for PolymorphicConfig class.<p>
70    *
71    * @param contextClass The context class for the configuration.
72    * @param locale The locale.
73    * @return The Config object for the given class.
74    * @throws ConfigurationException For errors in loading configuration data.
75    */
76   public static Config getConfig(Class contextClass, Locale locale)
77     throws ConfigurationException {
78539    String resource = contextClass.getName();
79539    Config config = null;
80539    String localeResource = resource + ConfigFactory.deriveLocaleName(locale);
81  
82     // Synchronize on the config map for thread safety
83539    synchronized (CONFIG_MAP) {
84539      config = (Config) CONFIG_MAP.get(localeResource);
85539      if (config == null) {
86378        config = new PolymorphicConfigImpl(contextClass, locale);
87378        CONFIG_MAP.put(localeResource, config);
88       }
89539    }
90     
91539    return config;
92   }
93  
94 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.