in ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/endTransaction/EndTransactionResponseGrammar.java [76:321]
public EndTransactionResponseGrammar()
{
setName( EndTransactionResponseGrammar.class.getName() );
// Create the transitions table
super.transitions = new GrammarTransition[EndTransactionResponseStates.LAST_STATE
.ordinal()][256];
/**
* Transition from init state to EndTransactionResponse Sequence
*
* txnEndRes ::= SEQUENCE {
* ...
*
* Creates the EndTransactionResponse object
*/
super.transitions[EndTransactionResponseStates.START_STATE.ordinal()][SEQUENCE.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.START_STATE,
EndTransactionResponseStates.END_TRANSACTION_SEQUENCE_STATE,
SEQUENCE,
new GrammarAction<EndTransactionResponseContainer>( "Init EndTransactionResponse" )
{
public void action( EndTransactionResponseContainer container )
{
// May be empty
if ( container.getCurrentTLV().getLength() == 0 )
{
container.setGrammarEndAllowed( true );
}
}
},
FollowUp.OPTIONAL );
/**
* Transition from Sequence to messageId
*
* txnEndReq ::= SEQUENCE {
* messageID MessageID OPTIONAL,
* -- msgid associated with non-success resultCode
* ...
*
* Set the messageId into the EndTransactionResponse instance, if it's not SUCCESS.
*/
super.transitions[EndTransactionResponseStates.END_TRANSACTION_SEQUENCE_STATE.ordinal()][INTEGER.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.END_TRANSACTION_SEQUENCE_STATE,
EndTransactionResponseStates.FAILED_MESSAGE_ID_STATE,
INTEGER,
new GrammarAction<EndTransactionResponseContainer>( "Set EndTransactionResponse failed MessageID" )
{
public void action( EndTransactionResponseContainer container ) throws DecoderException
{
BerValue value = container.getCurrentTLV().getValue();
try
{
int failedMessageId = IntegerDecoder.parse( value );
if ( failedMessageId > 0 )
{
container.getEndTransactionResponse().setFailedMessageId( failedMessageId );
}
// We may have nothing left
container.setGrammarEndAllowed( true );
}
catch ( IntegerDecoderException ide )
{
LOG.error( I18n
.err( I18n.ERR_08221_BAD_END_TRANSACTION_COMMIT, Strings.dumpBytes( value.getData() ), ide.getMessage() ) );
// This will generate a PROTOCOL_ERROR
throw new DecoderException( ide.getMessage(), ide );
}
}
},
FollowUp.OPTIONAL );
/**
* Transition from Sequence to updateControls
*
* txnEndReq ::= SEQUENCE {
* ...
* updatesControls SEQUENCE OF updateControls SEQUENCE {
*
* Nothing to do, just transitionning
*/
super.transitions[EndTransactionResponseStates.END_TRANSACTION_SEQUENCE_STATE.ordinal()][SEQUENCE.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.END_TRANSACTION_SEQUENCE_STATE,
EndTransactionResponseStates.UPDATE_CONTROLS_SEQ_STATE,
SEQUENCE,
FollowUp.OPTIONAL );
/**
* Transition from updateControls to updateControl
*
* txnEndReq ::= SEQUENCE {
* ...updateControls SEQUENCE {
*
* Create a new UpdateControls instane
*/
super.transitions[EndTransactionResponseStates.UPDATE_CONTROLS_SEQ_STATE.ordinal()][SEQUENCE.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.UPDATE_CONTROLS_SEQ_STATE,
EndTransactionResponseStates.UPDATE_CONTROL_SEQ_STATE,
SEQUENCE,
new GrammarAction<EndTransactionResponseContainer>( "Create an updateControl" )
{
public void action( EndTransactionResponseContainer container )
{
// Create the current UpdateControls
UpdateControls currentUpdateControls = new UpdateControls();
container.setCurrentControls( currentUpdateControls );
}
},
FollowUp.OPTIONAL );
/**
* Transition from updateControl to messageId
*
* txnEndReq ::= SEQUENCE {
* ...
* messageID MessageID,
*
* Set the messageId into the current updateControl
*/
super.transitions[EndTransactionResponseStates.UPDATE_CONTROL_SEQ_STATE.ordinal()][INTEGER.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.UPDATE_CONTROL_SEQ_STATE,
EndTransactionResponseStates.CONTROL_MESSAGE_ID_STATE,
INTEGER,
new GrammarAction<EndTransactionResponseContainer>( "Get the updateControl messageId" )
{
public void action( EndTransactionResponseContainer container ) throws DecoderException
{
UpdateControls currentUpdateControls = container.getCurrentUpdateControls();
BerValue value = container.getCurrentTLV().getValue();
try
{
int messageId = IntegerDecoder.parse( value );
currentUpdateControls.setMessageId( messageId );
// Make the container gather the following bytes
container.setGathering( true );
}
catch ( IntegerDecoderException ide )
{
LOG.error( I18n
.err( I18n.ERR_08222_BAD_END_TRANSACTION_MESSAGE_ID, Strings.dumpBytes( value.getData() ),
ide.getMessage() ) );
// This will generate a PROTOCOL_ERROR
throw new DecoderException( ide.getMessage(), ide );
}
}
},
FollowUp.OPTIONAL );
/**
* ...
* messageID MessageID,
* -- msgid associated with controls
* controls Controls
* ...
*
* Process the controls
*/
super.transitions[EndTransactionResponseStates.CONTROL_MESSAGE_ID_STATE.ordinal()][SEQUENCE.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.CONTROL_MESSAGE_ID_STATE,
EndTransactionResponseStates.CONTROLS_STATE,
SEQUENCE,
new GrammarAction<EndTransactionResponseContainer>( "Process the controls" )
{
public void action( EndTransactionResponseContainer container ) throws DecoderException
{
BerValue value = container.getCurrentTLV().getValue();
container.setGathering( false );
try
{
List<Control> controls = EndTransactionResponseContainer.decode( value.getData() );
// Add the updateControls to the list of updateControls
UpdateControls currentUpdateControls = container.getCurrentUpdateControls();
// Add the decoder controls
currentUpdateControls.setControls( controls );
// And add the decoded updateControls to the list of updateControls
container.getEndTransactionResponse().getUpdateControls().add( currentUpdateControls );
}
catch ( DecoderException de )
{
// Add an error
LOG.error( I18n
.err( I18n.ERR_08223_INVALID_CONTROL_LIST, Strings.dumpBytes( value.getData() ),
de.getMessage() ) );
// This will generate a PROTOCOL_ERROR
throw new DecoderException( de.getMessage(), de );
}
// We may have nothing left
container.setGrammarEndAllowed( true );
}
},
FollowUp.OPTIONAL );
/**
* Transition from controls to updateControl
*
* txnEndReq ::= SEQUENCE {
* ...
* messageID MessageID,
*
* Loop on the updateControl
*/
super.transitions[EndTransactionResponseStates.CONTROLS_STATE.ordinal()][SEQUENCE.getValue()] =
new GrammarTransition<EndTransactionResponseContainer>(
EndTransactionResponseStates.CONTROLS_STATE,
EndTransactionResponseStates.UPDATE_CONTROL_SEQ_STATE,
SEQUENCE,
new GrammarAction<EndTransactionResponseContainer>( "Get the updateControl messageId" )
{
public void action( EndTransactionResponseContainer container )
{
// Create a new current UpdateControl
UpdateControls currentUpdateControls = new UpdateControls();
container.setCurrentControls( currentUpdateControls );
}
},
FollowUp.OPTIONAL );
}