Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../img/srcFileCovDistChart0.png 29% of files have more coverage
19   99   7   9,5
8   51   0,37   2
2     3,5  
1    
3,3% of code in this file is excluded from these metrics.
 
  PropertiesEnumeration       Line # 41 19 7 0% 0.0
 
No Tests
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10    * This library is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this library; if not, write to the Free Software
17    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18    *
19    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23   
24    package net.smartlab.web;
25   
26    import java.lang.reflect.Constructor;
27    import java.net.URL;
28    import java.util.Iterator;
29    import java.util.Map;
30    import java.util.Properties;
31    import java.util.TreeMap;
32   
33    import org.apache.commons.logging.Log;
34    import org.apache.commons.logging.LogFactory;
35   
36    /**
37    * TODO documentation
38    * @author rlogiacco
39    *
40    */
 
41    public abstract class PropertiesEnumeration extends StringEnumeration {
42   
43    private static final long serialVersionUID = 228095287903246251L;
44   
45    private static final Class[] TYPES = new Class[] {
46    String.class, String.class
47    };
48   
49    private static Map enumerations = new TreeMap();
50   
51    private Map values;
52   
53    /**
54    * Provides logging capabilities.
55    */
56    protected final static Log logger = LogFactory.getLog(PropertiesEnumeration.class);
57   
58   
59    /**
60    * TODO documentation
61    */
 
62  0 toggle public PropertiesEnumeration() {
63  0 if (logger.isDebugEnabled()) {
64  0 logger.debug("PropertiesEnumeration() - start");
65    }
66  0 synchronized (this.getClass()) {
67  0 values = (Map)enumerations.get(this.getClass());
68  0 if (values == null) {
69  0 try {
70  0 String classname = this.getClass().getName();
71  0 URL url = this.getClass().getResource(classname.substring(classname.lastIndexOf('.') + 1) + ".properties");
72  0 Properties properties = new Properties();
73  0 properties.load(url.openStream());
74  0 Iterator entries = properties.entrySet().iterator();
75  0 Constructor instantiator = this.getClass().getConstructor(TYPES);
76  0 values = new TreeMap();
77  0 while (entries.hasNext()) {
78  0 Map.Entry entry = (Map.Entry)entries.next();
79  0 if (logger.isTraceEnabled()) {
80  0 logger.trace(" adding (" + entry.getKey() + ", " + entry.getValue() + ")");
81    }
82  0 values.put(entry.getKey(), instantiator.newInstance(new Object[] {
83    entry.getKey(), entry.getValue()
84    }));
85    }
86    } catch (Exception e) {
87    logger.error("PropertiesEnumeration() - failed", e);
88    }
89    }
90    }
91    }
92   
93    /**
94    * @see net.smartlab.web.StringEnumeration#decode(java.lang.String)
95    */
 
96  0 toggle public StringEnumeration decode(String code) {
97  0 return (StringEnumeration)values.get(code);
98    }
99    }