View Javadoc

1   
2   
3   /*
4    * The contents of this file are subject to the terms
5    * of the Common Development and Distribution License
6    * (the "License").  You may not use this file except
7    * in compliance with the License.
8    *
9    * You can obtain a copy of the license at
10   * glassfish/bootstrap/legal/CDDLv1.0.txt or
11   * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12   * See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * When distributing Covered Code, include this CDDL
16   * HEADER in each file and include the License file at
17   * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable,
18   * add the following below this CDDL HEADER, with the
19   * fields enclosed by brackets "[]" replaced with your
20   * own identifying information: Portions Copyright [yyyy]
21   * [name of copyright owner]
22   *
23   * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24   *
25   * Portions Copyright Apache Software Foundation.
26   */ 
27  
28  
29  package javax.servlet.http;
30  
31  
32  
33  /**
34   *
35   * Events of this type are either sent to an object that implements
36   * {@link HttpSessionBindingListener} when it is bound or 
37   * unbound from a session, or to a {@link HttpSessionAttributeListener} 
38   * that has been configured in the deployment descriptor when any attribute is
39   * bound, unbound or replaced in a session.
40   *
41   * <p>The session binds the object by a call to
42   * <code>HttpSession.setAttribute</code> and unbinds the object
43   * by a call to <code>HttpSession.removeAttribute</code>.
44   *
45   *
46   *
47   * @author		Various
48   * 
49   * @see 		HttpSession
50   * @see 		HttpSessionBindingListener
51   * @see			HttpSessionAttributeListener
52   */
53  
54  public class HttpSessionBindingEvent extends HttpSessionEvent {
55  
56  
57  
58  
59      /* The name to which the object is being bound or unbound */
60  
61      private String name;
62      
63      /* The object is being bound or unbound */
64  
65      private Object value;
66      
67    
68  
69      /**
70       *
71       * Constructs an event that notifies an object that it
72       * has been bound to or unbound from a session. 
73       * To receive the event, the object must implement
74       * {@link HttpSessionBindingListener}.
75       *
76       *
77       *
78       * @param session 	the session to which the object is bound or unbound
79       *
80       * @param name 	the name with which the object is bound or unbound
81       *
82       * @see			#getName
83       * @see			#getSession
84       *
85       */
86  
87      public HttpSessionBindingEvent(HttpSession session, String name) {
88  	super(session);
89  	this.name = name;
90      }
91      
92      /**
93       *
94       * Constructs an event that notifies an object that it
95       * has been bound to or unbound from a session. 
96       * To receive the event, the object must implement
97       * {@link HttpSessionBindingListener}.
98       *
99       *
100      *
101      * @param session 	the session to which the object is bound or unbound
102      *
103      * @param name 	the name with which the object is bound or unbound
104      *
105      * @see			#getName
106      * @see			#getSession
107      *
108      */
109     
110     public HttpSessionBindingEvent(HttpSession session, String name, Object value) {
111 	super(session);
112 	this.name = name;
113 	this.value = value;
114     }
115     
116     
117    	/** Return the session that changed. */
118     public HttpSession getSession () { 
119 	return super.getSession();
120     }
121  
122    
123   
124     
125     /**
126      *
127      * Returns the name with which the attribute is bound to or
128      * unbound from the session.
129      *
130      *
131      * @return		a string specifying the name with which
132      *			the object is bound to or unbound from
133      *			the session
134      *
135      *
136      */
137 
138     public String getName() {
139 	return name;
140     }
141     
142     /**
143 	* Returns the value of the attribute that has been added, removed or replaced.
144 	* If the attribute was added (or bound), this is the value of the attribute. If the attribute was
145 	* removed (or unbound), this is the value of the removed attribute. If the attribute was replaced, this
146 	* is the old value of the attribute.
147 	*
148         * @since 2.3
149 	*/
150 	
151 	public Object getValue() {
152 	    return this.value;   
153 	}
154     
155 }
156 
157 
158 
159 
160 
161 
162