org.apache.directory.shared.ldap.codec
Class LdapMessageCodec

java.lang.Object
  extended by org.apache.directory.shared.asn1.AbstractAsn1Object
      extended by org.apache.directory.shared.ldap.codec.LdapMessageCodec
All Implemented Interfaces:
Asn1Object
Direct Known Subclasses:
AbandonRequestCodec, AddRequestCodec, BindRequestCodec, CompareRequestCodec, DelRequestCodec, ExtendedRequestCodec, LdapMessageDecorator, LdapResponseCodec, ModifyDNRequestCodec, ModifyRequestCodec, SearchRequestCodec, SearchResultEntryCodec, SearchResultReferenceCodec, UnBindRequestCodec

public abstract class LdapMessageCodec
extends AbstractAsn1Object

The main ldapObject : every Ldap Message are encapsulated in it. It contains a message Id, a operation (protocolOp) and one ore more Controls.

Version:
$Rev: 912399 $, $Date: 2010-02-21 21:52:31 +0100 (Sun, 21 Feb 2010) $,
Author:
Apache Directory Project

Field Summary
protected  int ldapMessageLength
          The LdapMessage length
 
Fields inherited from class org.apache.directory.shared.asn1.AbstractAsn1Object
parent
 
Constructor Summary
LdapMessageCodec()
          Creates a new LdapMessage object.
 
Method Summary
 void addControl(Control control)
          Add a control to the Controls array
 void addControls(java.util.List<Control> controls)
          Set or add a list of controls to the Controls array.
 int computeLength()
          Compute the LdapMessage length LdapMessage : 0x30 L1 | +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId) +--> protocolOp [+--> Controls] MessageId length = Length(0x02) + length(MessageId) + MessageId.length L1 = length(ProtocolOp) LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1
protected abstract  int computeLengthProtocolOp()
           
 java.nio.ByteBuffer encode()
          Generate the PDU which contains the encoded object.
protected abstract  void encodeProtocolOp(java.nio.ByteBuffer buffer)
           
 Control getCodecControl(java.lang.String oid)
           
 java.util.List<Control> getControls()
          Get the Control Objects
 Control getControls(int i)
          Get the Control Object at a specific index
 Control getCurrentControl()
          Get the current Control Object
 int getMessageId()
          Get the message ID
abstract  MessageTypeEnum getMessageType()
          Get the message type
abstract  java.lang.String getMessageTypeName()
          Get the message type Name
 void initControls()
          Init the controls array
 void setMessageId(int messageId)
          Set the message ID
protected  java.lang.String toString(java.lang.String protocolOp)
          Get a String representation of a LdapMessage
 
Methods inherited from class org.apache.directory.shared.asn1.AbstractAsn1Object
addLength, encode, getCurrentLength, getExpectedLength, getParent, getTlvId, setCurrentLength, setExpectedLength, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ldapMessageLength

protected int ldapMessageLength
The LdapMessage length

Constructor Detail

LdapMessageCodec

public LdapMessageCodec()
Creates a new LdapMessage object.

Method Detail

getControls

public Control getControls(int i)
Get the Control Object at a specific index

Parameters:
i - The index of the Control Object to get
Returns:
The selected Control Object

getControls

public java.util.List<Control> getControls()
Get the Control Objects

Returns:
The Control Objects

getCurrentControl

public Control getCurrentControl()
Get the current Control Object

Returns:
The current Control Object

getCodecControl

public Control getCodecControl(java.lang.String oid)

addControl

public void addControl(Control control)
Add a control to the Controls array

Parameters:
control - The Control to add

addControls

public void addControls(java.util.List<Control> controls)
Set or add a list of controls to the Controls array. If the existing control array is not null then the given controls will be added

Parameters:
controls - The list of Controls to set or add

initControls

public void initControls()
Init the controls array


getMessageId

public int getMessageId()
Get the message ID

Returns:
The message ID

setMessageId

public void setMessageId(int messageId)
Set the message ID

Parameters:
messageId - The message ID

getMessageType

public abstract MessageTypeEnum getMessageType()
Get the message type

Returns:
The message type

getMessageTypeName

public abstract java.lang.String getMessageTypeName()
Get the message type Name

Returns:
The message type name

computeLengthProtocolOp

protected abstract int computeLengthProtocolOp()

computeLength

public int computeLength()
Compute the LdapMessage length LdapMessage : 0x30 L1 | +--> 0x02 0x0(1-4) [0..2^31-1] (MessageId) +--> protocolOp [+--> Controls] MessageId length = Length(0x02) + length(MessageId) + MessageId.length L1 = length(ProtocolOp) LdapMessage length = Length(0x30) + Length(L1) + MessageId length + L1

Specified by:
computeLength in interface Asn1Object
Specified by:
computeLength in class AbstractAsn1Object
Returns:
The object's computed length

encodeProtocolOp

protected abstract void encodeProtocolOp(java.nio.ByteBuffer buffer)
                                  throws EncoderException
Throws:
EncoderException

encode

public java.nio.ByteBuffer encode()
                           throws EncoderException
Generate the PDU which contains the encoded object. The generation is done in two phases : - first, we compute the length of each part and the global PDU length - second, we produce the PDU.
 0x30 L1 
   | 
   +--> 0x02 L2 MessageId  
   +--> ProtocolOp 
   +--> Controls 
   
 L2 = Length(MessageId)
 L1 = Length(0x02) + Length(L2) + L2 + Length(ProtocolOp) + Length(Controls)
 LdapMessageLength = Length(0x30) + Length(L1) + L1
 

Parameters:
buffer - The encoded PDU
Returns:
A ByteBuffer that contaons the PDU
Throws:
EncoderException - If anything goes wrong.

toString

protected java.lang.String toString(java.lang.String protocolOp)
Get a String representation of a LdapMessage

Returns:
A LdapMessage String


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