org.ejen.ext
Class Counter

java.lang.Object
  |
  +--org.ejen.ext.Counter

public class Counter
extends Object

Counter utility (instanciable).

Usage (XSL stylesheet)

  <?xml version="1.0" encoding="iso-8859-1"?>

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  ...
                  xmlns:cnt="org.ejen.ext.Counter"
                  extension-element-prefixes="cnt ..."
                  exclude-result-prefixes="cnt ..."
                  version="1.0">

    <xsl:output method="xml" encoding="iso-8859-1"/>

    <xsl:template match="ejen">

      <xsl:variable name="cnt1" select="cnt:new()"/>
      <xsl:variable name="cnt2" select="cnt:new(-5)"/>
      <xsl:variable name="cnt3" select="cnt:new([$cnt2])"/>
      <cnt:reset [value="0"] [instance="$cnt2"]/>
      <cnt:incr [step="-2"] [instance="$cnt2"]/>
      <cnt:read [instance="$cnt2"]/>
      <xsl:param name="i" select="cnt:read([$cnt2])"/>
      <cnt:incrAndRead [step="-2"] [instance="$cnt2"]/>
      <xsl:param name="i" select="cnt:incrAndRead([$cnt2])"/>
      <xsl:param name="i" select="cnt:incrAndRead([$cnt2,] -2)"/>
      <cnt:readAndIncr [step="-2"] [instance="$cnt2"]/>
      <xsl:param name="i" select="cnt:readAndIncr([$cnt2])"/>
      <xsl:param name="i" select="cnt:readAndIncr([$cnt2,] -2)"/>

    </xsl:template>

  </xsl:stylesheet>
 

Version:
1.0
Author:
F. Wolff

Constructor Summary
Counter()
          Constructs a new Counter object with initial value set to 1.
Counter(Counter cnt)
          Constructs a new Counter object whose initial value is the current value of the cnt parameter.
Counter(int value)
          Constructs a new Counter object whose initial value is the value parameter.
 
Method Summary
 void incr(XSLProcessorContext context, ElemExtensionCall elem)
          Increments the value of this Counter by 'step'.
 int incrAndRead(ExpressionContext context)
          Increments the value of this Counter by 1, then returns it.
 int incrAndRead(ExpressionContext context, int step)
          Increments the value of this Counter by 'step', then returns it.
 int incrAndRead(XSLProcessorContext context, ElemExtensionCall elem)
          Increments the value of this Counter, then returns it.
 int read(ExpressionContext context)
          Returns the current value of this Counter.
 int read(XSLProcessorContext context, ElemExtensionCall elem)
          Returns the current value of this Counter.
 int readAndIncr(ExpressionContext context)
          Returns the value of this Counter, then increments it by 1.
 int readAndIncr(ExpressionContext context, int step)
          Returns the value of this Counter, then increments it by 'step'.
 int readAndIncr(XSLProcessorContext context, ElemExtensionCall elem)
          Returns the value of this Counter, then increments it.
 void reset(XSLProcessorContext context, ElemExtensionCall elem)
          Resets the Counter value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Counter

public Counter()
Constructs a new Counter object with initial value set to 1. If this constructor is not explicitly used, the Xalan extension mechanism constructs a default instance.


  <xsl:variable name="cnt1" select="cnt:new()"/>
 


Counter

public Counter(int value)
Constructs a new Counter object whose initial value is the value parameter.


  <xsl:variable name="cnt2" select="cnt:new(0)"/>
 

XSLT parameters:
[Mandatory] initial value of this Counter.

Parameters:
value - initial value of this Counter.

Counter

public Counter(Counter cnt)
Constructs a new Counter object whose initial value is the current value of the cnt parameter.


  <xsl:variable name="cnt3" select="cnt:new($cnt1)"/>
 

XSLT parameters:
[Mandatory] Counter instance.

Parameters:
cnt - a Counter object.
Method Detail

reset

public void reset(XSLProcessorContext context,
                  ElemExtensionCall elem)
Resets the Counter value.


  <cnt:reset [value="0"] [instance="$cnt2"]/>
 

