| 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.resources; | |
| 34 | ||
| 35 | import java.util.Map; | |
| 36 | import java.util.Set; | |
| 37 | ||
| 38 | import org.chwf.config.Config; | |
| 39 | import org.chwf.config.ConfigFactory; | |
| 40 | import org.chwf.util.SequencedHashMap; | |
| 41 | ||
| 42 | /** | |
| 43 | * A wrapper for the ResourceManager configuration. | |
| 44 | * | |
| 45 | * @author Paul Strack | |
| 46 | */ | |
| 47 | 1 | public class ResourceManagerConfig { |
| 48 | ||
| 49 | /** The default factory key name. */ | |
| 50 | public static final String DEFAULT_FACTORY = ""; | |
| 51 | ||
| 52 | /** Lookup key for classes. */ | |
| 53 | private static final String CLASSES_KEY = "factories.*.default-factory"; | |
| 54 | ||
| 55 | /** Empty string array. */ | |
| 56 | 1 | private static final String[] EMPTY_ARRAY = new String[0]; |
| 57 | ||
| 58 | /** The raw config. */ | |
| 59 | private final Config config; | |
| 60 | ||
| 61 | /** | |
| 62 | * Retrieve configuration. | |
| 63 | * | |
| 64 | * @return The configuration. | |
| 65 | */ | |
| 66 | static ResourceManagerConfig getConfig() { | |
| 67 | 1 | Config config = ConfigFactory.getConfig(ResourceManagerConfig.class); |
| 68 | 1 | return new ResourceManagerConfig(config); |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Constructor. | |
| 73 | * | |
| 74 | * @param config Raw configuration. | |
| 75 | */ | |
| 76 | 7 | public ResourceManagerConfig(Config config) { |
| 77 | 7 | this.config = config; |
| 78 | 7 | } |
| 79 | ||
| 80 | /** | |
| 81 | * The resource class names. | |
| 82 | * | |
| 83 | * @return The class names as an array of strings. | |
| 84 | */ | |
| 85 | public String[] getResourceClasses() { | |
| 86 | 2 | Set keys = config.getMap(CLASSES_KEY).keySet(); |
| 87 | 2 | String[] array = new String[keys.size()]; |
| 88 | 2 | keys.toArray(array); |
| 89 | 2 | return array; |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * A map with the factory names as its keys, the factory class names | |
| 94 | * (as strings) as its values. The default factory's name is "". | |
| 95 | * | |
| 96 | * @param resourceClass The class whose factories are being retrieved. | |
| 97 | * @return The map of factories. | |
| 98 | */ | |
| 99 | public Map getFactoryClasses(String resourceClass) { | |
| 100 | 5 | String namedFactoryKey = "factories." + resourceClass + ".*.class"; |
| 101 | 5 | Map map = new SequencedHashMap(config.getMap(namedFactoryKey)); |
| 102 | 5 | String defaultFactory = |
| 103 | config.get("factories." + resourceClass + ".default-factory"); | |
| 104 | 5 | map.put(DEFAULT_FACTORY, defaultFactory); |
| 105 | 5 | return map; |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * A map of properties associated with the named factory. Properties | |
| 110 | * for the default factory can be retrieved using the DEFAULT_FACTORY | |
| 111 | * constant for the factory name. | |
| 112 | * | |
| 113 | * @param resourceClass The class whose factories are being retrieved. | |
| 114 | * @param name The factory name. | |
| 115 | * @return The map of factory properties. | |
| 116 | */ | |
| 117 | public Map getFactoryProperties(String resourceClass, String name) { | |
| 118 | 8 | String key = null; |
| 119 | 8 | if (name.length() > 0) { |
| 120 | 5 | key = "factories." + resourceClass + "." + name + ".properties"; |
| 121 | } else { | |
| 122 | 3 | key = "factories." + resourceClass + ".properties"; |
| 123 | } | |
| 124 | 8 | return config.getMap(key); |
| 125 | } | |
| 126 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |