view gnv/src/main/java/de/intevation/gnv/action/sessionmodel/SessionModelFactory.java @ 36:ad381cc47217

Format Code to max 80 Chars per Row gnv/trunk@172 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 02 Oct 2009 08:54:13 +0000
parents 4405f31bbc30
children 14eecfde4607
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.action.sessionmodel;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 * 
 */
public class SessionModelFactory {

    public final static String SESSION_MODEL_ID = "de.intevation.gnv.action.sessionmodel.SessionModel.ID";
    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(SessionModelFactory.class);

    /**
     * The singleton Instance of this Factory.
     */
    private static SessionModelFactory instance = null;

    /**
     * Constructor
     */
    private SessionModelFactory() {
        super();
    }

    /**
     * This Method provides an singleton Instance of this Class.
     * 
     * @return an singleton Instance of this Class
     */
    public static SessionModelFactory getInstance() {
        if (instance == null) {
            instance = new SessionModelFactory();
        }
        return instance;
    }

    /**
     * Getting the ArtifactDatabaseClient
     * 
     * @return the ArtifactDatabaseClient
     */
    public SessionModel getSessionModel(HttpServletRequest request) {
        synchronized (this.getClass()) {
            SessionModel sm = null;
            if (request.getSession().getAttribute(SESSION_MODEL_ID) != null) {
                sm = (SessionModel) request.getSession().getAttribute(
                        SESSION_MODEL_ID);
                ;
            } else {
                sm = new DefaultSessionModel();
                request.getSession().setAttribute(SESSION_MODEL_ID, sm);
            }

            return sm;
        }
    }

}

http://dive4elements.wald.intevation.org