Package HTTP

Source Code of HTTP.HTTPSession

/*
Copyright (c) 2003-2008 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package HTTP;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Enumeration;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.keyvalue.DefaultMapEntry;

import Framework.IntervalData;
import Framework.TextData;
/**
* Use this class to specify the nature of the session established between an HTTP client and an HTTP server.
* The session object defines the network session and the application session.
* If no session object is specified, a default session object with default session values is created.
*/
public class HTTPSession implements PropertyChangeListener{
    protected IntervalData SessionTimeOut = null;
    protected HttpSession qq_baseSession = null;

    public HTTPSession() {
        super();
    }

    public void setSession(HttpSession pSession) {
        this.qq_baseSession = pSession;
    }

    public String getId() {
        return this.qq_baseSession.getId();
    }

    public IntervalData getSessionTimeOut() {
        return SessionTimeOut;
    }

    public void setSessionTimeOut(IntervalData sessionTimeOut) {
        SessionTimeOut = sessionTimeOut;
    }

    public void clearSessionData(TextData descrName) {
        this.clearSessionData(descrName.getValue());
    }

    public void clearSessionData(String descrName) {
//        this.qq_baseSession.removeAttribute(descrName);
        Map.Entry<String, Object> entry = getCaseInsensitiveSessionAttribute(descrName); // case-insensitive lookup
        if (entry != null) qq_baseSession.removeAttribute((String)entry.getKey());
    }

    public Object getSessionData(TextData descrName){
        Map.Entry<String, Object> entry = getCaseInsensitiveSessionAttribute(descrName.toString());
        if (entry != null) {
            return entry.getValue();
        } else {
            return null;
        }
    }

    public Object getSessionData(String descrName){
        Map.Entry<String, Object> entry = getCaseInsensitiveSessionAttribute(descrName);
        if (entry != null) {
            return entry.getValue();
        } else {
            return null;
        }
    }

    @SuppressWarnings("unchecked")
  private Map.Entry<String, Object> getCaseInsensitiveSessionAttribute(String attributeName) {
        Enumeration enumeration = qq_baseSession.getAttributeNames();
        while( enumeration.hasMoreElements() ) {
            String name = (String)enumeration.nextElement();
            if (name.equalsIgnoreCase(attributeName)) {
                Object result = qq_baseSession.getAttribute(name);
                return new DefaultMapEntry(name, result);
            }
        }
        return null;
    }

    public void setSessionData(TextData descrName, Object dataObj){
        Map.Entry<String, Object> entry = getCaseInsensitiveSessionAttribute(descrName.toString());
        if (entry != null) {
            this.qq_baseSession.setAttribute((String)entry.getKey(), dataObj);
        } else {
            this.qq_baseSession.setAttribute(descrName.toString(), dataObj);
        }
    }

    public void setSessionData(String descrName, Object dataObj){
        Map.Entry<String, Object> entry = getCaseInsensitiveSessionAttribute(descrName);
        if (entry != null) {
            this.qq_baseSession.setAttribute((String)entry.getKey(), dataObj);
        } else {
            this.qq_baseSession.setAttribute(descrName, dataObj);
        }
    }

    public void duplicateIntoTarget(HTTPSession pTarget, boolean pDeep) {
        pTarget.SessionTimeOut = new IntervalData(this.SessionTimeOut);
    }
    public transient PropertyChangeSupport pcListeners = new PropertyChangeSupport(this);

    public synchronized void addPropertyChangeListener(String property, PropertyChangeListener listener) {
        if (pcListeners == null)
            pcListeners = new PropertyChangeSupport(this);
        pcListeners.addPropertyChangeListener(property, listener);
    }
    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
        if (pcListeners == null)
            pcListeners = new PropertyChangeSupport(this);
        pcListeners.removePropertyChangeListener(listener);
    }
    public synchronized PropertyChangeSupport getPropertyListeners() {
        if (pcListeners == null)
            pcListeners = new PropertyChangeSupport(this);
        return this.pcListeners;
    }
    public synchronized void propertyChange(PropertyChangeEvent pcEvt) {

    }

}
TOP

Related Classes of HTTP.HTTPSession

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.