1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package javax.servlet.http;
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 public class HttpSessionBindingEvent extends HttpSessionEvent {
43 /* The name to which the object is being bound or unbound */
44
45 private String name;
46
47 /* The object is being bound or unbound */
48
49 private Object value;
50
51
52
53 /**
54 *
55 * Constructs an event that notifies an object that it
56 * has been bound to or unbound from a session.
57 * To receive the event, the object must implement
58 * {@link HttpSessionBindingListener}.
59 *
60 *
61 *
62 * @param session the session to which the object is bound or unbound
63 *
64 * @param name the name with which the object is bound or unbound
65 *
66 * @see #getName
67 * @see #getSession
68 *
69 */
70
71 public HttpSessionBindingEvent(HttpSession session, String name) {
72 super(session);
73 this.name = name;
74 }
75
76 /**
77 *
78 * Constructs an event that notifies an object that it
79 * has been bound to or unbound from a session.
80 * To receive the event, the object must implement
81 * {@link HttpSessionBindingListener}.
82 *
83 *
84 *
85 * @param session the session to which the object is bound or unbound
86 *
87 * @param name the name with which the object is bound or unbound
88 *
89 * @see #getName
90 * @see #getSession
91 *
92 */
93
94 public HttpSessionBindingEvent(HttpSession session, String name, Object value) {
95 super(session);
96 this.name = name;
97 this.value = value;
98 }
99
100
101 /** Return the session that changed. */
102 public HttpSession getSession () {
103 return super.getSession();
104 }
105
106
107
108
109 /**
110 *
111 * Returns the name with which the attribute is bound to or
112 * unbound from the session.
113 *
114 *
115 * @return a string specifying the name with which
116 * the object is bound to or unbound from
117 * the session
118 *
119 *
120 */
121
122 public String getName() {
123 return name;
124 }
125
126 /**
127 * Returns the value of the attribute that has been added, removed or replaced.
128 * If the attribute was added (or bound), this is the value of the attribute. If the attribute was
129 * removed (or unbound), this is the value of the removed attribute. If the attribute was replaced, this
130 * is the old value of the attribute.
131 *
132 * @since 2.3
133 */
134
135 public Object getValue() {
136 return this.value;
137 }
138
139 }
140
141
142
143
144
145
146