*/
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
if ( buffer == null )
{
throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
}
try
{
// The ExtensibleMatch Tag
buffer.put( ( byte ) LdapConstants.EXTENSIBLE_MATCH_FILTER_TAG );
buffer.put( TLV.getBytes( extensibleMatchLength ) );
if ( ( matchingRule == null ) && ( type == null ) )
{
throw new EncoderException( I18n.err( I18n.ERR_04056 ) );
}
// The matching rule
if ( matchingRule != null )
{
buffer.put( ( byte ) LdapConstants.MATCHING_RULE_ID_TAG );
buffer.put( TLV.getBytes( matchingRuleBytes.length ) );
buffer.put( matchingRuleBytes );
}
// The type
if ( type != null )
{
buffer.put( ( byte ) LdapConstants.MATCHING_RULE_TYPE_TAG );
buffer.put( TLV.getBytes( typeBytes.length ) );
buffer.put( typeBytes );
}
// The match value
if ( matchValue != null )
{
buffer.put( ( byte ) LdapConstants.MATCH_VALUE_TAG );
byte[] bytes = matchValue.getBytes();
int bytesLength = bytes.length;
buffer.put( TLV.getBytes( bytesLength ) );
if ( bytesLength != 0 )
{
buffer.put( bytes );
}
}
// The dnAttributes flag, if true only
if ( dnAttributes )
{
buffer.put( ( byte ) LdapConstants.DN_ATTRIBUTES_FILTER_TAG );
buffer.put( ( byte ) 1 );
buffer.put( Value.TRUE_VALUE );
}
}
catch ( BufferOverflowException boe )
{
throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
}
return buffer;
}