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

COVERAGE SUMMARY FOR SOURCE FILE [UserContextStorageImpl.java]

nameclass, %method, %block, %line, %
UserContextStorageImpl.java0%   (0/1)0%   (0/9)0%   (0/84)0%   (0/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UserContextStorageImpl0%   (0/1)0%   (0/9)0%   (0/84)0%   (0/26)
UserContextStorageImpl (Log, SecurityService): void 0%   (0/1)0%   (0/14)0%   (0/5)
clear (): void 0%   (0/1)0%   (0/6)0%   (0/2)
clearContext (Principal): void 0%   (0/1)0%   (0/8)0%   (0/3)
get (String): Object 0%   (0/1)0%   (0/5)0%   (0/1)
getContext (): Map 0%   (0/1)0%   (0/19)0%   (0/5)
getContext (Principal): Map 0%   (0/1)0%   (0/20)0%   (0/5)
put (String, Object): void 0%   (0/1)0%   (0/7)0%   (0/2)
userConnected (Principal): void 0%   (0/1)0%   (0/1)0%   (0/1)
userDisconnected (Principal, boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)

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.hivelock;
16 
17import java.security.Principal;
18import java.util.HashMap;
19import java.util.Map;
20 
21import org.apache.commons.logging.Log;
22import org.apache.hivemind.ApplicationRuntimeException;
23 
24// singleton
25public class        UserContextStorageImpl
26        implements        UserContextStorage, UserEventListener
27{
28        public UserContextStorageImpl(Log logger, SecurityService security)
29        {
30                _logger = logger;
31                _security = security;
32        }
33        
34        public void                userConnected(Principal user)
35        {
36        }
37        
38        public void                userDisconnected(Principal user, boolean forced)
39        {
40                clearContext(user);
41        }
42 
43        public void                clear()
44        {
45                clearContext(_security.getCurrentUser());
46        }
47        
48        public Object        get(String key)
49        {
50                return getContext().get(key);
51        }
52        
53        public void                put(String key, Object value)
54        {
55                getContext().put(key, value);
56        }
57        
58        private Map<String, Object>                getContext()
59        {
60                Principal principal = _security.getCurrentUser();
61                if (principal == null)
62                {
63                        _logger.warn("No Principal in current context");
64                        throw new ApplicationRuntimeException(
65                                                        "Cannot use UserContextStorage with no Principal");
66                }
67                return getContext(principal);
68        }
69        
70        private synchronized Map<String, Object>        getContext(Principal principal)
71        {
72                Map<String, Object> context = _contexts.get(principal);
73                if (context == null)
74                {
75                        context = new HashMap<String, Object>();
76                        _contexts.put(principal, context);
77                }
78                return context;
79        }
80        
81        private synchronized void        clearContext(Principal principal)
82        {
83                if (principal != null)
84                {
85                        _contexts.remove(principal);
86                }
87        }
88 
89        final private Log                                                                        _logger;
90        final private SecurityService                                                _security;
91        final private Map<Principal, Map<String, Object>>        _contexts = 
92                                                                        new HashMap<Principal, Map<String, Object>>();
93}

[all classes][net.sourceforge.hivelock]
EMMA 2.0.5312 (C) Vladimir Roubtsov