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

COVERAGE SUMMARY FOR SOURCE FILE [HiveMindRegistryPublishFilter.java]

nameclass, %method, %block, %line, %
HiveMindRegistryPublishFilter.java0%   (0/1)0%   (0/6)0%   (0/34)0%   (0/10)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HiveMindRegistryPublishFilter0%   (0/1)0%   (0/6)0%   (0/34)0%   (0/10)
<static initializer> 0%   (0/1)0%   (0/5)0%   (0/1)
HiveMindRegistryPublishFilter (): void 0%   (0/1)0%   (0/3)0%   (0/1)
destroy (): void 0%   (0/1)0%   (0/1)0%   (0/1)
doFilter (ServletRequest, ServletResponse, FilterChain): void 0%   (0/1)0%   (0/20)0%   (0/5)
getRegistry (): Registry 0%   (0/1)0%   (0/4)0%   (0/1)
init (FilterConfig): void 0%   (0/1)0%   (0/1)0%   (0/1)

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.hiveutils.web;
16 
17import java.io.IOException;
18 
19import javax.servlet.Filter;
20import javax.servlet.FilterChain;
21import javax.servlet.FilterConfig;
22import javax.servlet.ServletException;
23import javax.servlet.ServletRequest;
24import javax.servlet.ServletResponse;
25import javax.servlet.http.HttpServletRequest;
26 
27import org.apache.hivemind.Registry;
28import org.apache.hivemind.servlet.HiveMindFilter;
29 
30/**
31 * Servlet Filter that allows retrieval of HiveMind <code>Registry</code> from
32 * any code location executed in the current thread without needing access to
33 * the <code>ServletRequest</code>.
34 * <p>
35 * It should be put in second position right after the standard
36 * <code>HiveMindFilter</code>.
37 * <p>
38 * It copies the current <code>Registry</code> to a <code>ThreadLocal</code>,
39 * making it accessible through a static method with no argument.
40 * <p>
41 * You should use this Filter <b>only</b> if you have some code that needs to
42 * access HiveMind <code>Registry</code>, but cannot have access to the current
43 * <code>ServletRequest</code>, eg if you use SecurityFilter (from Max Cooper),
44 * and your SecurityRealm needs to access the <code>Registry</code> (generally
45 * it would need to).
46 *
47 * @author Jean-Francois Poilpret
48 */
49public class HiveMindRegistryPublishFilter implements Filter
50{
51        /**
52         * Gets the HiveMind <code>Registry</code> assigned to the current thread.
53         * No argument is required.
54         */        
55        static public Registry        getRegistry()
56        {
57                return _localRegistry.get();
58        }
59        
60        public void init(FilterConfig config) throws ServletException
61        {
62        }
63 
64        public void destroy()
65        {
66        }
67        
68        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
69                throws IOException, ServletException
70        {
71                try
72                {
73                        _localRegistry.set(HiveMindFilter.getRegistry((HttpServletRequest) request));
74                        chain.doFilter(request, response);
75                }
76                finally
77                {
78                        _localRegistry.set(null);
79                }
80        }
81        
82        static protected ThreadLocal<Registry>        _localRegistry = new ThreadLocal<Registry>();
83}

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