org.apache.asn1.ber
Class Tuple

java.lang.Object
  extended by org.apache.asn1.ber.Tuple

public class Tuple
extends java.lang.Object

TLV Tuple used by the value chunking decoder. Because the length field is a primitive int it's maximum value is 2,147,483,647 a single TLV's tuple cannot have a length over this amount or a value size over 2 GB.

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

Field Summary
private static int BIT_13
          precalculated left shift of 1 by 14 places
private static int BIT_15
          precalculated left shift of 1 by 16 places
private static int BIT_20
          precalculated left shift of 1 by 21 places
private static int BIT_23
          precalculated left shift of 1 by 24 places
private static int BIT_27
          precalculated left shift of 1 by 28 places
private static int BIT_5
          mask for bit 5 with 0-based index
private static int BIT_6
          mask for bit 6 with 0-based index
private static int BIT_7
          mask for bit 7 with 0-based index
private static java.nio.ByteBuffer EMPTY_BUFFER
          empty buffer reused for handling null
(package private)  int id
          the tag id for this TLV tuple
(package private)  int index
          tlv byte index
(package private)  boolean isPrimitive
          the flag for whether or not this TLV is constructed or primitive
(package private)  int length
          the length for this TLV tuple's value field
(package private)  int rawTag
          the raw tag data
(package private)  TypeClass typeClass
          the type class for this TLV
(package private)  java.nio.ByteBuffer valueChunk
          the present value chunk buffer read for this TLV tuple
(package private)  int valueIndex
          tlv value index for how far into the value we have read
 
Constructor Summary
Tuple()
          Empty do nothing tuple.
Tuple(int id, int length)
          Creates constructed application type tlv tuples.
Tuple(int id, int length, boolean isPrimitive, TypeClass typeClass)
          Creates constructed application type tlv tuples.
Tuple(int id, int length, TypeClass typeClass)
          Creates constructed application type tlv tuples.
Tuple(int id, TypeClass typeClass)
          Creates a tuple where the length is indefinite.
 
Method Summary
 void clear()
          Clears the values of this tuple.
 java.lang.Object clone()
           
 boolean equals(java.lang.Object o)
          Does not take into account the value, index or the valueIndex values when checking for equality.
 int getId()
          Gets the tag id for this TLV Tuple.
 java.nio.ByteBuffer getLastValueChunk()
          Gets the last chunk read for the value field (V-part) for this TLV Tuple.
 int getLength()
          Gets the value length for this TLV Tuple.
 int getLengthLength()
          Gets the length in bytes of the length section of this TLV Tuple.
 int getRawPrimitiveTag()
          Gets the raw tag with the primitive/constructed flag dubbed out.
 int getRawTag()
          Gets the raw tag as it is stuffed into a primitive int.
 int getTagLength()
          Gets the length in bytes of the tag section for this TLV tuple.
 TypeClass getTypeClass()
          Gets the BER TLV TypeClass for this TLV Tuple.
 boolean isIndefinite()
          Get's whether or not this tuples's length is indefinite.
 boolean isIndefiniteTerminator()
          Get's whether or not this tuple terminates an indefinite constructed tuple.
 boolean isPrimitive()
          Gets whether or not this TLV tuple is primitive or constructed.
 void setId(int id)
          Sets the id of this Tuple and as a side effect the rawTag.
 void setLastValueChunk(java.nio.ByteBuffer buf)
          Sets the value representing the last chunk read or the last chunch to write.
 void setLength(java.nio.ByteBuffer octets, int lengthBytes)
          Sets the length bytes.
 void setLength(int length)
           
 void setRawTag(int rawTag)
          Sets the raw tag encoded as a primitive int and as a side effect this call also sets the id, primitive flag, and typeClass of this TLV tuple.
 void setTag(java.nio.ByteBuffer octets, int tagLength)
          Sets the tag section within the buffer.
 void setTag(TagEnum tag)
          Sets the tag parameters using a tag enumeration type.
 void setTag(TagEnum tag, boolean isPrimitive)
          Sets the tag parameters using a tag enumeration type explicitly setting the primitive/constructed bit.
 void setValueLength(int length)
          Sets the value length of this Tuple.
 int size()
          Gets the total size of this TLV tuple in bytes.
 java.nio.ByteBuffer toEncodedBuffer(java.util.List valueChunks)
          If this is a primitive TLV then the valueBytes argument is used to produce an encoded image of this TLV.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BUFFER

