org.apache.asn1new.ber.tlv
Class Tag

java.lang.Object
  extended by org.apache.asn1new.ber.tlv.Tag
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Tag
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The Tag component of a BER TLV Tuple.

Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
private  int bytePos
          Current position in the tagBytes
static int CONSTRUCTED_FLAG
          tag flag for the primitive/constructed bit - 0010 0000 - 0x20
static int FOUR_OCTET_IDMAX
          the max id size with four tag octets
private  int id
          the int used to store the tag octets
private  boolean isPrimitive
          whether or not this tag represents a primitive type
static int LONG_FLAG
          tag flag indicating the use of the long tag encoding form
static int LONG_MASK
          tag mask for the long tag format - 0111 1111 - 0x7F
static int MAX_TAG_BYTES
          The maximum bytes number that could be used to hold the value.
static int ONE_OCTET_IDMAX
          the max id size with one tag octet
static long serialVersionUID
           
static int SHORT_MASK
          tag mask for the short tag format - 0001 1111 - 0x1F
private  int size
          the number of octets currently read
static int TAG_MAX_FLAG
          the bit that signal that the value will overflow
private  byte[] tagBytes
          The bytes read from the PDU.
static int THREE_OCTET_IDMAX
          the max id size with three tag octets
static int TWO_OCTET_IDMAX
          the max id size with two tag octets
static int[] TYPE_CLASS
          array of the different Type classes
static int TYPE_CLASS_APPLICATION
          value for the application type class
static int TYPE_CLASS_CONTEXT_SPECIFIC
          value for the context specific type class
static int TYPE_CLASS_MASK
          mask to get the type class value
static int TYPE_CLASS_PRIVATE
          value for the private type class
static int TYPE_CLASS_UNIVERSAL
          value for the universal type class
private  int typeClass
          the type class of this tag
 
Constructor Summary
Tag()
          Creates a new Tag object.
 
Method Summary
 void addByte(byte octet)
          Add a byte to the inner representation of the tag.
 java.lang.Object clone()
          Clone the Tag
 int getId()
          Gets the id which represent the tag.
 int getSize()
          Gets the number of octets of this Tag.
 byte getTagByte()
          Get the first byte of the tag.
 byte[] getTagBytes()
           
 byte getTagBytes(int pos)
          Get the byte at a specific position of the tag's bytes
 int getTypeClass()
          Gets the type class for this Tag.
 void incTagSize()
          Gets the number of octets in this Tag.
 boolean isApplication()
          Tells if the tag class is Application or not
 boolean isConstructed()
          Checks to see if the tag is constructed.
 boolean isContextual()
          Tells if the tag class is Contextual or not
 boolean isPrimitive()
          Checks to see if the tag represented by this Tag is primitive or constructed.
 boolean isPrivate()
          Tells if the tag class is Private or not
 boolean isUniversal()
          Tells if the tag is Universal or not
 void reset()
          Reset the tag so that it can be reused.
 void setId(int id)
          Set the id.
 void setPrimitive(boolean isPrimitive)
          Set the tag type to Primitive or Constructed
 void setSize(int size)
          Gets the number of octets in this Tag.
 void setTypeClass(int typeClass)
          Gets the type class for this Tag.
 java.lang.String toString()
          A string representation of a Tag
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

CONSTRUCTED_FLAG

public static final transient int CONSTRUCTED_FLAG
tag flag for the primitive/constructed bit - 0010 0000 - 0x20

See Also:
Constant Field Values

SHORT_MASK

public static final transient int SHORT_MASK
tag mask for the short tag format - 0001 1111 - 0x1F

See Also:
Constant Field Values

LONG_MASK

public static final transient int LONG_MASK
tag mask for the long tag format - 0111 1111 - 0x7F

See Also:
Constant Field Values

LONG_FLAG

public static final transient int LONG_FLAG
tag flag indicating the use of the long tag encoding form

See Also:
Constant Field Values

ONE_OCTET_IDMAX

public static final transient int ONE_OCTET_IDMAX
the max id size with one tag octet

See Also:
Constant Field Values

TWO_OCTET_IDMAX

public static final transient int TWO_OCTET_IDMAX
the max id size with two tag octets

See Also:
Constant Field Values

THREE_OCTET_IDMAX

public static final transient int THREE_OCTET_IDMAX
the max id size with three tag octets

See Also:
Constant Field Values

FOUR_OCTET_IDMAX

public static final transient int FOUR_OCTET_IDMAX
the max id size with four tag octets

