EMMA Coverage Report (generated Thu Jan 20 11:39:44 EST 2011)
[all classes][com.hammurapi.common]

COVERAGE SUMMARY FOR SOURCE FILE [SingletonChainingContext.java]

nameclass, %method, %block, %line, %
SingletonChainingContext.java0%   (0/1)0%   (0/8)0%   (0/151)0%   (0/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SingletonChainingContext0%   (0/1)0%   (0/8)0%   (0/151)0%   (0/33)
SingletonChainingContext (Class, Object, Context): void 0%   (0/1)0%   (0/12)0%   (0/5)
bind (String, Object): void 0%   (0/1)0%   (0/17)0%   (0/4)
lookup (Class): Object 0%   (0/1)0%   (0/18)0%   (0/3)
lookup (String): Object 0%   (0/1)0%   (0/10)0%   (0/1)
lookupAll (Class): Iterator 0%   (0/1)0%   (0/45)0%   (0/9)
register (Class, Object): void 0%   (0/1)0%   (0/17)0%   (0/4)
unbind (String): Object 0%   (0/1)0%   (0/15)0%   (0/3)
unregister (Class, Object): void 0%   (0/1)0%   (0/17)0%   (0/4)

1package com.hammurapi.common;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.Iterator;
7 
8public class SingletonChainingContext<ST> implements MutableContext {
9        
10        private Class<ST> type;
11        private ST service;
12        private Context chain;
13 
14        public SingletonChainingContext(Class<ST> type, ST service, Context chain) {
15                this.type = type;
16                this.service = service;
17                this.chain = chain;
18        }
19 
20        public void bind(String name, Object obj) {
21                if (chain instanceof MutableContext) {
22                        ((MutableContext) chain).bind(name, obj);
23                } else {
24                        throw new IllegalStateException("Chain context is not mutable");
25                }
26        }
27 
28        public <T> void register(Class<? super T> type, T service) {
29                if (chain instanceof MutableContext) {
30                        ((MutableContext) chain).register(type, service);
31                } else {
32                        throw new IllegalStateException("Chain context is not mutable");
33                }
34        }
35 
36        public Object unbind(String name) {
37                if (chain instanceof MutableContext) {
38                        return ((MutableContext) chain).unbind(name);
39                } else {
40                        throw new IllegalStateException("Chain context is not mutable");
41                }                
42        }
43 
44        public <T> void unregister(Class<? super T> type, T service) {
45                if (chain instanceof MutableContext) {
46                        ((MutableContext) chain).unregister(type, service);
47                } else {
48                        throw new IllegalStateException("Chain context is not mutable");
49                }
50        }
51 
52        public Object lookup(String name) {
53                return chain==null ? null : chain.lookup(name);
54        }
55 
56        @SuppressWarnings("unchecked")
57        public <T> T lookup(Class<T> serviceClass) {
58                if (serviceClass.equals(type)) {
59                        return (T) service;
60                }
61                
62                return chain==null ? null : chain.lookup(serviceClass);
63        }
64 
65        @SuppressWarnings("unchecked")
66        public <T> Iterator<T> lookupAll(Class<T> serviceClass) {
67                if (serviceClass.equals(type)) {
68                        Collection<T> c = new ArrayList<T>();
69                        c.add((T) service);
70                        if (chain!=null) {
71                                Iterator<T> it = chain.lookupAll(serviceClass);
72                                while (it.hasNext()) {
73                                        c.add(it.next());
74                                }
75                        }
76                        return c.iterator();
77                }
78                return (Iterator<T>) (chain==null ? Collections.emptyList().iterator() : chain.lookupAll(serviceClass));
79        }
80 
81}

[all classes][com.hammurapi.common]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov