01: /*****************************************************************************
02: * Copyright (C) NanoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: *****************************************************************************/package com.opensymphony.webwork.pico;
09:
10: import com.opensymphony.xwork.ObjectFactory;
11: import org.picocontainer.defaults.ObjectReference;
12: import org.picocontainer.gems.adapters.ThreadLocalReference;
13:
14: import javax.servlet.*;
15: import javax.servlet.http.HttpServletRequest;
16: import java.io.IOException;
17:
18: /**
19: * Filter which initialises a PicoObjectFactory as the XWork ObjectFactory
20: * and passes to it the HttpServletRequest.
21: *
22: * @author Jonas Engman
23: * @deprecated Use {@link PicoFilterDispatcher}
24: */
25: public class PicoObjectFactoryFilter implements Filter {
26:
27: private final static String ALREADY_FILTERED_KEY = "nanocontainer_objectfactory_filtered";
28:
29: private ObjectReference objectReference;
30:
31: public void init(FilterConfig config) throws ServletException {
32: objectReference = new ThreadLocalReference();
33: ObjectFactory.setObjectFactory(new PicoObjectFactory(
34: objectReference));
35: }
36:
37: public void doFilter(ServletRequest request,
38: ServletResponse response, FilterChain chain)
39: throws IOException, ServletException {
40: HttpServletRequest httpServletRequest = (HttpServletRequest) request;
41: if (httpServletRequest.getAttribute(ALREADY_FILTERED_KEY) == null) {
42: httpServletRequest.setAttribute(ALREADY_FILTERED_KEY,
43: Boolean.TRUE);
44: objectReference.set(httpServletRequest);
45: try {
46: chain.doFilter(request, response);
47: } finally {
48: objectReference.set(null);
49: }
50: } else {
51: chain.doFilter(request, response);
52: }
53: }
54:
55: public void destroy() {
56: }
57: }
|