if ( tlv.getLength() == 0 )
{
String msg = I18n.err( I18n.ERR_04085 );
LOG.error( msg );
AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
// I guess that trying to add an entry which Dn is empty is a naming violation...
// Not 100% sure though ...
throw new ResponseCarryingException( msg, response, ResultCodeEnum.NAMING_VIOLATION,
Dn.EMPTY_DN, null );
}
else
{
Dn entryDn = null;
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try
{
entryDn = new Dn( dnStr );
}
catch ( LdapInvalidDnException ine )
{
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes)
+ ") is invalid";
LOG.error( "{} : {}", msg, ine.getMessage() );
AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
Dn.EMPTY_DN, ine );
}
addRequest.setEntryDn( entryDn );
}
LOG.debug( "Adding an entry with Dn : {}", addRequest.getEntry() );
}
} );
// --------------------------------------------------------------------------------------------
// Transition from Entry to Attributes
// --------------------------------------------------------------------------------------------
// AddRequest ::= [APPLICATION 8] SEQUENCE {
// ...
// attributes AttributeList }
//
// AttributeList ::= SEQUENCE OF ...
//
// Initialize the attribute list
super.transitions[LdapStatesEnum.ENTRY_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
LdapStatesEnum.ENTRY_STATE, LdapStatesEnum.ATTRIBUTES_STATE, UniversalTag.SEQUENCE.getValue(), null );
// --------------------------------------------------------------------------------------------
// Transition from Attributes to Attribute
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
//
// We don't do anything in this transition. The attribute will be created when we met the type
super.transitions[LdapStatesEnum.ATTRIBUTES_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
LdapStatesEnum.ATTRIBUTES_STATE, LdapStatesEnum.ATTRIBUTE_STATE, UniversalTag.SEQUENCE.getValue(), null );
// --------------------------------------------------------------------------------------------
// Transition from Attribute to type
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
// type AttributeDescription,
// ...
//
// AttributeDescription LDAPString
//
// We store the type in the current attribute
super.transitions[LdapStatesEnum.ATTRIBUTE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
LdapStatesEnum.ATTRIBUTE_STATE, LdapStatesEnum.TYPE_STATE, UniversalTag.OCTET_STRING.getValue(),
new GrammarAction<LdapMessageContainer<AddRequestDecorator>>( "Store attribute type" )
{
public void action( LdapMessageContainer<AddRequestDecorator> container ) throws DecoderException
{
AddRequestDecorator addRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the type. It can't be null.
if ( tlv.getLength() == 0 )
{
String msg = I18n.err( I18n.ERR_04086 );
LOG.error( msg );
AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
addRequest.getEntry().getDn(), null );
}
String type = getType(tlv.getValue().getData());
try
{
addRequest.addAttributeType( type );
}
catch ( LdapException ne )
{
String msg = I18n.err( I18n.ERR_04087 );
LOG.error( msg );
AddResponseImpl response = new AddResponseImpl( addRequest.getMessageId() );
throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
addRequest.getEntry().getDn(), ne );
}
if ( IS_DEBUG )
{
LOG.debug( "Adding type {}", type );
}
}
} );
// --------------------------------------------------------------------------------------------
// Transition from type to vals
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
// ...
// vals SET OF AttributeValue }
//
// Nothing to do here.
super.transitions[LdapStatesEnum.TYPE_STATE.ordinal()][UniversalTag.SET.getValue()] = new GrammarTransition(
LdapStatesEnum.TYPE_STATE, LdapStatesEnum.VALUES_STATE, UniversalTag.SET.getValue(), null );
// --------------------------------------------------------------------------------------------
// Transition from vals to Value
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
// ...
// vals SET OF AttributeValue }
//
// AttributeValue OCTET STRING
//
// Store the value into the current attribute
super.transitions[LdapStatesEnum.VALUES_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
LdapStatesEnum.VALUES_STATE, LdapStatesEnum.VALUE_STATE, UniversalTag.OCTET_STRING.getValue(), new ValueAction() );
// --------------------------------------------------------------------------------------------
// Transition from Value to Value
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
// ...
// vals SET OF AttributeValue }
//
// AttributeValue OCTET STRING
//
// Store the value into the current attribute
super.transitions[LdapStatesEnum.VALUE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
LdapStatesEnum.VALUE_STATE, LdapStatesEnum.VALUE_STATE, UniversalTag.OCTET_STRING.getValue(), new ValueAction() );
// --------------------------------------------------------------------------------------------
// Transition from Value to Attribute
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
//
// Nothing to do here.
super.transitions[LdapStatesEnum.VALUE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] = new GrammarTransition(
LdapStatesEnum.VALUE_STATE, LdapStatesEnum.ATTRIBUTE_STATE, UniversalTag.SEQUENCE.getValue(), null );
// --------------------------------------------------------------------------------------------
// Transition from Value to Controls
// --------------------------------------------------------------------------------------------
// AttributeList ::= SEQUENCE OF SEQUENCE {
//
// Initialize the controls
super.transitions[LdapStatesEnum.VALUE_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
LdapStatesEnum.VALUE_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
new ControlsInitAction() );
// --------------------------------------------------------------------------------------------
// AddResponse Message.
// --------------------------------------------------------------------------------------------
// LdapMessage ::= ... AddResponse ...
// AddResponse ::= [APPLICATION 9] LDAPResult
//
super.transitions[LdapStatesEnum.MESSAGE_ID_STATE.ordinal()][LdapConstants.ADD_RESPONSE_TAG] = new GrammarTransition(
LdapStatesEnum.MESSAGE_ID_STATE, LdapStatesEnum.ADD_RESPONSE_STATE, LdapConstants.ADD_RESPONSE_TAG,
new GrammarAction<LdapMessageContainer<AddResponseDecorator>>( "Init AddResponse" )
{
public void action( LdapMessageContainer<AddResponseDecorator> container ) throws DecoderException
{
// Now, we can allocate the AddResponse Object
AddResponseDecorator addResponse = new AddResponseDecorator(
container.getLdapCodecService(), new AddResponseImpl( container.getMessageId() ) );
container.setMessage( addResponse );
// We will check that the request is not null
TLV tlv = container.getCurrentTLV();