/****************************************************************************
 *
 *	%Q%
 *
 *	All rights reserved.  Unpublished, all rights reserved under
 *	copyright law and international treaty.  Use of a copyright notice
 *	is precautionary only and does not imply publication or disclosure.
 *	This software contains confidential information and trade secrets of
 *	Micro Focus International Ltd, and no part of this program or
 *	publication may be reproduced, transmitted, transcribed, stored in
 *	a retrieval system, or translated into any language or computer
 *	language, in any form or by any means, electronic, mechanical,
 *	magnetic, optical, chemical, manual or otherwise, without the prior
 *	written permission of:
 *
 *	Micro Focus International Ltd,
 *	The Lawn, Old Bath Road, Newbury, Berkshire, RG14 1QN, UK.
 *	(01635) 32646
 *
 *	RESTRICTED RIGHTS LEGEND
 *	Use, duplication, or disclosure by the Government is subject to
 *	restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
 *	in Technical Data and Computer Software clause at DFARS 52.227-7013
 *	or subparagraphs (c)(1) and (2) of Commercial Computer Software -
 *	Restricted Rights at 48 CFR 52.227-19, as applicable.  Contact
 *	Micro Focus International Ltd, 701 East Middlefield Road,
 *	Mountain View, California 94043, USA.
 *
 *	%Y%
 *
 *	Source Module %M%	Sccs Identification %I%
 *
 *	Last Modified on %E% at %U%
 *
 *      sccsid %W%
 *
 ****************************************************************************/

package com.mypackage.JMapServ;

import javax.servlet.http.*;
import java.io.*;
import java.net.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */
public class SessionMonitor implements HttpSessionBindingListener
{
  final static String   cobsessName = "CobolClientRequest";
  private JMapServ clientRequest;

  /**
   * Constructor declaration
   *
   * @param clientRequest
   *
   */
  public SessionMonitor(JMapServ clientRequest)
  {
    this.clientRequest = clientRequest;
  }

  /**
   * Method declaration
   *
   * @param event
   *
   */
  public void valueBound(HttpSessionBindingEvent event) {}

  /**
   * Method declaration
   *
   * @param event
   *
   */
  public void valueUnbound(HttpSessionBindingEvent event)
  {
    if (event.getName().equals(cobsessName))
    {
      try
      {
	this.clientRequest.remove();
      }
      catch (Exception e)
      {
	System.err.println("WARNING: failed to disconnect ClientRequest");
	e.printStackTrace(System.err);
      }
    }
  }

  /**
   * Method declaration
   *
   * @param session
   * @param clientRequest
   *
   */
  static public void setClientRequest(HttpSession session, JMapServ clientRequest)
  {
    session.setAttribute(cobsessName, new SessionMonitor(clientRequest));
  }

  /**
   * Method declaration
   *
   * @param session
   *
   * @return
   */
  static public JMapServ getClientRequest(HttpSession session)
  {
    SessionMonitor ourSess = (SessionMonitor)session.getAttribute(cobsessName);
    if (ourSess != null)
	    return ourSess.clientRequest;
    return null;
  }

  /**
   * Method declaration
   *
   * @return
   *
   */
  public JMapServ getClientRequest()
  {
    return this.clientRequest;
  }

}

/** End of source module %M% **/
