View Javadoc

1   /*
2   * Copyright 2004 The Apache Software Foundation
3   *
4   * Licensed under the Apache License, Version 2.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.apache.org/licenses/LICENSE-2.0
9   *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16  
17  package javax.servlet.http;
18  
19  
20  
21  /**
22   *
23   * Events of this type are either sent to an object that implements
24   * {@link HttpSessionBindingListener} when it is bound or 
25   * unbound from a session, or to a {@link HttpSessionAttributeListener} 
26   * that has been configured in the deployment descriptor when any attribute is
27   * bound, unbound or replaced in a session.
28   *
29   * <p>The session binds the object by a call to
30   * <code>HttpSession.setAttribute</code> and unbinds the object
31   * by a call to <code>HttpSession.removeAttribute</code>.
32   *
33   *
34   *
35   * @author		Various
36   * @version		$Version$
37   * 
38   * @see 		HttpSession
39   * @see 		HttpSessionBindingListener
40   * @see			HttpSessionAttributeListener
41   */
42  
43  public class HttpSessionBindingEvent extends HttpSessionEvent {
44  
45  
46  
47  
48      /* The name to which the object is being bound or unbound */
49  
50      private String name;
51      
52      /* The object is being bound or unbound */
53  
54      private Object value;
55      
56    
57  
58      /**
59       *
60       * Constructs an event that notifies an object that it
61       * has been bound to or unbound from a session. 
62       * To receive the event, the object must implement
63       * {@link HttpSessionBindingListener}.
64       *
65       *
66       *
67       * @param session 	the session to which the object is bound or unbound
68       *
69       * @param name 	the name with which the object is bound or unbound
70       *
71       * @see			#getName
72       * @see			#getSession
73       *
74       */
75  
76      public HttpSessionBindingEvent(HttpSession session, String name) {
77  	super(session);
78  	this.name = name;
79      }
80      
81      /**
82       *
83       * Constructs an event that notifies an object that it
84       * has been bound to or unbound from a session. 
85       * To receive the event, the object must implement
86       * {@link HttpSessionBindingListener}.
87       *
88       *
89       *
90       * @param session 	the session to which the object is bound or unbound
91       *
92       * @param name 	the name with which the object is bound or unbound
93       *
94       * @see			#getName
95       * @see			#getSession
96       *
97       */
98      
99      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