private static final java.nio.ByteBuffer EMPTY_BUFFER
empty buffer reused for handling null


BIT_5

private static final int BIT_5
mask for bit 5 with 0-based index

See Also:
Constant Field Values

BIT_6

private static final int BIT_6
mask for bit 6 with 0-based index

See Also:
Constant Field Values

BIT_7

private static final int BIT_7
mask for bit 7 with 0-based index

See Also:
Constant Field Values

BIT_13

private static final int BIT_13
precalculated left shift of 1 by 14 places

See Also:
Constant Field Values

BIT_15

private static final int BIT_15
precalculated left shift of 1 by 16 places

See Also:
Constant Field Values

BIT_20

private static final int BIT_20
precalculated left shift of 1 by 21 places

See Also:
Constant Field Values

BIT_23

private static final int BIT_23
precalculated left shift of 1 by 24 places

See Also:
Constant Field Values

BIT_27

private static final int BIT_27
precalculated left shift of 1 by 28 places

See Also:
Constant Field Values

rawTag

int rawTag
the raw tag data


id

int id
the tag id for this TLV tuple


isPrimitive

boolean isPrimitive
the flag for whether or not this TLV is constructed or primitive


typeClass

TypeClass typeClass
the type class for this TLV


length

int length
the length for this TLV tuple's value field


valueChunk

java.nio.ByteBuffer valueChunk
the present value chunk buffer read for this TLV tuple


index

int index
tlv byte index


valueIndex

int valueIndex
tlv value index for how far into the value we have read

Constructor Detail

Tuple

public Tuple()
Empty do nothing tuple.


Tuple

public Tuple(int id,
             int length)
Creates constructed application type tlv tuples. Constructed TLV's with a definate length will use this constructor predominantly. The TypeClass defualts to APPLICATION.

Parameters:
id - the tag id of the tlv
length - the length of the value which is the length of all the nested tuples.

Tuple

public Tuple(int id,
             int length,
             TypeClass typeClass)
Creates constructed application type tlv tuples. Constructed TLV's with a definate length will use this constructor predominantly.

Parameters:
id - the tag id of the tlv
length - the length of the value which is the length of all the nested tuples.
typeClass - the type class of this tlv tuple

Tuple

public Tuple(int id,
             int length,
             boolean isPrimitive,
             TypeClass typeClass)
Creates constructed application type tlv tuples. Constructed TLV's with a definate length will use this constructor predominantly.

Parameters:
id - the tag id of the tlv
length - the length of the value which is the length of all the nested tuples.
isPrimitive - whether or not this Tuple is primitive or constructed
typeClass - the type class of this tlv tuple

Tuple

public Tuple(int id,
             TypeClass typeClass)
Creates a tuple where the length is indefinite. The tuple according to the BER encoding must be of the constructed type.

Parameters:
id - the tag id of the tlv
typeClass - the type class for the tlv
Method Detail

getId

public int getId()
Gets the tag id for this TLV Tuple.

Returns:
the tag id

setId

public void setId(int id)
Sets the id of this Tuple and as a side effect the rawTag.

Parameters:
id - the new tag id to set

getRawTag

public int getRawTag()
Gets the raw tag as it is stuffed into a primitive int.

Returns:
a primitive int stuffed with the first four octets of the tag

setRawTag

public void setRawTag(int rawTag)
Sets the raw tag encoded as a primitive int and as a side effect this call also sets the id, primitive flag, and typeClass of this TLV tuple.

Parameters:
rawTag - the raw primitive int encoded tag.

setTag

public void setTag(TagEnum tag)
Sets the tag parameters using a tag enumeration type. This operation sets the id, isPrimitive, typeClass, and rawTag fields at the same time.

Parameters:
tag - the tag enumeration constant

