EMMA Coverage Report (generated Fri Jul 28 01:51:09 CEST 2006)
[all classes][org.jtiger.framework]

COVERAGE SUMMARY FOR SOURCE FILE [ClassAliasMappingFactory.java]

nameclass, %method, %block, %line, %
ClassAliasMappingFactory.java100% (2/2)100% (7/7)89%  (89/100)87%  (27/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClassAliasMappingFactory100% (1/1)100% (2/2)100% (7/7)100% (3/3)
ClassAliasMappingFactory (): void 100% (1/1)100% (3/3)100% (2/2)
newClassAliasMapping (): ClassAliasMapping 100% (1/1)100% (4/4)100% (1/1)
     
class ClassAliasMappingFactory$ClassAliasMappingImpl100% (1/1)100% (5/5)88%  (82/93)86%  (24/28)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)
ClassAliasMappingFactory$ClassAliasMappingImpl (): void 100% (1/1)100% (3/3)100% (2/2)
getAliases (): ReadOnlyArray 100% (1/1)80%  (12/15)60%  (3/5)
getMappedClassName (String): String 100% (1/1)100% (17/17)100% (6/6)
initialiseMapping (): void 100% (1/1)85%  (45/53)85%  (11/13)

1/*
2 * JTiger Unit Testing Framework for J2SE 1.5
3 * Copyright (C) 2005 Tony Morris
4 *
5 * This software is licenced under the
6 * Common Public Licence version 1.0
7 * http://www.opensource.org/licenses/cpl1.0.php
8 *
9 * You received a copy of this licence with this software.
10 */
11package org.jtiger.framework;
12 
13import static org.jtiger.framework.SequenceFactory.newSequence;
14import java.util.Properties;
15import java.util.Map;
16import java.util.HashMap;
17import java.util.Set;
18import java.io.InputStream;
19import java.io.IOException;
20 
21/**
22 * Provides an alias name to a class name using {@link #CLASS_ALIAS_MAPPING_RESOURCE a resource} as the mapping. This
23 * resource forms part of the JTiger core.
24 *
25 * @see ClassAliasMapping
26 * @author %javadoc.author.tag%
27 * @version %version%<br/>
28 *          <i>Build Number %build.number%</i><br/>
29 *          <i>Build Time %build.time% CET (GMT + 1)</i>
30 */
31public final class ClassAliasMappingFactory
32{
33    /**
34     * The value that aliases are prefixed with before being obtained by calling
35     * {@link ClassAliasMapping#getMappedClassName(String)}. That is, if an alias exists in the resource as "alias", the value
36     * that is mapped to that alias can be obtained by calling
37     * <code>{@link ClassAliasMapping#getMappedClassName(String) theClassAliasMapping.getMappedClassName(ALIAS_PREFIX + "alias")}</code>
38     */
39    public static final String ALIAS_PREFIX = "~";
40 
41    /**
42     * The name of the resource that provides the class name mapping. This resource forms part of the JTiger core.
43     */
44    public static final String CLASS_ALIAS_MAPPING_RESOURCE = "/org/jtiger/classaliases.properties";
45 
46    private ClassAliasMappingFactory()
47    {
48 
49    }
50 
51    /**
52     * Returns a new <code>ClassAliasMapping</code> instance.
53     *
54     * @return A new <code>ClassAliasMapping</code> instance.
55     */
56    public static ClassAliasMapping newClassAliasMapping()
57    {
58        return new ClassAliasMappingImpl();
59    }
60 
61    private static final class ClassAliasMappingImpl implements ClassAliasMapping
62    {
63        private static final Map<String, String> m;
64        private static boolean initialised;
65 
66        static
67        {
68            m = new HashMap<String, String>();
69        }
70 
71        ClassAliasMappingImpl()
72        {
73 
74        }
75 
76        public String getMappedClassName(final String alias) throws NullPointerException
77        {
78            if(alias == null)
79            {
80                throw new NullPointerException();
81            }
82 
83            if(!initialised)
84            {
85                initialiseMapping();
86                initialised = true;
87            }
88 
89            return ClassAliasMappingImpl.m.get(alias.toLowerCase());
90        }
91 
92        public ReadOnlyArray<String> getAliases()
93        {
94            if(!initialised)
95            {
96                initialiseMapping();
97                initialised = true;
98            }
99 
100            final Set<String> keys = ClassAliasMappingImpl.m.keySet();
101            return newSequence(keys.toArray(new String[keys.size()]));
102        }
103 
104        private static void initialiseMapping()
105        {
106            final InputStream in = ClassAliasMappingImpl.class.getResourceAsStream(CLASS_ALIAS_MAPPING_RESOURCE);
107            final Properties props = new Properties();
108 
109            try
110            {
111                props.load(in);
112 
113                final Set<Object> names = props.keySet();
114 
115                for(Object o : names)
116                {
117                    final String name = (String)o;
118                    final String aliasedName = new StringBuilder(ALIAS_PREFIX).append(name.toLowerCase()).toString();
119                    ClassAliasMappingImpl.m.put(aliasedName, props.getProperty(name));
120                }
121            }
122            catch(IOException e)
123            {
124                throw new IllegalStateException(e.getMessage(), e);
125            }
126        }
127    }
128}

[all classes][org.jtiger.framework]
EMMA 2.0.5312 (C) Vladimir Roubtsov