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 org.picocontainer.gems.web;
09:
10: import org.picocontainer.behaviors.Storing;
11:
12: import javax.servlet.http.HttpSession;
13:
14: /** @author Paul Hammant */
15: public class HttpSessionStoringAdapter {
16:
17: private Storing storingBehavior;
18: private final String name;
19:
20: public HttpSessionStoringAdapter(Storing storingBehavior,
21: String name) {
22: this .storingBehavior = storingBehavior;
23: this .name = name;
24: }
25:
26: public synchronized void retrieveOrCreateStore(HttpSession session) {
27: Storing.StoreWrapper sr = (Storing.StoreWrapper) session
28: .getAttribute(name);
29: if (sr != null) {
30: storingBehavior.putCacheForThread(sr);
31: } else {
32: session.setAttribute(name, storingBehavior
33: .resetCacheForThread());
34:
35: }
36: }
37:
38: public void resetStore() {
39: storingBehavior.resetCacheForThread();
40: }
41:
42: public void invalidateStore() {
43: storingBehavior.invalidateCacheForThread();
44: }
45:
46: }
|