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

COVERAGE SUMMARY FOR SOURCE FILE [CompositeContext.java]

nameclass, %method, %block, %line, %
CompositeContext.java100% (1/1)10%  (1/10)3%   (6/233)7%   (3/45)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeContext100% (1/1)10%  (1/10)3%   (6/233)7%   (3/45)
CompositeContext (): void 0%   (0/1)0%   (0/3)0%   (0/2)
bind (String, Object): void 0%   (0/1)0%   (0/31)0%   (0/5)
lookup (Class): Object 0%   (0/1)0%   (0/29)0%   (0/6)
lookup (String): Object 0%   (0/1)0%   (0/29)0%   (0/6)
lookupAll (Class): Iterator 0%   (0/1)0%   (0/39)0%   (0/7)
register (Class, Object): void 0%   (0/1)0%   (0/31)0%   (0/5)
setParts (Context []): void 0%   (0/1)0%   (0/4)0%   (0/2)
unbind (String): Object 0%   (0/1)0%   (0/30)0%   (0/4)
unregister (Class, Object): void 0%   (0/1)0%   (0/31)0%   (0/5)
CompositeContext (Context []): void 100% (1/1)100% (6/6)100% (3/3)

1package com.hammurapi.common;
2 
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6 
7/**
8 * Context delegating to other contexts "parts".
9 * @author Pavel Vlasov
10 *
11 */
12public class CompositeContext implements MutableContext {
13        
14        private Context[] parts;
15        
16        public CompositeContext() {
17                // 
18        }
19 
20        public CompositeContext(Context...parts) {
21                this.parts = parts;
22        }
23        
24        public void setParts(Context...parts) {
25                this.parts = parts;
26        }
27        
28        public <T> Iterator<T> lookupAll(Class<T> serviceClass) {
29                List<T> all = new ArrayList<T>();
30                for (Context part: parts) {
31                        if (part!=null) {
32                                Iterator<T> cit = part.lookupAll(serviceClass);
33                                while (cit.hasNext()) {
34                                        all.add(cit.next());
35                                }
36                        }
37                }
38                return all.iterator();
39        }
40        
41        public <T> T lookup(Class<T> serviceClass) {
42                for (Context part: parts) {
43                        if (part!=null) {
44                                T ret = part.lookup(serviceClass);
45                                if (ret!=null) {
46                                        return ret;
47                                }
48                        }
49                }
50                return null;
51        }
52        
53        public Object lookup(String name) {
54                for (Context part: parts) {
55                        if (part!=null) {
56                                Object ret = part.lookup(name);
57                                if (ret!=null) {
58                                        return ret;
59                                }
60                        }
61                }
62                return null;
63        }
64 
65        public void bind(String name, Object obj) {
66                for (Context part: parts) {
67                        if (part instanceof MutableContext) {
68                                ((MutableContext) part).bind(name, obj);
69                                return;
70                        }
71                }
72                throw new IllegalStateException("Composite context doesn't contain mutable parts.");
73        }
74 
75        public <T> void register(Class<? super T> type, T service) {
76                for (Context part: parts) {
77                        if (part instanceof MutableContext) {
78                                ((MutableContext) part).register(type, service);
79                                return;
80                        }
81                }
82                throw new IllegalStateException("Composite context doesn't contain mutable parts.");
83        }
84 
85        public Object unbind(String name) {
86                for (Context part: parts) {
87                        if (part instanceof MutableContext) {
88                                return ((MutableContext) part).unbind(name);
89                        }
90                }
91                throw new IllegalStateException("Composite context doesn't contain mutable parts.");
92        }
93 
94        public <T> void unregister(Class<? super T> type, T service) {
95                for (Context part: parts) {
96                        if (part instanceof MutableContext) {
97                                ((MutableContext) part).unregister(type, service);
98                                return;
99                        }
100                }
101                throw new IllegalStateException("Composite context doesn't contain mutable parts.");
102        }
103}
104        

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