Line | Hits | Source |
---|---|---|
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 | ||
38 | /** | |
39 | * <p>A subclass of <code>Config</code> that adds the superclass configuration | |
40 | * to the configuration search path. Other than the factory method, it may | |
41 | * be used in every respect like the {@link Config} class.</p> | |
42 | * | |
43 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
44 | */ | |
45 | 1 | class PolymorphicConfigImpl extends ConfigImpl { |
46 | ||
47 | /** The raw config object. */ | |
48 | private final Config config; | |
49 | ||
50 | /** The polymorphic config object for the superclass. */ | |
51 | private final Config superClassConfig; | |
52 | ||
53 | /** | |
54 | * Constructor. | |
55 | * | |
56 | * @param contextClass The context class for the configuration. | |
57 | * @param locale The locale. | |
58 | */ | |
59 | PolymorphicConfigImpl(Class contextClass, Locale locale) { | |
60 | 378 | super(contextClass, locale); |
61 | 378 | this.config = ConfigFactory.getConfig(contextClass, locale); |
62 | 378 | if (contextClass.equals(Object.class)) { |
63 | 144 | superClassConfig = ConfigFactory.TERMINAL_CONFIG; |
64 | } else { | |
65 | 234 | Class superclass = contextClass.getSuperclass(); |
66 | 234 | this.superClassConfig = PolymorphicConfig.getConfig(superclass, locale); |
67 | } | |
68 | 378 | } |
69 | ||
70 | /** | |
71 | * Overrides the behavior of superclass to add the context class's superclass | |
72 | * configuration to the configuration search path.<p> | |
73 | * | |
74 | * @param key The search key, which is used as the initial part | |
75 | * of property keys. | |
76 | * @return The map, or an empty map if no property keys beginning with | |
77 | * the search key. | |
78 | */ | |
79 | public Map getOrderedMap(String key) { | |
80 | 685 | Map map = config.getOrderedMap(key); |
81 | 685 | if (map.isEmpty()) { |
82 | 634 | map = superClassConfig.getOrderedMap(key); |
83 | } | |
84 | 685 | return map; |
85 | } | |
86 | ||
87 | /** | |
88 | * Overrides the behavior of superclass to add the superclass configuration | |
89 | * to the configuration search path. | |
90 | * | |
91 | * @param key The lookup key. | |
92 | * @return The raw value. | |
93 | */ | |
94 | public String getRawValue(String key) { | |
95 | 398 | String value = (String) ((RawConfig) config).getRawValue(key); |
96 | 398 | if (value == null) { |
97 | 362 | value = ((RawConfig) superClassConfig).getRawValue(key); |
98 | } | |
99 | 398 | return value; |
100 | } | |
101 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |