HttpSessionStoringAdapter.java :  » Inversion-of-Control » PicoContainer » org » picocontainer » gems » web » Java Open Source

Java Open Source » Inversion of Control » PicoContainer 
PicoContainer » org » picocontainer » gems » web » HttpSessionStoringAdapter.java
/*****************************************************************************
 * Copyright (C) NanoContainer Organization. All rights reserved.            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *                                                                           *
 *****************************************************************************/

package org.picocontainer.gems.web;

import org.picocontainer.behaviors.Storing;

import javax.servlet.http.HttpSession;

/** @author Paul Hammant */
public class HttpSessionStoringAdapter {

    private Storing storingBehavior;
    private final String name;

    public HttpSessionStoringAdapter(Storing storingBehavior, String name) {
        this.storingBehavior = storingBehavior;
        this.name = name;
    }

    public synchronized void retrieveOrCreateStore(HttpSession session) {
        Storing.StoreWrapper sr = (Storing.StoreWrapper)session.getAttribute(name);
        if (sr != null) {
            storingBehavior.putCacheForThread(sr);
        } else {
            session.setAttribute(name, storingBehavior.resetCacheForThread());

        }
    }

    public void resetStore() {
        storingBehavior.resetCacheForThread();
    }

    public void invalidateStore() {
        storingBehavior.invalidateCacheForThread();
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.