001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 // 021 // This source code implements specifications defined by the Java 022 // Community Process. In order to remain compliant with the specification 023 // DO NOT add / change / or delete method signatures! 024 // 025 026 package javax.servlet.http; 027 028 /** 029 * Events of this type are either sent to an object that implements 030 * {@link HttpSessionBindingListener} when it is bound or 031 * unbound from a session, or to a {@link HttpSessionAttributeListener} 032 * that has been configured in the deployment descriptor when any attribute is 033 * bound, unbound or replaced in a session. 034 * 035 * <p>The session binds the object by a call to 036 * <code>HttpSession.setAttribute</code> and unbinds the object 037 * by a call to <code>HttpSession.removeAttribute</code>. 038 * 039 * @see HttpSession 040 * @see HttpSessionBindingListener 041 * @see HttpSessionAttributeListener 042 * 043 * @version $Rev: 467553 $ $Date: 2006-10-25 06:01:51 +0200 (Mi, 25. Okt 2006) $ 044 */ 045 public class HttpSessionBindingEvent extends HttpSessionEvent { 046 /** 047 * The name to which the object is being bound or unbound 048 */ 049 private String name; 050 051 /** 052 * The object is being bound or unbound 053 */ 054 private Object value; 055 056 /** 057 * Constructs an event that notifies an object that it 058 * has been bound to or unbound from a session. 059 * To receive the event, the object must implement 060 * {@link HttpSessionBindingListener}. 061 * 062 * @param session the session to which the object is bound or unbound 063 * 064 * @param name the name with which the object is bound or unbound 065 * 066 * @see #getName 067 * @see #getSession 068 */ 069 public HttpSessionBindingEvent(HttpSession session, String name) { 070 super(session); 071 this.name = name; 072 } 073 074 /** 075 * Constructs an event that notifies an object that it 076 * has been bound to or unbound from a session. 077 * To receive the event, the object must implement 078 * {@link HttpSessionBindingListener}. 079 * 080 * @param session the session to which the object is bound or unbound 081 * 082 * @param name the name with which the object is bound or unbound 083 * 084 * @see #getName 085 * @see #getSession 086 */ 087 public HttpSessionBindingEvent(HttpSession session, String name, Object value) { 088 super(session); 089 this.name = name; 090 this.value = value; 091 } 092 093 /** 094 * Return the session that changed. 095 */ 096 public HttpSession getSession() { 097 return super.getSession(); 098 } 099 100 /** 101 * Returns the name with which the attribute is bound to or unbound from 102 * the session. 103 * 104 * @return a string specifying the name with which the object is bound to 105 * or unbound from the session 106 */ 107 public String getName() { 108 return name; 109 } 110 111 /** 112 * Returns the value of the attribute that has been added, removed or 113 * replaced. If the attribute was added (or bound), this is the value of 114 * the attribute. If the attrubute was removed (or unbound), this is the 115 * value of the removed attribute. If the attribute was replaced, this 116 * is the old value of the attribute. 117 * 118 * @since Servlet 2.3 119 */ 120 public Object getValue() { 121 return this.value; 122 } 123 } 124 125 126 127 128 129 130