com.ora.jsp.beans.counter
Class CounterBean

java.lang.Object
  |
  +--com.ora.jsp.beans.counter.CounterBean
All Implemented Interfaces:
java.io.Serializable

public class CounterBean
extends java.lang.Object
implements java.io.Serializable

This class maintains page counters. Note that this class is intended to be used in session and application scope so regular setter and getter methods for pageContext and isPermanent can not be used; all info needed to get and increment the counter value must be provided as parameters to the corresponding method to avoid multi-threading issues.

Version:
1.0
Author:
Hans Bergsten, Gefion software
See Also:
Serialized Form

Field Summary
private  java.util.Hashtable counters
           
 
Constructor Summary
CounterBean()
           
 
Method Summary
 int getCurrentValue(javax.servlet.jsp.PageContext pageContext)
          Returns the current value of the counter for this page.
 int getNextValue(javax.servlet.jsp.PageContext pageContext)
          Increments the counter for this page and returns the new value.
 int getNextValue(javax.servlet.jsp.PageContext pageContext, boolean permanent)
          Increments the counter for this page and returns the new value.
 void incrementValue(javax.servlet.jsp.PageContext pageContext, boolean permanent)
          Increments the counter for this page.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

counters

private java.util.Hashtable counters
Constructor Detail

CounterBean

public CounterBean()
Method Detail

getCurrentValue

public int getCurrentValue(javax.servlet.jsp.PageContext pageContext)
                    throws java.lang.Exception
Returns the current value of the counter for this page.
Parameters:
pageContext - the PageContext for the page
Returns:
the current counter value, or -1 if it's not found
Throws:
throws - Exception if the pageContext is null

getNextValue

public int getNextValue(javax.servlet.jsp.PageContext pageContext)
                 throws java.lang.Exception
Increments the counter for this page and returns the new value.
Parameters:
pageContext - the PageContext for the page
Returns:
the current counter value incremented by one
Throws:
throws - Exception if the pageContext is null

getNextValue

public int getNextValue(javax.servlet.jsp.PageContext pageContext,
                        boolean permanent)
                 throws java.lang.Exception
Increments the counter for this page and returns the new value. If permanent is true the new value is also saved to a file.
Parameters:
pageContext - the PageContext for the page
permanent - set to true if the new value should be saved to a file
Returns:
the current counter value incremented by one
Throws:
throws - Exception if the pageContext is null

incrementValue

public void incrementValue(javax.servlet.jsp.PageContext pageContext,
                           boolean permanent)
                    throws java.lang.Exception
Increments the counter for this page. If the permanent is true, the new value is also saved in a file.
Parameters:
pageContext - the PageContext for the page
permanent - set to true if the new value should be saved to a file
Throws:
throws - Exception if the pageContext is null