directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r178097 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java
Date Tue, 24 May 2005 06:34:52 GMT
Author: elecharny
Date: Mon May 23 23:34:52 2005
New Revision: 178097

URL: http://svn.apache.org/viewcvs?rev=178097&view=rev
Log:
Added the UnbindRequest grammar

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java?rev=178097&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/UnBindRequestGrammar.java
Mon May 23 23:34:52 2005
@@ -0,0 +1,129 @@
+/*
+ *   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.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.UnBindRequestPOJO;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the LdapMessage. 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 UnBindRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( UnBindRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. UnBindRequestGrammar is a singleton */
+    private static IGrammar instance = new UnBindRequestGrammar();
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the UnBindRequest Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new LdapMessageGrammar object.
+     */
+    private UnBindRequestGrammar()
+    {
+
+        name = UnBindRequestGrammar.class.getName();
+        
+        statesEnum = LdapStatesEnum.getInstance();
+
+        // We have 3 differents states, so 2 transitions between states.
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_UNBIND_REQUEST_STATE][256];
+
+        //============================================================================================
+        // protocolOp : UnBind Request
+        //============================================================================================
+        // We have to allocate a UnBindRequestPOJO
+        // LdapMessage ::= ... UnBindRequest ...
+        // UnbindRequest ::= [APPLICATION 2] NULL (Length)
+        super.transitions[LdapStatesEnum.UNBIND_REQUEST_TAG][0x42]    = new GrammarTransition(
+                LdapStatesEnum.UNBIND_REQUEST_TAG, LdapStatesEnum.UNBIND_REQUEST_LENGTH,
null );
+
+        // LdapMessage ::= ... UnBindRequest ...
+        // UnbindRequest ::= [APPLICATION 2] NULL (Value)
+        // We have to check that the length is null (the Value is empty). This is the end
of this grammar.
+        super.transitions[LdapStatesEnum.UNBIND_REQUEST_LENGTH][0x42] = new GrammarTransition(
+                LdapStatesEnum.UNBIND_REQUEST_LENGTH, LdapStatesEnum.GRAMMAR_END,
+                new GrammarAction( "Init UnBindRequest" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessagePOJO      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        checkLength( ldapMessage, ldapMessageContainer.getCurrentTLV() );
+
+                        // Now, we can allocate the UnBindRequest POJO
+                        UnBindRequestPOJO unBindRequest = new UnBindRequestPOJO();
+
+                        // As this is a new Constructed object, we have to init its length
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+                        int expectedLength = tlv.getLength().getLength();
+                        
+                        // If the length is not null, this is an error.
+                        if (expectedLength != 0)
+                        {
+                            throw new DecoderException("The length of a UnBindRequest must
be null");
+                        }
+
+                        unBindRequest.setExpectedLength( expectedLength );
+                        unBindRequest.setCurrentLength( 0 );
+                        unBindRequest.setFather( ldapMessage );
+
+                        // And we associate it to the ldapMessage POJO
+                        ldapMessage.setProtocolOP( unBindRequest );
+                    }
+                } );
+    }
+}



Mime
View raw message