in ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/extended/ads_impl/storedProcedure/StoredProcedureRequestGrammar.java [71:310]
private StoredProcedureRequestGrammar()
{
setName( StoredProcedureRequestGrammar.class.getName() );
// Create the transitions table
super.transitions = new GrammarTransition[StoredProcedureStatesEnum.LAST_STORED_PROCEDURE_STATE.ordinal()][256];
//============================================================================================
// StoredProcedure Message
//============================================================================================
// StoredProcedure ::= SEQUENCE {
// ...
// Nothing to do.
super.transitions[StoredProcedureStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.START_STATE,
StoredProcedureStatesEnum.STORED_PROCEDURE_STATE,
UniversalTag.SEQUENCE.getValue(),
null,
FollowUp.MANDATORY );
// language OCTETSTRING, (Tag)
// ...
//
// Creates the storeProcedure and stores the language
super.transitions[StoredProcedureStatesEnum.STORED_PROCEDURE_STATE.ordinal()][UniversalTag.OCTET_STRING
.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.STORED_PROCEDURE_STATE,
StoredProcedureStatesEnum.LANGUAGE_STATE,
UniversalTag.OCTET_STRING.getValue(),
new GrammarAction<StoredProcedureRequestContainer>( "Stores the language" )
{
public void action( StoredProcedureRequestContainer container ) throws DecoderException
{
TLV tlv = container.getCurrentTLV();
// Store the value.
if ( tlv.getLength() == 0 )
{
// We can't have a void language !
String msg = I18n.err( I18n.ERR_08207_SP_LANGUAGE_NULL );
LOG.error( msg );
throw new DecoderException( msg );
}
else
{
// Only this field's type is String by default
String language = Strings.utf8ToString( tlv.getValue().getData() );
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.msg( I18n.MSG_08213_SP_LANGUAGE_FOUND, language ) );
}
container.getStoredProcedure().setLanguage( language );
}
}
},
FollowUp.MANDATORY );
// procedure OCTET STRING, (Value)
// ...
// Stores the procedure.
super.transitions[StoredProcedureStatesEnum.LANGUAGE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.LANGUAGE_STATE,
StoredProcedureStatesEnum.PROCEDURE_STATE,
UniversalTag.OCTET_STRING.getValue(),
new GrammarAction<StoredProcedureRequestContainer>( "Stores the procedure" )
{
public void action( StoredProcedureRequestContainer container ) throws DecoderException
{
TLV tlv = container.getCurrentTLV();
// Store the value.
if ( tlv.getLength() == 0 )
{
// We can't have a void procedure !
String msg = I18n.err( I18n.ERR_08208_NULL_PROCEDURE );
LOG.error( msg );
throw new DecoderException( msg );
}
else
{
byte[] procedure = tlv.getValue().getData();
container.getStoredProcedure().setProcedure( procedure );
}
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.msg( I18n.MSG_08212_PROCEDURE_FOUND,
container.getStoredProcedure().getProcedureSpecification() ) );
}
}
},
FollowUp.MANDATORY );
// parameters SEQUENCE OF Parameter { (Value)
// ...
// The list of parameters will be created with the first parameter.
// We can have an empty list of parameters, so the PDU can be empty
super.transitions[StoredProcedureStatesEnum.PROCEDURE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.PROCEDURE_STATE,
StoredProcedureStatesEnum.PARAMETERS_STATE,
UniversalTag.SEQUENCE.getValue(),
new GrammarAction<StoredProcedureRequestContainer>( "Stores the parameters" )
{
public void action( StoredProcedureRequestContainer container )
{
container.setGrammarEndAllowed( true );
}
},
FollowUp.OPTIONAL );
// parameter SEQUENCE OF { (Value)
// ...
// Nothing to do.
super.transitions[StoredProcedureStatesEnum.PARAMETERS_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.PARAMETERS_STATE,
StoredProcedureStatesEnum.PARAMETER_STATE,
UniversalTag.SEQUENCE.getValue(),
null,
FollowUp.OPTIONAL );
// Parameter ::= {
// type OCTETSTRING, (Value)
// ...
//
// We can create a parameter, and store its type
super.transitions[StoredProcedureStatesEnum.PARAMETER_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.PARAMETER_STATE,
StoredProcedureStatesEnum.PARAMETER_TYPE_STATE,
UniversalTag.OCTET_STRING.getValue(),
new GrammarAction<StoredProcedureRequestContainer>( "Store parameter type" )
{
public void action( StoredProcedureRequestContainer container ) throws DecoderException
{
TLV tlv = container.getCurrentTLV();
// Store the value.
if ( tlv.getLength() == 0 )
{
// We can't have a void parameter type !
String msg = I18n.err( I18n.ERR_08209_NULL_PARAMETER_TYPE );
LOG.error( msg );
throw new DecoderException( msg );
}
else
{
StoredProcedureParameter parameter = new StoredProcedureParameter();
byte[] parameterType = tlv.getValue().getData();
parameter.setType( parameterType );
// We store the type in the current parameter.
container.setCurrentParameter( parameter );
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.msg( I18n.MSG_08210_PARAMETER_TYPE_FOUND, Strings.dumpBytes( parameterType ) ) );
}
}
}
},
FollowUp.MANDATORY );
// Parameter ::= {
// ...
// value OCTETSTRING (Tag)
// }
// Store the parameter value
super.transitions[StoredProcedureStatesEnum.PARAMETER_TYPE_STATE.ordinal()][UniversalTag.OCTET_STRING
.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.PARAMETER_TYPE_STATE,
StoredProcedureStatesEnum.PARAMETER_VALUE_STATE,
UniversalTag.OCTET_STRING.getValue(),
new GrammarAction<StoredProcedureRequestContainer>( "Store parameter value" )
{
public void action( StoredProcedureRequestContainer container ) throws DecoderException
{
TLV tlv = container.getCurrentTLV();
StoredProcedureRequest storedProcedure = container.getStoredProcedure();
// Store the value.
if ( tlv.getLength() == 0 )
{
// We can't have a void parameter value !
String msg = I18n.err( I18n.ERR_08210_NULL_PARAMETER_VALUE );
LOG.error( msg );
throw new DecoderException( msg );
}
else
{
byte[] parameterValue = tlv.getValue().getData();
if ( parameterValue.length != 0 )
{
StoredProcedureParameter parameter = container.getCurrentParameter();
parameter.setValue( parameterValue );
// We can now add a new Parameter to the procedure
storedProcedure.addParameter( parameter );
if ( LOG.isDebugEnabled() )
{
LOG.debug( I18n.msg( I18n.MSG_08211_PARAMETER_VALUE_FOUND, Strings.dumpBytes( parameterValue ) ) );
}
}
else
{
String msg = I18n.err( I18n.ERR_08211_EMPTY_PARAMETER_VALUE );
LOG.error( msg );
throw new DecoderException( msg );
}
}
// The only possible END state for the grammar is here
container.setGrammarEndAllowed( true );
}
},
FollowUp.OPTIONAL );
// Parameters ::= SEQUENCE OF Parameter
//
// Loop on next parameter
super.transitions[StoredProcedureStatesEnum.PARAMETER_VALUE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
new GrammarTransition<StoredProcedureRequestContainer>(
StoredProcedureStatesEnum.PARAMETER_VALUE_STATE,
StoredProcedureStatesEnum.PARAMETER_STATE,
UniversalTag.SEQUENCE.getValue(),
null,
FollowUp.OPTIONAL );
}