You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/06/06 00:51:59 UTC
svn commit: r180166 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
Author: elecharny
Date: Sun Jun 5 15:51:59 2005
New Revision: 180166
URL: http://svn.apache.org/viewcvs?rev=180166&view=rev
Log:
Refactored with Jalopy
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java?rev=180166&r1=180165&r2=180166&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapMessageGrammar.java Sun Jun 5 15:51:59 2005
@@ -52,105 +52,113 @@
/** The instance of grammar. LdapMessageGrammar is a singleton */
private static IGrammar instance = new LdapMessageGrammar();
- /**
- * Get the instance of this grammar
- *
- * @return An instance on the LdapMessage Grammar
- */
- public static IGrammar getInstance()
- {
- return instance;
- }
-
//~ Constructors -------------------------------------------------------------------------------
+
/**
* Creates a new LdapMessageGrammar object.
*/
private LdapMessageGrammar()
{
- name = LdapMessageGrammar.class.getName();
+ name = LdapMessageGrammar.class.getName();
statesEnum = LdapStatesEnum.getInstance();
// We have 9 differents states, so 8 transitions between states.
super.transitions = new GrammarTransition[LdapStatesEnum.LAST_LDAP_MESSAGE_STATE][256];
//============================================================================================
- // LdapMessage
+ // LdapMessage
//============================================================================================
// LDAPMessage --> SEQUENCE { ... (Tag)
// We have a LDAPMessage, and the tag must be 0x30
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_TAG][0x30] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_TAG,
- LdapStatesEnum.LDAP_MESSAGE_LENGTH, new GrammarAction( "LdapMessage Tag" )
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_TAG][0x30] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_TAG, LdapStatesEnum.LDAP_MESSAGE_LENGTH,
+ new GrammarAction( "LdapMessage Tag" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
// First, create a empty LdapMessage POJO
- LdapMessagePOJO ldapMessage = new LdapMessagePOJO();
+ LdapMessagePOJO ldapMessage = new LdapMessagePOJO();
// Then stores it into the container
- ldapMessageContainer.setLdapMessage(ldapMessage);
-
+ ldapMessageContainer.setLdapMessage( ldapMessage );
+
return;
}
} );
// LDAPMessage --> SEQUENCE { ... (Length)
// Ok, get the LdapMessage length
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_LENGTH][0x30] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_LENGTH,
- LdapStatesEnum.LDAP_MESSAGE_VALUE, new GrammarAction( "LdapMessage Length" )
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_LENGTH][0x30] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_LENGTH, LdapStatesEnum.LDAP_MESSAGE_VALUE,
+ new GrammarAction( "LdapMessage Length" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- // We have to store the expected Length of the PDU
- LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
- LdapMessagePOJO ldapMessage = ldapMessageContainer.getLdapMessage();
- ldapMessage.setExpectedLength(ldapMessageContainer.getCurrentTLV().getLength().getLength());
- ldapMessage.setCurrentLength(0);
+ // We have to store the expected Length of the PDU
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessagePOJO ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+
+ ldapMessage.setExpectedLength( ldapMessageContainer.getCurrentTLV()
+ .getLength().getLength() );
+ ldapMessage.setCurrentLength( 0 );
- return;
+ return;
}
} );
-
+
// LDAPMessage --> SEQUENCE { ... (Value)
// Nothing to do, it's a constructed TLV. It's just a phantom transition ...
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_VALUE][0x30] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_VALUE, LdapStatesEnum.LDAP_MESSAGE_ID_TAG, null);
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_VALUE][0x30] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_VALUE, LdapStatesEnum.LDAP_MESSAGE_ID_TAG, null );
//--------------------------------------------------------------------------------------------
- // LdapMessage Message ID
+ // LdapMessage Message ID
//--------------------------------------------------------------------------------------------
// LDAPMessage --> ... MessageId ...(Tag)
// The tag must be 0x02. Nothing special to do.
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_TAG][0x02] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_ID_TAG, LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH, null);
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_TAG][0x02] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_ID_TAG, LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH, null );
// LDAPMessage --> ... MessageId ...(Length)
// Checks the length
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH, LdapStatesEnum.LDAP_MESSAGE_ID_VALUE,
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH][0x02] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_ID_LENGTH, LdapStatesEnum.LDAP_MESSAGE_ID_VALUE,
new GrammarAction( "Check MessageId Length " )
{
public void action( IAsn1Container container ) throws DecoderException
{
- LdapMessageContainer ldapMessageContainer = ((LdapMessageContainer)container);
- checkLength(ldapMessageContainer.getLdapMessage(), ldapMessageContainer.getCurrentTLV());
+
+ LdapMessageContainer ldapMessageContainer = ( ( LdapMessageContainer )
+ container );
+ checkLength( ldapMessageContainer.getLdapMessage(),
+ ldapMessageContainer.getCurrentTLV() );
return;
}
} );
-
+
// LDAPMessage --> ... MessageId ...(Value)
// Checks that MessageId is in [0 .. 2147483647] and store the value in the LdapMessage POJO
// (2147483647 = Integer.MAX_VALUE)
- super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] = new GrammarTransition( LdapStatesEnum.LDAP_MESSAGE_ID_VALUE, LdapStatesEnum.PROTOCOL_OP_TAG,
+ super.transitions[LdapStatesEnum.LDAP_MESSAGE_ID_VALUE][0x02] = new GrammarTransition(
+ LdapStatesEnum.LDAP_MESSAGE_ID_VALUE, LdapStatesEnum.PROTOCOL_OP_TAG,
new GrammarAction( "Store MessageId" )
{
public void action( IAsn1Container container ) throws DecoderException
{
- LdapMessageContainer ldapMessageContainer = (LdapMessageContainer)container;
- LdapMessagePOJO ldapMessage = ldapMessageContainer.getLdapMessage();
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessagePOJO ldapMessage =
+ ldapMessageContainer.getLdapMessage();
// The current TLV should be a integer
// We get it and store it in MessageId
@@ -158,40 +166,37 @@
Value value = tlv.getValue();
- int messageId = IntegerDecoder.parse( value , 0, Integer.MAX_VALUE);
+ int messageId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );
- if ( ( messageId < 0 ) || ( messageId > Integer.MAX_VALUE ) )
- {
- throw new DecoderException(
- "The message ID must be between (0 .. 2 147 483 647)" );
- }
- else
- {
- ldapMessage.setMessageId( messageId );
-
- return;
- }
+ ldapMessage.setMessageId( messageId );
+
+ return;
}
} );
//********************************************************************************************
- // If the Tag is 0x42, then it's a UnBindRequest.
- // If the Tag is 0x50, then it's an AbandonRequest.
+ // If the Tag is 0x42, then it's a UnBindRequest.
+ // If the Tag is 0x50, then it's an AbandonRequest.
// If the Tag is 0x60, then it's a BindRequest. Nothing to do while the length is not checked.
- // If the Tag is 0x61, then it's a BindResponse.
- // If the Tag is 0x67, then it's a ModifyResponse.
- // If the Tag is 0x69, then it's a AddResponse.
- // If the Tag is 0x6B, then it's a DelResponse.
- // If the Tag is 0x6F, then it's a CompareResponse.
+ // If the Tag is 0x61, then it's a BindResponse.
+ // If the Tag is 0x63, then it's a SearchRequest.
+ // If the Tag is 0x65, then it's a SearchResultDone
+ // If the Tag is 0x67, then it's a ModifyResponse.
+ // If the Tag is 0x69, then it's an AddResponse.
+ // If the Tag is 0x6B, then it's a DelResponse.
+ // If the Tag is 0x6D, then it's a ModifyDNResponse.
+ // If the Tag is 0x6F, then it's a CompareResponse.
//********************************************************************************************
-
+
//--------------------------------------------------------------------------------------------
// UnBindRequest Message.
//--------------------------------------------------------------------------------------------
// LdapMessage ::= ... UnBindRequest ...
// unbindRequest ::= [APPLICATION 2] NULL (Tag)
// We have to switch to the UnBindRequest grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x42] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.UNBIND_REQUEST_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x42] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.UNBIND_REQUEST_GRAMMAR_SWITCH,
+ null );
//--------------------------------------------------------------------------------------------
// AbandonRequest Message.
@@ -199,7 +204,9 @@
// LdapMessage ::= ... AbandonRequest ...
// AbandonRequest ::= [APPLICATION 16] MessageID (Tag)
// We have to switch to the AbandonRequest grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x50] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ABANDON_REQUEST_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x50] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ABANDON_REQUEST_GRAMMAR_SWITCH,
+ null );
//--------------------------------------------------------------------------------------------
// BindRequest Message.
@@ -207,7 +214,8 @@
// LdapMessage ::= ... BindRequest ...
// BindRequest ::= [APPLICATION 0] SEQUENCE { ... (Tag)
// Nothing to do while the length is not checked.
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x60] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_REQUEST_GRAMMAR_SWITCH, null );
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x60] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_REQUEST_GRAMMAR_SWITCH, null );
//--------------------------------------------------------------------------------------------
// BindResponse Message.
@@ -215,7 +223,27 @@
// LdapMessage ::= ... BindResponse ...
// BindResponse ::= [APPLICATION 1] SEQUENCE { ... (Tag)
// We have to switch to the BindResponse grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x61] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_RESPONSE_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x61] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.BIND_RESPONSE_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchRequest Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchRequest ...
+ // SearchRequest ::= [APPLICATION 3] SEQUENCE { ... (Tag)
+ // Nothing to do while the length is not checked.
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x63] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_REQUEST_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // SearchResultDone Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... SearchResultDone ...
+ // SearchResultDone ::= [APPLICATION 5] SEQUENCE { ... (Tag)
+ // We have to switch to the SearchResultDone grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x65] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.SEARCH_RESULT_DONE_GRAMMAR_SWITCH,
+ null );
//--------------------------------------------------------------------------------------------
// ModifydResponse Message.
@@ -223,7 +251,9 @@
// LdapMessage ::= ... ModifyResponse ...
// ModifyResponse ::= [APPLICATION 7] SEQUENCE { ... (Tag)
// We have to switch to the ModifyResponse grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x67] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_RESPONSE_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x67] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_RESPONSE_GRAMMAR_SWITCH,
+ null );
//--------------------------------------------------------------------------------------------
// AddResponse Message.
@@ -231,7 +261,8 @@
// LdapMessage ::= ... AddResponse ...
// AddResponse ::= [APPLICATION 9] LDAPResult (Tag)
// We have to switch to the AddResponse grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x69] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ADD_RESPONSE_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x69] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.ADD_RESPONSE_GRAMMAR_SWITCH, null );
//--------------------------------------------------------------------------------------------
// DelResponse Message.
@@ -239,7 +270,18 @@
// LdapMessage ::= ... DelResponse ...
// DelResponse ::= [APPLICATION 11] LDAPResult (Tag)
// We have to switch to the DelResponse grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x6B] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.DEL_RESPONSE_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x6B] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.DEL_RESPONSE_GRAMMAR_SWITCH, null );
+
+ //--------------------------------------------------------------------------------------------
+ // ModifydResponse Message.
+ //--------------------------------------------------------------------------------------------
+ // LdapMessage ::= ... ModifyDNResponse ...
+ // ModifyDNResponse ::= [APPLICATION 13] SEQUENCE { ... (Tag)
+ // We have to switch to the ModifyDNResponse grammar
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x6D] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.MODIFY_DN_RESPONSE_GRAMMAR_SWITCH,
+ null );
//--------------------------------------------------------------------------------------------
// CompareResponse Message.
@@ -247,7 +289,21 @@
// LdapMessage ::= ... CompareResponse ...
// CompareResponse ::= [APPLICATION 15] LDAPResult (Tag)
// We have to switch to the CompareResponse grammar
- super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x6F] = new GrammarTransition( LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.COMPARE_RESPONSE_GRAMMAR_SWITCH, null);
+ super.transitions[LdapStatesEnum.PROTOCOL_OP_TAG][0x6F] = new GrammarTransition(
+ LdapStatesEnum.PROTOCOL_OP_TAG, LdapStatesEnum.COMPARE_RESPONSE_GRAMMAR_SWITCH,
+ null );
+
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the LdapMessage Grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
}
}