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/05/29 01:08:34 UTC
svn commit: r178898 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java
Author: elecharny
Date: Sat May 28 16:08:34 2005
New Revision: 178898
URL: http://svn.apache.org/viewcvs?rev=178898&view=rev
Log:
Added the AbandonRequest grammar
Added:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java
Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java?rev=178898&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AbandonRequestGrammar.java Sat May 28 16:08:34 2005
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec.grammars;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.utils.IntegerDecoder;
+import org.apache.asn1.ldap.pojo.AbandonRequestPOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the abandon request. All the actions are declared in this
+ * class. As it is a singleton, these declaration are only done once.
+ *
+ * If an action is to be added or modified, this is where the work is to be done !
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbandonRequestGrammar extends AbstractGrammar implements IGrammar
+{
+ //~ Static fields/initializers -----------------------------------------------------------------
+
+ /** The logger */
+ private static final Logger log = Logger.getLogger( AbandonRequestGrammar.class );
+
+ /** Logging speed up */
+ private static final boolean DEBUG = log.isDebugEnabled();
+
+ /** The instance of grammar. AbandonRequestGrammar is a singleton */
+ private static IGrammar instance = new AbandonRequestGrammar();
+
+ //~ Constructors -------------------------------------------------------------------------------
+
+ /**
+ * Creates a new AbandonRequestGrammar object.
+ */
+ private AbandonRequestGrammar()
+ {
+
+ name = AbandonRequestGrammar.class.getName();
+
+ statesEnum = LdapStatesEnum.getInstance();
+
+ // We have 4 differents states, so 3 transitions between states.
+ super.transitions = new GrammarTransition[LdapStatesEnum.LAST_ABANDON_REQUEST_STATE][256];
+
+ //--------------------------------------------------------------------------------------------
+ // AbandonRequest Message ID
+ //--------------------------------------------------------------------------------------------
+ // AbandonRequest ::= [APPLICATION 16] MessageID (Tag)
+ // The tag must be 0x50. It codes for an integer, as we use
+ // IMPLICIT tags (we won't have a 0x02 tag to code the integer).
+ // Nothing special to do.
+ super.transitions[LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_TAG][0x50] =
+ new GrammarTransition( LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_TAG,
+ LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_LENGTH, null );
+
+ // AbandonRequest ::= [APPLICATION 16] MessageID (Length)
+ // Checks the length
+ super.transitions[LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_LENGTH][0x50] =
+ new GrammarTransition( LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_LENGTH,
+ LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE,
+ new GrammarAction( "Check MessageId Length " )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( ( LdapMessageContainer )
+ container );
+ checkLength( ldapMessageContainer.getLdapMessage(),
+ ldapMessageContainer.getCurrentTLV() );
+
+ return;
+ }
+ } );
+
+ // AbandonRequest ::= [APPLICATION 16] MessageID (Value)
+ // Checks that MessageId is in [0 .. 2147483647] and store the value in the AbandonRequest POJO
+ // (2147483647 = Integer.MAX_VALUE)
+ // This is the last state.
+ super.transitions[LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE][0x50] =
+ new GrammarTransition( LdapStatesEnum.ABANDON_REQUEST_MESSAGE_ID_VALUE,
+ LdapStatesEnum.GRAMMAR_END, new GrammarAction( "Store MessageId" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+
+ LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+ container;
+ LdapMessagePOJO ldapMessage =
+ ldapMessageContainer.getLdapMessage();
+
+ // The current TLV should be a integer
+ // We get it and store it in MessageId
+ TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+ Value value = tlv.getValue();
+
+ 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
+ {
+
+ // Ok, the Message ID is correct. We have to allocate an
+ // abandonRequest POJO to store the value, and store the
+ // POJO in the LDAPMessage
+ AbandonRequestPOJO abandonRequest = new AbandonRequestPOJO();
+ abandonRequest.setMessageId( messageId );
+ ldapMessage.setProtocolOP( abandonRequest );
+
+ return;
+ }
+ }
+ } );
+
+ }
+
+ //~ Methods ------------------------------------------------------------------------------------
+
+ /**
+ * Get the instance of this grammar
+ *
+ * @return An instance on the AbandonRequest Grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
+ }
+}