EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.app.pojo.impl]

COVERAGE SUMMARY FOR SOURCE FILE [PojoContext.java]

nameclass, %method, %block, %line, %
PojoContext.java100% (1/1)83%  (5/6)59%  (112/190)61%  (19.5/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PojoContext100% (1/1)83%  (5/6)59%  (112/190)61%  (19.5/32)
loadPropertiesFile (String): void 0%   (0/1)0%   (0/47)0%   (0/10)
putProperty (String, String): void 100% (1/1)33%  (14/43)60%  (3.6/6)
putProperties (Map): void 100% (1/1)93%  (28/30)98%  (5.9/6)
<static initializer> 100% (1/1)100% (30/30)100% (3/3)
PojoContext (String, String []): void 100% (1/1)100% (20/20)100% (4/4)
getPackagePath (): String [] 100% (1/1)100% (20/20)100% (3/3)

1package org.jtoolkit.essence.app.pojo.impl;
2 
3import org.apache.commons.logging.Log;
4import static org.apache.commons.logging.LogFactory.getLog;
5import org.jetbrains.annotations.NotNull;
6import org.jtoolkit.essence.utils.IOUtils;
7import org.jtoolkit.essence.utils.Named;
8 
9import java.io.FileNotFoundException;
10import java.io.IOException;
11import java.util.LinkedHashMap;
12import java.util.Map;
13import java.util.Properties;
14import java.util.Set;
15 
16/*
17   Copyright 2006 Peter Lawrey
18 
19   Licensed under the Apache License, Version 2.0 (the "License");
20   you may not use this file except in compliance with the License.
21   You may obtain a copy of the License at
22 
23       http://www.apache.org/licenses/LICENSE-2.0
24 
25   Unless required by applicable law or agreed to in writing, software
26   distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
27   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28   See the License for the specific language governing permissions and
29   limitations under the License.
30*/
31 
32/**
33 * This define a context for building data value objects and components.
34 * Its package.path is used to lookup class names and properties are used to expand ${} in values.
35 *
36 * @author Peter Lawrey
37 */
38@SuppressWarnings("unchecked")
39public class PojoContext {
40    private static final Log LOG = getLog(PojoContext.class);
41    private static final String[] BASE_PACKAGE_PATH = {"org.jtoolkit", "java.lang", ""};
42 
43    public static final PojoContext EMPTY = new PojoContext("", new String[] { "" });
44 
45    private final Map<String, String> propertiesMap;
46    public final Named.Source<String> properties;
47 
48    public PojoContext(String name, String[] contexts) {
49        propertiesMap = new LinkedHashMap<String, String>();
50        properties = new Named.ContextSource<String>(name, new Named.MapSource<String>(propertiesMap), contexts);
51    }
52 
53    /**
54     * Add unset proeprties to this context.  However, properties once set do not change.
55     */
56    public void putProperties(@NotNull Map map) {
57        for (Map.Entry entry : (Set<Map.Entry>) map.entrySet()) {
58            String key = String.valueOf(entry.getKey());
59            String value = entry.getValue() == null ? null : String.valueOf(entry.getValue());
60            putProperty(key, value);
61        }
62    }
63 
64    public void putProperty(String key, String value) {
65        Object prev = propertiesMap.get(key);
66        if (prev != null && !prev.equals(value)) {
67            if (LOG.isDebugEnabled())
68                LOG.debug(Thread.currentThread().getName() + ": Property " + key + " remains " + prev + " not overriden to " + value);
69        } else {
70            propertiesMap.put(key, value);
71        }
72    }
73 
74    /**
75     * @return the base search path for packages.  This is a list of prefix strings and can be class names to refer to inner classes.
76     */
77    @NotNull public String[] getPackagePath() {
78        Object path = propertiesMap.get("package.path");
79        if (path == null) return BASE_PACKAGE_PATH;
80        return (path + "::java.lang").split("[,:;] ?");
81    }
82 
83    /**
84     * Add unset proeprties from a properties file.
85     */
86    public void loadPropertiesFile(@NotNull String filename) {
87        Properties prop = new Properties();
88        try {
89            prop.load(IOUtils.getInputStream(filename));
90            putProperties(prop);
91        } catch (FileNotFoundException ignored) {
92            if (LOG.isDebugEnabled())
93                LOG.debug(Thread.currentThread().getName() + ": Properties file not found " + filename);
94        } catch (IOException e) {
95            throw new Error("Error loading " + filename + " exiting!", e);
96        }
97    }
98}

[all classes][org.jtoolkit.essence.app.pojo.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov