EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.service.impl]

COVERAGE SUMMARY FOR SOURCE FILE [PropertyFileSymbolSource.java]

nameclass, %method, %block, %line, %
PropertyFileSymbolSource.java100% (1/1)100% (3/3)82%  (77/94)87%  (20/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PropertyFileSymbolSource100% (1/1)100% (3/3)82%  (77/94)87%  (20/23)
addProperties (Log, String, String): void 100% (1/1)73%  (46/63)81%  (13/16)
PropertyFileSymbolSource (Log, List): void 100% (1/1)100% (26/26)100% (6/6)
valueForSymbol (String): String 100% (1/1)100% (5/5)100% (1/1)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.service.impl;
16 
17import java.io.File;
18import java.io.FileInputStream;
19import java.io.IOException;
20import java.io.InputStream;
21import java.util.List;
22import java.util.Properties;
23 
24import org.apache.commons.logging.Log;
25import org.apache.hivemind.SymbolSource;
26import org.apache.hivemind.impl.BaseLocatable;
27 
28/**
29 * Implementation of {@link org.apache.hivemind.SymbolSource} driven
30 * off of a property file.
31 *
32 * @author Jean-Francois Poilpret
33 */
34public class        PropertyFileSymbolSource
35        extends                BaseLocatable
36        implements        SymbolSource
37{
38        public PropertyFileSymbolSource(Log logger, List<PropertyFileContribution> parameters)
39        {
40                for (PropertyFileContribution contrib: parameters)
41                {
42                        addProperties(logger, contrib.getFile(), contrib.getProperty());
43                }
44        }
45        
46        private void        addProperties(Log logger, String path, String property)
47        {
48                String actualPath = path;
49                if (actualPath == null)
50                {
51                        // Configuration does not define path but a system property where
52                        // to find actual path
53                        actualPath = System.getProperty(property);
54                }
55                Properties properties = new Properties(_allProperties);
56                try
57                {
58                        File file = new File(actualPath);
59                        if (!file.exists())
60                        {
61                                logger.error("Problem reading property file [" + actualPath + "]");
62                                return;
63                        }
64                        InputStream input = new FileInputStream(file);
65                        properties.load(input);
66                        input.close();
67                }
68                catch (IOException e)
69                {
70                        logger.error("Problem reading property file [" + actualPath + "]", e);
71                }
72                _allProperties = properties;
73        }
74 
75        public String valueForSymbol(String name)
76        {
77                return _allProperties.getProperty(name);
78        }
79 
80        private Properties        _allProperties = new Properties();
81}

[all classes][net.sourceforge.hiveutils.service.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov