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    package javax.servlet.http;
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    public class HttpSessionBindingEvent extends HttpSessionEvent {
043        /* The name to which the object is being bound or unbound */
044    
045        private String name;
046        
047        /* The object is being bound or unbound */
048    
049        private Object value;
050        
051      
052    
053        /**
054         *
055         * Constructs an event that notifies an object that it
056         * has been bound to or unbound from a session. 
057         * To receive the event, the object must implement
058         * {@link HttpSessionBindingListener}.
059         *
060         *
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         */
070    
071        public HttpSessionBindingEvent(HttpSession session, String name) {
072            super(session);
073            this.name = name;
074        }
075        
076        /**
077         *
078         * Constructs an event that notifies an object that it
079         * has been bound to or unbound from a session. 
080         * To receive the event, the object must implement
081         * {@link HttpSessionBindingListener}.
082         *
083         *
084         *
085         * @param session   the session to which the object is bound or unbound
086         *
087         * @param name      the name with which the object is bound or unbound
088         *
089         * @see                     #getName
090         * @see                     #getSession
091         *
092         */
093        
094        public HttpSessionBindingEvent(HttpSession session, String name, Object value) {
095            super(session);
096            this.name = name;
097            this.value = value;
098        }
099        
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