See Also:
Constant Field Values

TAG_MAX_FLAG

public static final transient int TAG_MAX_FLAG
the bit that signal that the value will overflow

See Also:
Constant Field Values

TYPE_CLASS_UNIVERSAL

public static final transient int TYPE_CLASS_UNIVERSAL
value for the universal type class

See Also:
Constant Field Values

TYPE_CLASS_APPLICATION

public static final transient int TYPE_CLASS_APPLICATION
value for the application type class

See Also:
Constant Field Values

TYPE_CLASS_CONTEXT_SPECIFIC

public static final transient int TYPE_CLASS_CONTEXT_SPECIFIC
value for the context specific type class

See Also:
Constant Field Values

TYPE_CLASS_PRIVATE

public static final transient int TYPE_CLASS_PRIVATE
value for the private type class

See Also:
Constant Field Values

TYPE_CLASS_MASK

public static final transient int TYPE_CLASS_MASK
mask to get the type class value

See Also:
Constant Field Values

MAX_TAG_BYTES

public static final transient int MAX_TAG_BYTES
The maximum bytes number that could be used to hold the value. Actually, it's five : - 7 bits x 4 bytes = 28 bits, which is not enough to represent an int. - 7 bits x 5 bytes = 35 bits, which is just above int's number of bits Note : the higher bit is not used.

See Also:
Constant Field Values

TYPE_CLASS

public static final int[] TYPE_CLASS
array of the different Type classes


id

private int id
the int used to store the tag octets


size

private int size
the number of octets currently read


isPrimitive

private boolean isPrimitive
whether or not this tag represents a primitive type


typeClass

private int typeClass
the type class of this tag


tagBytes

private byte[] tagBytes
The bytes read from the PDU. We store only 5 bytes, so we can't have tag that are above 2^28


bytePos

private int bytePos
Current position in the tagBytes

Constructor Detail

Tag

public Tag()
Creates a new Tag object.

Method Detail

reset

public void reset()
Reset the tag so that it can be reused.


getId

public int getId()
Gets the id which represent the tag.

Returns:
the id

setId

public void setId(int id)
Set the id.

Parameters:
id - The id to be set

getSize

public int getSize()
Gets the number of octets of this Tag.

Returns:
the number of octets of this Tag

setSize

public void setSize(int size)
Gets the number of octets in this Tag.

Parameters:
size - The size of the tag

incTagSize

public void incTagSize()
Gets the number of octets in this Tag.


getTypeClass

public int getTypeClass()
Gets the type class for this Tag.

Returns:
The typeClass for this Tag

setTypeClass

public void setTypeClass(int typeClass)
Gets the type class for this Tag.

Parameters:
typeClass - The TypeClass to set

isConstructed

public boolean isConstructed()
Checks to see if the tag is constructed.

Returns:
true if constructed, false if primitive

isPrimitive

public boolean isPrimitive()
Checks to see if the tag represented by this Tag is primitive or constructed.

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

isUniversal

public boolean isUniversal()
Tells if the tag is Universal or not

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

isApplication

public boolean isApplication()
Tells if the tag class is Application or not

Returns:
true if it is Application, false otherwise.

isPrivate

public boolean isPrivate()
Tells if the tag class is Private or not

Returns:
true if it is Private, false otherwise.

isContextual

public boolean isContextual()
Tells if the tag class is Contextual or not

Returns:
true if it is Contextual, false otherwise.

setPrimitive

public void setPrimitive(boolean isPrimitive)
Set the tag type to Primitive or Constructed

Parameters:
isPrimitive - The type to set

addByte

public void addByte(byte octet)
Add a byte to the inner representation of the tag.

Parameters:
octet - The byte to add.

getTagByte

public byte getTagByte()
Get the first byte of the tag.

Returns:
The first byte of the tag.

getTagBytes

public byte[] getTagBytes()
Returns:
Get all the bytes of the tag

getTagBytes

public byte getTagBytes(int pos)
Get the byte at a specific position of the tag's bytes

Parameters:
pos - The position
Returns:
The byte found

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the Tag

Overrides:
clone in class java.lang.Object
Returns:
A copy of the tag
Throws:
java.lang.CloneNotSupportedException - Thrown if we have a cloning problem

toString

public java.lang.String toString()
A string representation of a Tag

Overrides:
toString in class java.lang.Object
Returns:
A string representation of a Tag


Copyright © 2005-2009 . All Rights Reserved.