org.apache.asn1.ber.digester
Class BERDigester

java.lang.Object
  extended by org.apache.asn1.codec.stateful.AbstractStatefulDecoder
      extended by org.apache.asn1.ber.digester.BERDigester
All Implemented Interfaces:
org.apache.asn1.codec.stateful.StatefulDecoder

public class BERDigester
extends org.apache.asn1.codec.stateful.AbstractStatefulDecoder

A special BER TLV event rulesBase. This class was inspired by the XML rulesBase in Jakarta Commons.

Version:
$Rev: 157644 $
Author:
Apache Directory Project

Nested Class Summary
(package private)  class BERDigester.DigesterCallback
           
 
Field Summary
private  org.apache.commons.collections.primitives.BooleanStack booleanStack
          the primitive boolean stack where rules push and pop booleans
private  org.apache.commons.collections.primitives.ByteStack byteStack
          the primitive byte stack where rules push and pop bytes
private  org.apache.commons.collections.primitives.CharStack charStack
          the primitive char stack where rules push and pop chars
private  java.lang.ClassLoader classLoader
          The class loader to use for instantiating application objects.
private  BERDecoder decoder
          the underlying decoder used by this rulesBase
private  org.apache.commons.collections.primitives.DoubleStack doubleStack
          the primitive double stack where rules push and pop doubles
private  org.apache.commons.collections.primitives.FloatStack floatStack
          the primitive float stack where rules push and pop floats
private  org.apache.commons.collections.primitives.IntStack intStack
          the primitive int stack where rules push and pop ints
private  org.apache.commons.collections.primitives.LongStack longStack
          the primitive long stack where rules push and pop longs
private  java.util.List matched
          the currently matched rules
private  BERDigesterMonitor monitor
          The monitor used by this digester
static int NO_TOP_TAG
          For now this corresponds to a tag of class Universal with an id of 15.
private  org.apache.commons.collections.ArrayStack objectStack
          the object stack where rules push and pop ASN.1 POJO stubs
