org.apache.directory.shared.asn1.ber
Class AbstractContainer

java.lang.Object
  extended by org.apache.directory.shared.asn1.ber.AbstractContainer
All Implemented Interfaces:
Asn1Container

public abstract class AbstractContainer
extends Object
implements Asn1Container

This class is the abstract container used to store the current state of a PDU being decoded. It also stores the grammars used to decode the PDU, and all the informations needed to decode a PDU.

Author:
Apache Directory Project

Field Summary
protected  int decodeBytes
          A counter for the decoded bytes
protected  Grammar<?> grammar
          All the possible grammars
protected  int[] stateStack
          Store a stack of the current states used when switching grammars
 
Constructor Summary
protected AbstractContainer()
          Creates a new instance of AbstractContainer with a starting state.
protected AbstractContainer(ByteBuffer stream)
          Creates a new instance of AbstractContainer with a starting state.
 
Method Summary
 void clean()
          Clean the container for the next usage.
 TLV getCurrentTLV()
          Get the current TLV
 int getDecodeBytes()
           
 Grammar<?> getGrammar()
          Get the current grammar
 int getMaxPDUSize()
           
 int getNewTlvId()
          Return a new ID and increment the counter
 TLV getParentTLV()
          Get the parent TLV;
 TLVStateEnum getState()
          Get the current grammar state
 ByteBuffer getStream()
          Gets the current stream containing the bytes to decode
 int getTlvId()
          Get the current TLV id
 Enum<?> getTransition()
          Get the transition
 void incrementDecodeBytes(int nb)
          Increment the decodedBytes by the latest received buffer's size.
 boolean isGathering()
          
 boolean isGrammarEndAllowed()
          Check that we can have a end state after this transition
 void rewind()
          Move backward in the stream to the first byte for a given TLV.
 void setCurrentTLV(TLV currentTLV)
          Set the current TLV
 void setGathering(boolean isGathering)
          Set the isGathering flag
 void setGrammarEndAllowed(boolean grammarEndAllowed)
          Set the flag to allow a end transition
 void setMaxPDUSize(int maxPDUSize)
          Set the maximum PDU size.
 void setParentTLV(TLV parentTLV)
          Set the parent TLV.
 void setState(TLVStateEnum state)
          Set the new current state
 void setStream(ByteBuffer stream)
          Stores the Stream being decoded
 void setTransition(Enum<?> transition)
          Update the transition from a state to another
 void updateParent()
          Look for the closest parent which has an expected length above 0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grammar

protected Grammar<?> grammar
All the possible grammars


stateStack

protected int[] stateStack
Store a stack of the current states used when switching grammars


decodeBytes

protected int decodeBytes
A counter for the decoded bytes

Constructor Detail

AbstractContainer

protected AbstractContainer()
Creates a new instance of AbstractContainer with a starting state.


AbstractContainer

protected AbstractContainer(ByteBuffer stream)
Creates a new instance of AbstractContainer with a starting state.

Parameters:
stream - the buffer containing the data to decode
Method Detail

getGrammar

public Grammar<?> getGrammar()
Get the current grammar

Specified by:
getGrammar in interface Asn1Container
Returns:
Returns the grammar used to decode a LdapMessage.

getState

public TLVStateEnum getState()
Get the current grammar state

Specified by:
getState in interface Asn1Container
Returns:
Returns the current grammar state

setState

public void setState(TLVStateEnum state)
Set the new current state

Specified by:
setState in interface Asn1Container
Parameters:
state - The new state

isGrammarEndAllowed

public boolean isGrammarEndAllowed()
Check that we can have a end state after this transition

Specified by:
isGrammarEndAllowed in interface Asn1Container
Returns:
true if this can be the last transition

setGrammarEndAllowed

public void setGrammarEndAllowed(boolean grammarEndAllowed)
Set the flag to allow a end transition

Specified by:
setGrammarEndAllowed in interface Asn1Container
Parameters:
grammarEndAllowed - true or false, depending on the next transition being an end or not.

getTransition

public Enum<?> getTransition()
Get the transition

Specified by:
getTransition in interface Asn1Container
Returns:
Returns the transition from the previous state to the new state

setTransition

public void setTransition(Enum<?> transition)
Update the transition from a state to another

Specified by:
setTransition in interface Asn1Container
Parameters:
transition - The transition to set

setCurrentTLV

public void setCurrentTLV(TLV currentTLV)
Set the current TLV

Specified by:
setCurrentTLV in interface Asn1Container
Parameters:
currentTLV - The current TLV

getCurrentTLV

public TLV getCurrentTLV()
Get the current TLV

Specified by:
getCurrentTLV in interface Asn1Container
Returns:
Returns the current TLV being decoded

getParentTLV

public TLV getParentTLV()
Get the parent TLV;

Specified by:
getParentTLV in interface Asn1Container
Returns:
Returns the parent TLV, if any.

setParentTLV

public void setParentTLV(TLV parentTLV)
Set the parent TLV.

Specified by:
setParentTLV in interface Asn1Container
Parameters:
parentTLV - The parent TLV to set.

clean

public void clean()
Clean the container for the next usage.


getNewTlvId

public int getNewTlvId()
Return a new ID and increment the counter

Specified by:
getNewTlvId in interface Asn1Container
Returns:
A new TLV id.

getTlvId

public int getTlvId()
Description copied from interface: Asn1Container
Get the current TLV id

Specified by:
getTlvId in interface Asn1Container
Returns:
The TLV Id

getDecodeBytes

public int getDecodeBytes()
Specified by:
getDecodeBytes in interface Asn1Container
Returns:
The number of decoded bytes for this message. This is used to control the PDU size and avoid PDU exceeding the maximum allowed size to break the server.

incrementDecodeBytes

public void incrementDecodeBytes(int nb)
Increment the decodedBytes by the latest received buffer's size.

Specified by:
incrementDecodeBytes in interface Asn1Container
Parameters:
nb - The buffer size.

getMaxPDUSize

public int getMaxPDUSize()
Specified by:
getMaxPDUSize in interface Asn1Container
Returns:
The maximum PDU size.

setMaxPDUSize

public void setMaxPDUSize(int maxPDUSize)
Set the maximum PDU size.

Specified by:
setMaxPDUSize in interface Asn1Container
Parameters:
maxPDUSize - The maximum PDU size (if negative or null, will be replaced by the max integer value)

getStream

public ByteBuffer getStream()
Gets the current stream containing the bytes to decode

Specified by:
getStream in interface Asn1Container
Returns:
The current stream

setStream

public void setStream(ByteBuffer stream)
Stores the Stream being decoded

Specified by:
setStream in interface Asn1Container
Parameters:
stream - The stream being decoded

rewind

public void rewind()
Move backward in the stream to the first byte for a given TLV. This is useful when we have read some Tag and Length in order to define the next transition, and if this transition do a grammar switch.

Specified by:
rewind in interface Asn1Container

updateParent

public void updateParent()
Look for the closest parent which has an expected length above 0

Specified by:
updateParent in interface Asn1Container

isGathering

public boolean isGathering()

Specified by:
isGathering in interface Asn1Container
Returns:
true if the container should gather the value into itself, false if the decoding of the Value part should be done immediately for constructed types.

setGathering

public void setGathering(boolean isGathering)
Set the isGathering flag

Specified by:
setGathering in interface Asn1Container
Parameters:
isGathering - true to ask the Asn1Decoder to gather the data into the container. If not set, the default value is 'false'


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.