XSLT Attributes:
instance [Optional] Counter instance (if not set, default instance is used).
value [Optional/AVT] new Counter value (if not set, the counter will be reset to DEFAULT_INITIAL_VALUE).

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Throws:
WrappedRuntimeException - with a XSL Exception or a java.lang.NumberFormatException.

incr

public void incr(XSLProcessorContext context,
                 ElemExtensionCall elem)
Increments the value of this Counter by 'step'.


  <cnt:incr [step="-2"] [instance="$cnt2"]/>
 

XSLT Attributes:
instance [Optional] Counter instance (if not set, default instance is used).
step [Optional/AVT] step used for incrementation (if not set, the counter will be incremented by 1).

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Throws:
WrappedRuntimeException - with a XSL Exception or a java.lang.NumberFormatException.

read

public int read(XSLProcessorContext context,
                ElemExtensionCall elem)
Returns the current value of this Counter.


  <cnt:read [instance="$cnt2"]/>
 

XSLT Attributes:
instance [Optional] Counter instance (if not set, default instance is used).

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter.

read

public int read(ExpressionContext context)
Returns the current value of this Counter.


  <xsl:param name="i" select="cnt:read([$cnt2])"/>
 

XSLT parameters:
[Optional] Counter instance (if not set, default instance is used).

Parameters:
context - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter.

incrAndRead

public int incrAndRead(XSLProcessorContext context,
                       ElemExtensionCall elem)
Increments the value of this Counter, then returns it.


  <cnt:incrAndRead [step="-2"] [instance="$cnt2"]/>
 

XSLT Attributes:
instance [Optional] Counter instance (if not set, default instance is used).
step [Optional/AVT] step used for incrementation (if not set, the counter will be incremented by 1).

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter (after incrementation).
Throws:
WrappedRuntimeException - with a XSL Exception or a java.lang.NumberFormatException.

incrAndRead

public int incrAndRead(ExpressionContext context)
Increments the value of this Counter by 1, then returns it.


  <xsl:param name="i" select="cnt:incrAndRead([$cnt2])"/>
 

XSLT parameters:
[Optional] Counter instance (if not set, default instance is used).

Parameters:
context - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter (after incrementation).

incrAndRead

public int incrAndRead(ExpressionContext context,
                       int step)
Increments the value of this Counter by 'step', then returns it.


  <xsl:param name="i" select="cnt:incrAndRead([$cnt2,] -2)"/>
 

XSLT parameters:
[Optional] Counter instance (if not set, default instance is used).
[Mandatory] step used for incrementation (if not set, the counter will be incremented by 1).

Parameters:
context - automatically passed by the xalan extension mechanism.
step - incrementation step.
Returns:
the current value of this Counter (after incrementation).

readAndIncr

public int readAndIncr(XSLProcessorContext context,
                       ElemExtensionCall elem)
Returns the value of this Counter, then increments it.


  <cnt:readAndIncr [step="-2"] [instance="$cnt2"]/>
 

XSLT Attributes:
instance [Optional] Counter instance (if not set, default instance is used).
step [Optional/AVT] step used for incrementation (if not set, the counter will be incremented by 1).

Parameters:
context - automatically passed by the xalan extension mechanism.
elem - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter (before incrementation).
Throws:
WrappedRuntimeException - with a XSL Exception or a java.lang.NumberFormatException.

readAndIncr

public int readAndIncr(ExpressionContext context)
Returns the value of this Counter, then increments it by 1.


  <xsl:param name="i" select="cnt:readAndIncr([$cnt2])"/>
 

XSLT parameters:
[Optional] Counter instance (if not set, default instance is used).

Parameters:
context - automatically passed by the xalan extension mechanism.
Returns:
the current value of this Counter (before incrementation).

readAndIncr

public int readAndIncr(ExpressionContext context,
                       int step)
Returns the value of this Counter, then increments it by 'step'.


  <xsl:param name="i" select="cnt:readAndIncr([$cnt2,] -2)"/>
 

XSLT parameters:
[Optional] Counter instance (if not set, default instance is used).
[Mandatory] step used for incrementation (if not set, the counter will be incremented by 1).

Parameters:
context - automatically passed by the xalan extension mechanism.
step - incrementation step.
Returns:
the current value of this Counter (before incrementation).