private  java.lang.Object root
          The "root" element of the stack (in other words, the last object that was popped.
private  Rules rules
          the rules base used by this digester
private  org.apache.commons.collections.primitives.ShortStack shortStack
          the primitive short stack where rules push and shorts
private  org.apache.commons.collections.primitives.IntStack tagStack
          the tag stack used to store the nesting pattern
private  boolean useContextClassLoader
          Do we want to use the Context ClassLoader when loading classes for instantiating new objects.
 
Constructor Summary
BERDigester()
          Creates a BER TLV event rulesBase.
 
Method Summary
 void addRule(int[] pattern, Rule rule)
          Register a new Rule matching the specified pattern.
 void clear()
          Clear the current contents of the object stack.
 void decode(java.lang.Object encoded)
           
(package private)  void fireFinishEvent()
           
(package private)  void fireLengthEvent(int length)
           
(package private)  void fireTagEvent(int id, boolean isPrimitive, TypeClass typeClass)
           
(package private)  void fireValueEvent(java.nio.ByteBuffer buf)
           
 int getBooleanCount()
          Return the current depth of the boolean stack.
 int getByteCount()
          Return the current depth of the byte stack.
 int getCharCount()
          Return the current depth of the char stack.
 java.lang.ClassLoader getClassLoader()
          Return the class loader to be used for instantiating application objects when required.
 int getCount()
          Return the current depth of the object stack.
 int getDoubleCount()
          Return the current depth of the double stack.
 int getFloatCount()
          Return the current depth of the float stack.
 int getIntCount()
          Return the current depth of the int stack.
 int getLongCount()
          Return the current depth of the long stack.
 java.lang.Object getRoot()
          This method allows you to access the root object that has been created after decoding.
 Rules getRules()
          Return the Rules implementation object containing our rules collection and associated matching policy.
 int getShortCount()
          Return the current depth of the short stack.
 int getTag(int n)
          Return the n'th tag down the Tag stack, where 0 is the top element and [getCount()-1] is the bottom element.
 int getTagCount()
          Return the current depth of the Tag stack.
 int getTopTag()
          Gets the raw int for the tag of the TLV currently being processed hence the tag on the top of the stack.
 boolean getUseContextClassLoader()
          Return the boolean as to whether the context classloader should be used.
 java.lang.Object peek()
          Return the top object on the stack without removing it.
 java.lang.Object peek(int n)
          Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 boolean peekBoolean()
          Return the top boolean on the stack without removing it.
 boolean peekBoolean(int n)
          Return the n'th boolean down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 byte peekByte()
          Return the top byte on the stack without removing it.
 byte peekByte(int n)
          Return the n'th byte down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 char peekChar()
          Return the top char on the stack without removing it.
 char peekChar(int n)
          Return the n'th char down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 double peekDouble()
          Return the top double on the stack without removing it.
 double peekDouble(int n)
          Return the n'th double down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 float peekFloat()
          Return the top float on the stack without removing it.
 float peekFloat(int n)
          Return the n'th float down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 int peekInt()
          Return the top int on the stack without removing it.
 int peekInt(int n)
          Return the n'th int down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 long peekLong()
          Return the top long on the stack without removing it.
 long peekLong(int n)
          Return the n'th long down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 short peekShort()
          Return the top short on the stack without removing it.
 short peekShort(int n)
          Return the n'th short down the stack, where 0 is the top element and [getCount()-1] is the bottom element.
 java.lang.Object pop()
          Pop the top object off of the stack, and return it.
 boolean popBoolean()
          Pop the top boolean off of the stack, and return it.
 byte popByte()
          Pop the top byte off of the stack, and return it.
 char popChar()
          Pop the top char off of the stack, and return it.
 double popDouble()
          Pop the top double off of the stack, and return it.
 float popFloat()
          Pop the top float off of the stack, and return it.
 int popInt()
          Pop the top int off of the stack, and return it.
 long popLong()
          Pop the top long off of the stack, and return it.
 short popShort()
          Pop the top short off of the stack, and return it.
 void push(java.lang.Object object)
          Push a new object onto the top of the object stack.
 void pushBoolean(boolean bit)
          Push a new boolean onto the top of the boolean stack.
 void pushByte(byte bite)
          Push a new byte onto the top of the byte stack.
 void pushChar(char ch)
          Push a new char onto the top of the char stack.
 void pushDouble(double element)
          Push a new double onto the top of the double stack.
 void pushFloat(float element)
          Push a new float onto the top of the float stack.
 void pushInt(int element)
          Push a new int onto the top of the int stack.
 void pushLong(long element)
          Push a new long onto the top of the long stack.
 void pushShort(short element)
          Push a new short onto the top of the short stack.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the class loader to be used for instantiating application objects when required.
 void setRules(Rules rules)
          Set the Rules implementation object containing our rules collection and associated matching policy.
 void setUseContextClassLoader(boolean use)
          Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes that are defined in various rules.
 
Methods inherited from class org.apache.asn1.codec.stateful.AbstractStatefulDecoder
decodeOccurred, getDecoderMonitor, setCallback, setDecoderMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_TOP_TAG

public static final int NO_TOP_TAG
For now this corresponds to a tag of class Universal with an id of 15. This has been reserved for future use but to my knowledge currently it is not being used for anything specifically. Hence we use it as the return value instead of throwing an empty stack exception when the top of the tag stack is requested.

See Also:
Constant Field Values

decoder

private BERDecoder decoder
the underlying decoder used by this rulesBase


objectStack

private org.apache.commons.collections.ArrayStack objectStack
the object stack where rules push and pop ASN.1 POJO stubs


booleanStack

private org.apache.commons.collections.primitives.BooleanStack booleanStack
the primitive boolean stack where rules push and pop booleans


charStack

private org.apache.commons.collections.primitives.CharStack charStack
the primitive char stack where rules push and pop chars


floatStack

private org.apache.commons.collections.primitives.FloatStack floatStack
the primitive float stack where rules push and pop floats


doubleStack

private org.apache.commons.collections.primitives.DoubleStack doubleStack
the primitive double stack where rules push and pop doubles


intStack

private org.apache.commons.collections.primitives.IntStack intStack
the primitive int stack where rules push and pop ints


byteStack

private org.apache.commons.collections.primitives.ByteStack byteStack
the primitive byte stack where rules push and pop bytes


longStack

private org.apache.commons.collections.primitives.LongStack longStack
the primitive long stack where rules push and pop longs


shortStack

private org.apache.commons.collections.primitives.ShortStack shortStack
the primitive short stack where rules push and shorts


tagStack

private org.apache.commons.collections.primitives.IntStack tagStack
the tag stack used to store the nesting pattern


rules

private Rules rules
the rules base used by this digester


matched

private java.util.List matched
the currently matched rules


classLoader

private java.lang.ClassLoader classLoader
The class loader to use for instantiating application objects. If not specified, the context class loader, or the class loader used to load Digester itself, is used, based on the value of the useContextClassLoader variable.


useContextClassLoader

private boolean useContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects. Default is false.


root

private java.lang.Object root
The "root" element of the stack (in other words, the last object that was popped.


monitor

private BERDigesterMonitor monitor
The monitor used by this digester

Constructor Detail

BERDigester

public BERDigester()
Creates a BER TLV event rulesBase.

Method Detail

decode

public void decode(java.lang.Object encoded)
            throws org.apache.asn1.codec.DecoderException
Throws:
org.apache.asn1.codec.DecoderException

addRule

public void addRule(int[] pattern,
                    Rule rule)
Register a new Rule matching the specified pattern.

Parameters:
pattern - tag nesting pattern
rule - the Rule to add to this BERDigester

getRules

public Rules getRules()
Return the Rules implementation object containing our rules collection and associated matching policy.

Returns:
the entire set of rules

clear

public void clear()
Clear the current contents of the object stack.


getCount

public int getCount()
Return the current depth of the object stack.

Returns:
the size of the object stack

peek

public java.lang.Object peek()
Return the top object on the stack without removing it.

Returns:
the top object
Throws:
java.util.EmptyStackException - if there are no objects on the stack

peek

public java.lang.Object peek(int n)
Return the n'th object down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no objects on the stack
java.lang.IndexOutOfBoundsException - if the index is out of bounds

pop

public java.lang.Object pop()
Pop the top object off of the stack, and return it.

Returns:
the top object off of the stack
Throws:
java.util.EmptyStackException - if there are no objects on the stack

push

public void push(java.lang.Object object)
Push a new object onto the top of the object stack.

Parameters:
object - the object to push onto the stack

getBooleanCount

public int getBooleanCount()
Return the current depth of the boolean stack.

Returns:
the size of the boolean stack

peekBoolean

public boolean peekBoolean()
Return the top boolean on the stack without removing it.

Returns:
the top boolean
Throws:
java.util.EmptyStackException - if there are no more boolean elements left

peekBoolean

public boolean peekBoolean(int n)
Return the n'th boolean down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more boolean elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popBoolean

public boolean popBoolean()
Pop the top boolean off of the stack, and return it.

Returns:
the top boolean off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushBoolean

public void pushBoolean(boolean bit)
Push a new boolean onto the top of the boolean stack.

Parameters:
bit - the boolean to push onto the stack

getCharCount

public int getCharCount()
Return the current depth of the char stack.

Returns:
the size of the char stack

peekChar

public char peekChar()
Return the top char on the stack without removing it.

Returns:
the top char
Throws:
java.util.EmptyStackException - if there are no more char elements left

peekChar

public char peekChar(int n)
Return the n'th char down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more char elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popChar

public char popChar()
Pop the top char off of the stack, and return it.

Returns:
the top char off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushChar

public void pushChar(char ch)
Push a new char onto the top of the char stack.

Parameters:
ch - the char to push onto the stack

getByteCount

public int getByteCount()
Return the current depth of the byte stack.

Returns:
the size of the byte stack

peekByte

public byte peekByte()
Return the top byte on the stack without removing it.

Returns:
the top byte
Throws:
java.util.EmptyStackException - if there are no more byte elements left

peekByte

public byte peekByte(int n)
Return the n'th byte down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more byte elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popByte

public byte popByte()
Pop the top byte off of the stack, and return it.

Returns:
the top byte off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushByte

public void pushByte(byte bite)
Push a new byte onto the top of the byte stack.

Parameters:
bite - the byte to push onto the stack

getShortCount

public int getShortCount()
Return the current depth of the short stack.

Returns:
the size of the short stack

peekShort

public short peekShort()
Return the top short on the stack without removing it.

Returns:
the top short
Throws:
java.util.EmptyStackException - if there are no more short elements left

peekShort

public short peekShort(int n)
Return the n'th short down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more short elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popShort

public short popShort()
Pop the top short off of the stack, and return it.

Returns:
the top short off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushShort

public void pushShort(short element)
Push a new short onto the top of the short stack.

Parameters:
element - the short to push onto the stack

getIntCount

public int getIntCount()
Return the current depth of the int stack.

Returns:
the size of the int stack

peekInt

public int peekInt()
Return the top int on the stack without removing it.

Returns:
the top int
Throws:
java.util.EmptyStackException - if there are no more int elements left

peekInt

public int peekInt(int n)
Return the n'th int down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more int elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popInt

public int popInt()
Pop the top int off of the stack, and return it.

Returns:
the top int off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushInt

public void pushInt(int element)
Push a new int onto the top of the int stack.

Parameters:
element - the int to push onto the stack

getLongCount

public int getLongCount()
Return the current depth of the long stack.

Returns:
the size of the long stack

peekLong

public long peekLong()
Return the top long on the stack without removing it.

Returns:
the top long
Throws:
java.util.EmptyStackException - if there are no more long elements left

peekLong

public long peekLong(int n)
Return the n'th long down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more long elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popLong

public long popLong()
Pop the top long off of the stack, and return it.

Returns:
the top long off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushLong

public void pushLong(long element)
Push a new long onto the top of the long stack.

Parameters:
element - the long to push onto the stack

getFloatCount

public int getFloatCount()
Return the current depth of the float stack.

Returns:
the size of the float stack

peekFloat

public float peekFloat()
Return the top float on the stack without removing it.

Returns:
the top float
Throws:
java.util.EmptyStackException - if there are no more float elements left

peekFloat

public float peekFloat(int n)
Return the n'th float down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more float elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popFloat

public float popFloat()
Pop the top float off of the stack, and return it.

Returns:
the top float off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushFloat

public void pushFloat(float element)
Push a new float onto the top of the float stack.

Parameters:
element - the float to push onto the stack

getDoubleCount

public int getDoubleCount()
Return the current depth of the double stack.

Returns:
the size of the double stack

peekDouble

public double peekDouble()
Return the top double on the stack without removing it.

Returns:
the top double
Throws:
java.util.EmptyStackException - if there are no more double elements left

peekDouble

public double peekDouble(int n)
Return the n'th double down the stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the element index
Returns:
the element at the index
Throws:
java.util.EmptyStackException - if there are no more double elements left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

popDouble

public double popDouble()
Pop the top double off of the stack, and return it.

Returns:
the top double off of the stack
Throws:
java.util.EmptyStackException - if the stack is empty

pushDouble

public void pushDouble(double element)
Push a new double onto the top of the double stack.

Parameters:
element - the double to push onto the stack

getRoot

public java.lang.Object getRoot()
This method allows you to access the root object that has been created after decoding.

Returns:
the root object that has been created after decoding or null if the rulesBase has not decoded any PDUs yet.

setRules

public void setRules(Rules rules)
Set the Rules implementation object containing our rules collection and associated matching policy.

Parameters:
rules - the rules to add to this rulesBase

getTagCount

public int getTagCount()
Return the current depth of the Tag stack.

Returns:
the size of the Tag stack

getTag

public int getTag(int n)
Return the n'th tag down the Tag stack, where 0 is the top element and [getCount()-1] is the bottom element.

Parameters:
n - the Tag index
Returns:
the Tag at the index
Throws:
java.util.EmptyStackException - if there are no more int Tags left
java.lang.IndexOutOfBoundsException - if the index is out of bounds

getTopTag

public int getTopTag()
Gets the raw int for the tag of the TLV currently being processed hence the tag on the top of the stack. The tag's int has the primitive flag dubbed out so it appears to represent a primitive TLV even when the TLV may be constructed.

Returns:
the raw int for the tag of the TLV currently being processed, or NO_TOP_TAG if there is no TLV currently being processed.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:


setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.

Parameters:
classLoader - The new class loader to use, or null to revert to the standard rules

getUseContextClassLoader

public boolean getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.


setUseContextClassLoader

public void setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes that are defined in various rules. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.

Parameters:
use - determines whether to use Context ClassLoader.

fireTagEvent

void fireTagEvent(int id,
                  boolean isPrimitive,
                  TypeClass typeClass)

fireLengthEvent

void fireLengthEvent(int length)

fireValueEvent

void fireValueEvent(java.nio.ByteBuffer buf)

fireFinishEvent

void fireFinishEvent()


Copyright © 2004-2009 . All Rights Reserved.