SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 371 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

38 DailySpecialWatcher.java
package coreservlets.listeners;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Listener that keeps track of orders of the
* current daily special.
*/
public class DailySpecialWatcher
implements HttpSessionAttributeListener {
private static int dailySpecialCount = 0;
Listing 6.37 DailySpecialRegistrar.java (continued)
6.15 Using Multiple Cooperating Listeners 329
/** If the name of the session attribute that was added
* matches one of the stored order-attribute-names AND
* the value of the attribute matches one of the
* stored daily-special-item-names, then increment
* the count of daily specials ordered.
*/
public void attributeAdded(HttpSessionBindingEvent event) {
checkForSpecials(event, 1);
}
/** If the name of the session attribute that was removed
* matches one of the stored order-attribute-names AND
* the value of the attribute matches one of the
* stored daily-special-item-names, then decrement
* the count of daily specials ordered.
*/
public void attributeRemoved(HttpSessionBindingEvent event) {
checkForSpecials(event, -1);
}
/** If the name of the session attribute that was replaced
* matches one of the stored order-attribute-names AND
* the value of the attribute matches one of the
* stored daily-special-item-names, then increment
* the count of daily specials ordered. Note that the
* value here is the old value (the one being replaced);
* the attributeAdded method will handle the new value
* (the replacement).


Pages:
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383