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 372 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"


*/
public void attributeReplaced(HttpSessionBindingEvent event) {
checkForSpecials(event, -1);
}
/** Check whether the attribute that was just added or removed
* matches one of the stored order-attribute-names AND
* the value of the attribute matches one of the
* stored daily-special-item-names. If so, add the delta
* (+1 or -1) to the count of daily specials ordered.
*/
private void checkForSpecials(HttpSessionBindingEvent event,
int delta) {
ServletContext context =
event.getSession().getServletContext();
ArrayList attributeNames =
getList(context, "order-attribute-names");
Listing 6.38 DailySpecialWatcher.java (continued)
Chapter 6 ?–  The Application Events Framework 330
ArrayList itemNames =
getList(context, "daily-special-item-names");
synchronized(attributeNames) {
for(int i=0; iString attributeName = attributeNames.get(i);
for(int j=0; jString itemName = itemNames.get(j);
if (attributeName.equals(event.getName()) &&
itemName.equals((String)event.getValue())) {
dailySpecialCount = dailySpecialCount + delta;
}
}
}
}
context.setAttribute("dailySpecialCount",
new Integer(dailySpecialCount));
}
/** Get either the order-attribute-names or
* daily-special-item-names list.
*/
private ArrayList getList(ServletContext context,
String attributeName) {
ArrayList list =
(ArrayList)context.


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