org.objectweb.jac.wrappers
Class LimiterWrapper

java.lang.Object
  |
  +--org.objectweb.jac.core.Wrapper
        |
        +--org.objectweb.jac.wrappers.LimiterWrapper
All Implemented Interfaces:
Advice, ConstructorInterceptor, Interceptor, MethodInterceptor, Serializable

public class LimiterWrapper
extends Wrapper

LimiterWrapper implements a wrapper that tests a counter value before calling the wrappee object. If the counter is not with the max and min limits, it raises the LimiterException

Use this wrapper as follows:

Where a_stack is an instance of a class Stack. When wrapping the stack, it will raise a LimiterException if a push is done and that the counter is greater or equal to 100 or if a pop is done and that the counter is lower or equal to 0.

NOTE: this class cannot be used alone. Its instances must wrap some instances of other objects (possibly other wrappers).

See Also:
Wrappee, Wrapping.wrap(Wrappee,Wrapper,AbstractMethodItem), LimiterException, Serialized Form

Field Summary
protected  int counter
          Store the counter of the limiter.
protected  int max
          Store the maximum bound of the limiter.
protected  int min
          Store the minimum bound of the limiter.
 
Fields inherited from class org.objectweb.jac.core.Wrapper
ac, cr
 
Constructor Summary
LimiterWrapper(AspectComponent ac, int min, int max)
          Construct a new limiter and initialize the bounds.
 
Method Summary
 Object construct(ConstructorInvocation invocation)
           
 Object dec(Interaction interaction)
          This wrapping method decrements the limiter counter and calls the wrappee method.
 int getCounter()
          Return the current counter of the limiter.
 int getMax()
          Return the max bound of the limiter.
 Object inc(Interaction interaction)
          This wrapping method increments the limiter counter and calls the wrappee method.
 Object invoke(MethodInvocation invocation)
           
 void setMax(int max)
          Set the max bound of the limiter.
 Object testMax(Interaction interaction)
          This wrapping method tests the counter of the limiter and raises the LimiterExeption when when it is over the maximum value.
 Object testMin(Interaction interaction)
          This wrapping method tests the counter of the limiter and raises the LimiterExeption when when it is below the minimum value.
 
Methods inherited from class org.objectweb.jac.core.Wrapper
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

max

protected int max
Store the maximum bound of the limiter.


min

protected int min
Store the minimum bound of the limiter.


counter

protected int counter
Store the counter of the limiter.

Constructor Detail

LimiterWrapper

public LimiterWrapper(AspectComponent ac,
                      int min,
                      int max)
Construct a new limiter and initialize the bounds.

Parameters:
min - the minimum counter value.
max - the maximum counter value.
Method Detail

getMax

public int getMax()
Return the max bound of the limiter.

Returns:
the max bound

setMax

public void setMax(int max)
Set the max bound of the limiter.

Parameters:
max - the new max bound

getCounter

public int getCounter()
Return the current counter of the limiter.

Returns:
the counter

inc

public Object inc(Interaction interaction)
This wrapping method increments the limiter counter and calls the wrappee method.

For instance, inc could wrap the push method of a stack so that the counter is incremented when a new element is placed on the top of the stack.

NOTE: this method do not test the bounds. Use testMax to do this.

Returns:
the original method return value
See Also:
testMax(Interaction)

dec

public Object dec(Interaction interaction)
This wrapping method decrements the limiter counter and calls the wrappee method.

For instance, dec could wrap the pop method of a stack so that the counter is incremented when an element is removed from it.

NOTE: this method do not test the bounds. Use testMin to do this.

Returns:
the original method return value
See Also:
testMin(Interaction)

testMax

public Object testMax(Interaction interaction)
               throws LimiterException
This wrapping method tests the counter of the limiter and raises the LimiterExeption when when it is over the maximum value.

NOTE: this method must be used with the inc and dec wrapping methods that mofify the counter value.

Returns:
the original method return value or raise an exception
LimiterException
See Also:
inc(Interaction), dec(Interaction)

testMin

public Object testMin(Interaction interaction)
               throws LimiterException
This wrapping method tests the counter of the limiter and raises the LimiterExeption when when it is below the minimum value.

NOTE: this method must be used with the inc and dec wrapping methods that mofify the counter value.

Returns:
the original method return value or raise an exception
LimiterException
See Also:
inc(Interaction), dec(Interaction)

invoke

public Object invoke(MethodInvocation invocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Overrides:
invoke in class Wrapper
Throwable

construct

public Object construct(ConstructorInvocation invocation)
                 throws Throwable
Specified by:
construct in interface ConstructorInterceptor
Overrides:
construct in class Wrapper
Throwable