setTag

public void setTag(TagEnum tag,
                   boolean isPrimitive)
Sets the tag parameters using a tag enumeration type explicitly setting the primitive/constructed bit. This operation sets the id, isPrimitive, typeClass, and rawTag fields at the same time.

Parameters:
tag - the tag enumeration constant
isPrimitive - primitive/constructed bit override

getRawPrimitiveTag

public int getRawPrimitiveTag()
Gets the raw tag with the primitive/constructed flag dubbed out. Effectively this makes every tag appear primitive and is done to remove encoding ambiguities that could interfere with pattern matching.

Returns:
the raw tag with the primitive/constructed flag dubbed out

isIndefinite

public boolean isIndefinite()
Get's whether or not this tuples's length is indefinite.

Returns:
whether or not this tuple's length is indefinite

isIndefiniteTerminator

public boolean isIndefiniteTerminator()
Get's whether or not this tuple terminates an indefinite constructed tuple. This means that length == 0 && isPrimitive = true && id == 0 and the type class is universal.

Returns:
whether or not this node's length is indefinite

isPrimitive

public boolean isPrimitive()
Gets whether or not this TLV tuple is primitive or constructed.

Returns:
true if it is primitive, false if it is constructed

getLength

public int getLength()
Gets the value length for this TLV Tuple.

Returns:
the length in bytes of the value field for this TLV tuple

setLength

public void setLength(int length)

getTypeClass

public TypeClass getTypeClass()
Gets the BER TLV TypeClass for this TLV Tuple.

Returns:
the BER TLV TypeClass for this TLV Tuple

getLastValueChunk

public java.nio.ByteBuffer getLastValueChunk()
Gets the last chunk read for the value field (V-part) for this TLV Tuple.

Returns:
the last valueChunk field for this TLV Tuple

setLastValueChunk

public void setLastValueChunk(java.nio.ByteBuffer buf)
Sets the value representing the last chunk read or the last chunch to write.

Parameters:
buf - the last chunk as a buffer

size

public int size()
Gets the total size of this TLV tuple in bytes. This includes the length of the tag field, the length of the length field and the length of the value feild.

Returns:
the total TLV size in bytes

clear

public void clear()
Clears the values of this tuple.


equals

public boolean equals(java.lang.Object o)
Does not take into account the value, index or the valueIndex values when checking for equality. Technically if both are being constructed by the decoder then they should only be equal when these values are equal because the tag, length or value would not be correct. Plus since this is a chunking tuple the valueChunk means nothing with respect to the final value.

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

toEncodedBuffer

public java.nio.ByteBuffer toEncodedBuffer(java.util.List valueChunks)
If this is a primitive TLV then the valueBytes argument is used to produce an encoded image of this TLV. If it is constructed then only the TL part of the tuple is encoded leaving the value to be encoded by the set of child TLVs.

Returns:
partial encoded image if constructed or complete TLV if primitive
To Do:
this should produce chunking output and needs to be removed from here actually and made into a standalone encoder. You give it a buffer and it fills it as much as it can remembering where the encode stopped. Hence it is stateful as expected from the statemachine.

setTag

public void setTag(java.nio.ByteBuffer octets,
                   int tagLength)
Sets the tag section within the buffer.

Parameters:
octets - the buffer to set the tag in
tagLength - the length of the tag section

setValueLength

public void setValueLength(int length)
Sets the value length of this Tuple.

Parameters:
length - the length of this tuple's value.
See Also:
to get the entire determinate length of tuple

setLength

public void setLength(java.nio.ByteBuffer octets,
                      int lengthBytes)
Sets the length bytes.

Parameters:
octets - the byte [] to set length in
lengthBytes - the number bytes for the length section

getTagLength

public int getTagLength()
Gets the length in bytes of the tag section for this TLV tuple.

Returns:
the length in bytes of the tag section for this TLV tuple

getLengthLength

public int getLengthLength()
Gets the length in bytes of the length section of this TLV Tuple.

Returns:
the length in bytes of the length section


Copyright © 2004-2009 . All Rights Reserved.