directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208997 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
Date Sun, 03 Jul 2005 22:32:39 GMT
Author: elecharny
Date: Sun Jul  3 15:32:36 2005
New Revision: 208997

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

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

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java?rev=208997&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedResponseGrammar.java
Sun Jul  3 15:32:36 2005
@@ -0,0 +1,204 @@
+/*
+ *   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.ExtendedResponse;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.primitives.OID;
+import org.apache.asn1.primitives.OctetString;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the ExtendedResponse LDAP message. 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 ExtendedResponseGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( ExtendedResponseGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. ExtendedResponseGrammar is a singleton */
+    private static IGrammar instance = new ExtendedResponseGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ExtendedResponseGrammar object.
+     */
+    private ExtendedResponseGrammar()
+    {
+        name              = ExtendedResponseGrammar.class.getName();
+        statesEnum        = LdapStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_EXTENDED_RESPONSE_STATE][256];
+
+        //============================================================================================
+        // ExtendedResponse
+        //============================================================================================
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_TAG][0x78] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_TAG,
+                LdapStatesEnum.EXTENDED_RESPONSE_VALUE, null );
+
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE { (Value)
+        // Initialize the compare request pojo
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_VALUE][0x78] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_VALUE, LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT,
+                new GrammarAction( "Init Extended Reponse" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ExtendedResponse Object
+                        ldapMessage.setProtocolOP( new ExtendedResponse() );
+                    }
+                } );
+
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+        //     COMPONENTS OF LDAPResult, (Tag)
+        //     ...
+        // The Tag will be the LDAPResult Tag (0x0A). So we have to switch the grammar.
+        // The current state will be stored.
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][0x0A] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT,
+                LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
+
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+        //     ...
+        //     responseName     [10] LDAPOID OPTIONAL, (Tag)
+        //     ...
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][0x8A] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT, LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE,
null
+                 );
+        
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+        //     ...
+        //     responseName     [10] LDAPOID OPTIONAL, (Value)
+        //     ...
+        // Store the response name.
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE][0x8A] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_NAME_VALUE, LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG,
+			        new GrammarAction( "Store name" )
+			        {
+			            public void action( IAsn1Container container ) throws DecoderException
+			            {
+			
+			                LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+			                    container;
+			                LdapMessage          ldapMessage          =
+			                    ldapMessageContainer.getLdapMessage();
+			
+			                // We can allocate the ExtendedResponse Object
+			                ExtendedResponse extendedResponse = ldapMessage.getExtendedResponse();
+			
+			                // Get the Value and store it in the ExtendedResponse
+			                TLV tlv = ldapMessageContainer.getCurrentTLV();
+			
+			                // We have to handle the special case of a 0 length matched OID
+			                if ( tlv.getLength().getLength() == 0 )
+			                {
+			                    throw new DecoderException( "The name must not be null" );
+			                }
+			                else
+			                {
+			                    extendedResponse.setName( new OID( tlv.getValue().getData() ) );
+			                }
+			            }
+			        } );
+
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+        //     ...
+        //     response         [11] OCTET STRING OPTIONAL } (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG][0x8B] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_TAG,
+                LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE, null );
+
+        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+        //     ...
+        //     response         [11] OCTET STRING OPTIONAL } (Value)
+        // Store the response
+        super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE][0x8B] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_RESPONSE_RESPONSE_VALUE, LdapStatesEnum.END_STATE,
+                new GrammarAction( "Store response" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ExtendedResponse Object
+                        ExtendedResponse extendedResponse = ldapMessage.getExtendedResponse();
+
+                        // Get the Value and store it in the ExtendedResponse
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched OID
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            extendedResponse.setResponse( OctetString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            extendedResponse.setResponse( new OctetString( tlv.getValue().getData()
) );
+                        }
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}



Mime
View raw message