001 /* 002 * Copyright 2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package javax.servlet.http; 018 019 020 021 /** 022 * 023 * Events of this type are either sent to an object that implements 024 * {@link HttpSessionBindingListener} when it is bound or 025 * unbound from a session, or to a {@link HttpSessionAttributeListener} 026 * that has been configured in the deployment descriptor when any attribute is 027 * bound, unbound or replaced in a session. 028 * 029 * <p>The session binds the object by a call to 030 * <code>HttpSession.setAttribute</code> and unbinds the object 031 * by a call to <code>HttpSession.removeAttribute</code>. 032 * 033 * 034 * 035 * @author Various 036 * @version $Version$ 037 * 038 * @see HttpSession 039 * @see HttpSessionBindingListener 040 * @see HttpSessionAttributeListener 041 */ 042 043 public class HttpSessionBindingEvent extends HttpSessionEvent { 044 045 046 047 048 /* The name to which the object is being bound or unbound */ 049 050 private String name; 051 052 /* The object is being bound or unbound */ 053 054 private Object value; 055 056 057 058 /** 059 * 060 * Constructs an event that notifies an object that it 061 * has been bound to or unbound from a session. 062 * To receive the event, the object must implement 063 * {@link HttpSessionBindingListener}. 064 * 065 * 066 * 067 * @param session the session to which the object is bound or unbound 068 * 069 * @param name the name with which the object is bound or unbound 070 * 071 * @see #getName 072 * @see #getSession 073 * 074 */ 075 076 public HttpSessionBindingEvent(HttpSession session, String name) { 077 super(session); 078 this.name = name; 079 } 080 081 /** 082 * 083 * Constructs an event that notifies an object that it 084 * has been bound to or unbound from a session. 085 * To receive the event, the object must implement 086 * {@link HttpSessionBindingListener}. 087 * 088 * 089 * 090 * @param session the session to which the object is bound or unbound 091 * 092 * @param name the name with which the object is bound or unbound 093 * 094 * @see #getName 095 * @see #getSession 096 * 097 */ 098 099 public HttpSessionBindingEvent(HttpSession session, String name, Object value) { 100 super(session); 101 this.name = name; 102 this.value = value; 103 } 104 105 106 /** Return the session that changed. */ 107 public HttpSession getSession () { 108 return super.getSession(); 109 } 110 111 112 113 114 /** 115 * 116 * Returns the name with which the attribute is bound to or 117 * unbound from the session. 118 * 119 * 120 * @return a string specifying the name with which 121 * the object is bound to or unbound from 122 * the session 123 * 124 * 125 */ 126 127 public String getName() { 128 return name; 129 } 130 131 /** 132 * Returns the value of the attribute that has been added, removed or replaced. 133 * If the attribute was added (or bound), this is the value of the attribute. If the attribute was 134 * removed (or unbound), this is the value of the removed attribute. If the attribute was replaced, this 135 * is the old value of the attribute. 136 * 137 * @since 2.3 138 */ 139 140 public Object getValue() { 141 return this.value; 142 } 143 144 } 145 146 147 148 149 150 151