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/04/23 09:35:39 UTC

svn commit: r164349 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapStatesEnum.java

Author: elecharny
Date: Sat Apr 23 00:35:39 2005
New Revision: 164349

URL: http://svn.apache.org/viewcvs?rev=164349&view=rev
Log:
Added this ldap specialization class of the StatesEnum class

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

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapStatesEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapStatesEnum.java?rev=164349&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapStatesEnum.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/LdapStatesEnum.java Sat Apr 23 00:35:39 2005
@@ -0,0 +1,462 @@
+/*
+ *   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.ber.grammar.IStates;
+
+
+/**
+ * This class store the Ldap grammar's constants.
+ * It is also used for debugging purpose
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapStatesEnum implements IStates
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    // LdapMessage ------------------------------------------------------------
+    /** Initiate the counter to 0 */
+    private static int LDAP_MESSAGE_STATE = 0;
+
+    /** LDAPMessage Tag */
+
+    public static int LDAP_MESSAGE_TAG = 0;
+
+    /** LDAPMessage Length */
+    public static int LDAP_MESSAGE_LENGTH = 1;
+
+    /** LDAPMessage Value */
+    public static int LDAP_MESSAGE_VALUE = 2;
+
+    // Message ID -------------------------------------------------------------
+    /** MessageID Tag */
+    public static int LDAP_MESSAGE_ID_TAG = 3;
+
+    /** MessageID Length */
+    public static int LDAP_MESSAGE_ID_LENGTH = 4;
+
+    /** MessageID Value */
+    public static int LDAP_MESSAGE_ID_VALUE = 5;
+
+    // ProtocolOp -------------------------------------------------------------
+    /** protocolOp CHOICE Tag */
+    public static int PROTOCOL_OP_TAG = 6;
+
+    /** protocolOp CHOICE Length */
+    public static int PROTOCOL_OP_LENGTH = 7;
+
+    /** protocolOp CHOICE Value */
+    public static int PROTOCOL_OP_VALUE = 8;
+    
+    public static int LAST_LDAP_MESSAGE_STATE = 9;
+    
+    
+
+    // BindRequest ============================================================
+    // Version ----------------------------------------------------------------
+    private static int BIND_REQUEST_STATE = 0;
+
+    /** The BindRequest Tag */
+    public static int BIND_REQUEST_TAG = 0;
+    
+    /** BIND_REQUEST Length */
+    public static int BIND_REQUEST_LENGTH = 1;
+    
+    /** The BindRequest Value */
+    public static int BIND_REQUEST_VALUE = 2;
+
+    /**  Version Tag */
+    public static int BIND_REQUEST_VERSION_TAG = 3;
+
+    /** Version Length */
+    public static int BIND_REQUEST_VERSION_LENGTH = 4;
+
+    /** Version Length */
+    public static int BIND_REQUEST_VERSION_VALUE = 5;
+
+    // Name -------------------------------------------------------------------
+    /** Name Tag */
+    public static int BIND_REQUEST_NAME_TAG = 6;
+
+    /** Name Length */
+    public static int BIND_REQUEST_NAME_LENGTH = 7;
+
+    /** Name Value */
+    public static int BIND_REQUEST_NAME_VALUE = 8;
+
+    // Authentication choice --------------------------------------------------
+    /** Authentication choice Tag */
+    public static int BIND_REQUEST_AUTHENTICATION_CHOICE_TAG = 9;
+
+    // Authentication simple --------------------------------------------------
+    /** Authentication Simple Tag */
+    //public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_TAG = BIND_REQUEST_STATE++;
+
+    /** Authentication Simple Length */
+    public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH = 10;
+
+    /** Authentication Simple Value */
+    public static int BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE = 11;
+
+    // Authentication sasl ----------------------------------------------------
+    /** Authentication Sasl Tag */
+    //public static int BIND_AUTHENTICATION_SASL_TAG = INIT_STATE++;
+
+    /** Authentication Sasl Length */
+    public static int BIND_REQUEST_AUTHENTICATION_SASL_LENGTH = 12;
+
+    /** Authentication Sasl Value */
+    public static int BIND_REQUEST_AUTHENTICATION_SASL_VALUE = 13;
+
+    // Authentication sasl mechanism ------------------------------------------
+    /** Authentication Sasl mechanism Tag */
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_TAG = 14;
+
+    /** Authentication sasl mechanism Length */
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH = 15;
+
+    /** Authentication sasl mechanism Value */
+    public static int BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE = 16;
+
+    // Authentication sasl mechanism ------------------------------------------
+    /** Authentication Sasl credentials Tag */
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG = 17;
+
+    /** Authentication sasl credentials Length */
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH = 18;
+
+    /** Authentication sasl credentials Value */
+    public static int BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE = 19;
+
+    public static int LAST_BIND_REQUEST_STATE = 20;
+
+    
+    // Controls ===============================================================
+    private static int LDAP_CONTROL_STATE = 0;
+    
+    /** Controls Tag */
+    public static int CONTROLS_TAG = 1;
+
+    /** Controls Length */
+    public static int CONTROLS_LENGTH = 2;
+
+    /** Controls Value */
+    public static int CONTROLS_VALUE = 3;
+
+    // Control ----------------------------------------------------------------
+    /** Control Tag */
+    public static int CONTROL_TAG = 4;
+
+    /** Control Length */
+    public static int CONTROL_LENGTH = 5;
+
+    /** Control Value */
+    public static int CONTROL_VALUE = 6;
+
+    // Control controltype ----------------------------------------------------
+    /** Control type Tag */
+    public static int CONTROL_TYPE_TAG = 7;
+
+    /** Control type Length */
+    public static int CONTROL_TYPE_LENGTH = 8;
+
+    /** Control type Value */
+    public static int CONTROL_TYPE_VALUE = 9;
+
+    // Control criticality ----------------------------------------------------
+    /** Control criticality Tag */
+    public static int CONTROL_CRITICALITY_TAG = 10;
+
+    /** Control criticality Length */
+    public static int CONTROL_CRITICALITY_LENGTH = 11;
+
+    /** Control criticality Value */
+    public static int CONTROL_CRITICALITY_VALUE = 12;
+
+    // Control controlvalue ---------------------------------------------------
+    /** Control value Tag */
+    public static int CONTROL_VALUE_TAG = 13;
+
+    /** Control value Length */
+    public static int CONTROL_VALUE_LENGTH = 14;
+
+    /** Control value Value */
+    public static int CONTROL_VALUE_VALUE = 15;
+    
+    /** Control last state */
+    public static int CONTROL_LAST_STATE = 16;
+
+    // BindResponse ===========================================================
+    // Version ----------------------------------------------------------------
+    private static int BIND_RESPONSE_STATE = 0;
+
+    /**  Response Tag */
+    public static int BIND_RESPONSE_TAG = 0;
+
+    /**  Response Length */
+    public static int BIND_RESPONSE_LENGTH = 1;
+
+    /**  Response Value */
+    public static int BIND_RESPONSE_VALUE = 2;
+
+    /**  Response Ldap Result */
+    public static int BIND_RESPONSE_LDAP_RESULT = 3;
+
+    /**  Response message ID Tag */
+    public static int BIND_RESPONSE_MESSAGE_ID_TAG = 4;
+
+    /** serverSaslCreds Tag */
+    public static int BIND_RESPONSE_SERVER_SASL_CREDS_TAG = 5;
+
+    /** serverSaslCreds Length */
+    public static int BIND_RESPONSE_SERVER_SASL_CREDS_LENGTH = 6;
+
+    /** serverSaslCreds Length */
+    public static int BIND_RESPONSE_SERVER_SASL_CREDS_VALUE = 7;
+
+    /** Last state */
+    public static int LAST_LDAP_STATE = 8; 
+    
+    
+    // LdapResult grammar states ==============================================
+    private static int LDAP_RESULT_STATE = 0;
+    
+    // LdapResult Code --------------------------------------------------------
+    /** LdapResult Code Tag */
+    public static int LDAP_RESULT_CODE_TAG = 0;
+
+    /** LdapResult Code Length */
+    public static int LDAP_RESULT_CODE_LENGTH = 1;
+
+    /** LdapResult Code Value */
+    public static int LDAP_RESULT_CODE_VALUE = 2;
+
+    // LdapResult Matched DN --------------------------------------------------
+    /** LdapResult Matched DN Tag */
+    public static int LDAP_RESULT_MATCHED_DN_TAG = 3;
+
+    /** LdapResult Matched DN Length */
+    public static int LDAP_RESULT_MATCHED_DN_LENGTH = 4;
+
+    /** LdapResult Matched DN Value */
+    public static int LDAP_RESULT_MATCHED_DN_VALUE = 5;
+
+    // LdapResult error message -----------------------------------------------
+    /** LdapResult error message Tag */
+    public static int LDAP_RESULT_ERROR_MESSAGE_TAG = 6;
+
+    /** LdapResult error message Length */
+    public static int LDAP_RESULT_ERROR_MESSAGE_LENGTH = 7;
+
+    /** LdapResult error message Value */
+    public static int LDAP_RESULT_ERROR_MESSAGE_VALUE = 8;
+
+    // LdapResult referral sequence -------------------------------------------
+    /** LdapResult referral sequence Tag */
+    public static int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = 9;
+
+    /** LdapResult referral sequence Length */
+    public static int LDAP_RESULT_REFERRAL_SEQUENCE_LENGTH = 10;
+
+    // LdapResult referrale ---------------------------------------------------
+    /** LdapResult referral Tag */
+    public static int LDAP_RESULT_REFERRAL_TAG = 11;
+
+    /** LdapResult referral Length */
+    public static int LDAP_RESULT_REFERRAL_LENGTH = 12;
+
+    /** LdapResult referral Value */
+    public static int LDAP_RESULT_REFERRAL_VALUE = 13;
+    
+    /** LdapResult referral Tag loop */
+    public static int LDAP_RESULT_REFERRAL_LOOP_TAG = 14;
+
+    /** The last state */
+    public static int LDAP_RESULT_LAST_STATE = 15;
+
+    /** Ldap Message Grammar */
+    public static final int LDAP_MESSAGE_GRAMMAR_SWITCH = 0x0100;
+
+    /** LdapMessage grammar number */
+    public static final int LDAP_MESSAGE_GRAMMAR = 0;
+
+    /** Ldap Result Grammar */
+    public static final int LDAP_RESULT_GRAMMAR_SWITCH = 0x0200;
+
+    /** LdapResult grammar number */
+    public static final int LDAP_RESULT_GRAMMAR = 1;
+
+    /** Ldap Control Grammar */
+    public static final int LDAP_CONTROL_GRAMMAR_SWITCH = 0x0300;
+
+    /** LdapControl grammar number */
+    public static final int LDAP_CONTROL_GRAMMAR = 2;
+
+    /** Bind Request  Grammar */
+    public static final int BIND_REQUEST_GRAMMAR_SWITCH = 0x0400;
+
+    /** BindRequest grammar number */
+    public static final int BIND_REQUEST_GRAMMAR = 3;
+
+    /** BindResponse Grammar */
+    public static final int BIND_RESPONSE_GRAMMAR_SWITCH = 0x0500;
+
+    /** BindResponse number */
+    public static final int BIND_RESPONSE_GRAMMAR = 4;
+
+    /** A string representation of grammars */
+    private static String[] GrammarSwitchString =
+        new String[]
+        {
+            "LDAP_MESSAGE_GRAMMAR_SWITCH", "LDAP_RESULT_GRAMMAR_SWITCH",
+            "LDAP_CONTROL_GRAMMAR_SWITCH", "BIND_REQUEST_GRAMMAR_SWITCH",
+            "BIND_RESPONSE_GRAMMAR_SWITCH"
+        };
+
+    /** A string representation of all the states */
+    private static String[] LdapMessageString =
+        new String[]
+        {
+            "LDAP_MESSAGE_TAG", "LDAP_MESSAGE_LENGTH", "LDAP_MESSAGE_VALUE", "LDAP_MESSAGE_ID_TAG",
+            "LDAP_MESSAGE_ID_LENGTH", "LDAP_MESSAGE_ID_VALUE", "PROTOCOL_OP_TAG",
+            "PROTOCOL_OP_LENGTH", "PROTOCOL_OP_VALUE"
+        };
+
+    /** A string representation of all the LdapResult states */
+    private static String[] LdapResultString =
+        new String[]
+        {
+            "LDAP_RESULT_CODE_TAG", "LDAP_RESULT_CODE_LENGTH", "LDAP_RESULT_CODE_VALUE",
+            "LDAP_RESULT_MATCHED_DN_TAG", "LDAP_RESULT_MATCHED_DN_LENGTH",
+            "LDAP_RESULT_MATCHED_DN_VALUE", "LDAP_RESULT_ERROR_MESSAGE_TAG",
+            "LDAP_RESULT_ERROR_MESSAGE_LENGTH", "LDAP_RESULT_ERROR_MESSAGE_VALUE",
+            "LDAP_RESULT_REFERRAL_SEQUENCE_TAG", "LDAP_RESULT_REFERRAL_SEQUENCE_LENGTH",
+            "LDAP_RESULT_REFERRAL_TAG", "LDAP_RESULT_REFERRAL_LENGTH",
+            "LDAP_RESULT_REFERRAL_VALUE", "LAST_STATE"
+        };
+
+    /** A string representation of all the controls states */
+    private static String[] LdapControlString =
+        new String[]
+        {
+            "CONTROLS_TAG", "CONTROLS_LENGTH", "CONTROLS_VALUE", "CONTROL_TAG", "CONTROL_LENGTH",
+            "CONTROL_VALUE", "CONTROL_TYPE_TAG", "CONTROL_TYPE_LENGTH", "CONTROL_TYPE_VALUE",
+            "CONTROL_CRITICALITY_TAG", "CONTROL_CRITICALITY_LENGTH", "CONTROL_CRITICALITY_VALUE",
+            "CONTROL_VALUE_TAG", "CONTROL_VALUE_LENGTH", "CONTROL_VALUE_VALUE"
+        };
+
+    /** A string representation of all the Bind Request states */
+    private static String[] BindRequestString =
+        new String[]
+        {
+            "BIND_REQUEST_TAG", "BIND_REQUEST_LENGTH", "BIND_REQUEST_VALUE",
+            "BIND_REQUEST_VERSION_TAG", "BIND_REQUEST_VERSION_LENGTH",
+            "BIND_REQUEST_VERSION_VALUE", "BIND_REQUEST_NAME_TAG", "BIND_REQUEST_NAME_LENGTH",
+            "BIND_REQUEST_NAME_VALUE", "BIND_REQUEST_AUTHENTICATION_CHOICE_TAG",
+
+            //public static int BIND_AUTHENTICATION_SIMPLE_TAG",
+            "BIND_REQUEST_AUTHENTICATION_SIMPLE_LENGTH",
+            "BIND_REQUEST_AUTHENTICATION_SIMPLE_VALUE",
+            //public static int BIND_AUTHENTICATION_SASL_TAG",
+            "BIND_REQUEST_AUTHENTICATION_SASL_LENGTH", "BIND_REQUEST_AUTHENTICATION_SASL_VALUE",
+            "BIND_REQUEST_AUTHENTICATION_MECHANISM_TAG",
+            "BIND_REQUEST_AUTHENTICATION_MECHANISM_LENGTH",
+            "BIND_REQUEST_AUTHENTICATION_MECHANISM_VALUE",
+            "BIND_REQUEST_AUTHENTICATION_CREDENTIALS_TAG",
+            "BIND_REQUEST_AUTHENTICATION_CREDENTIALS_LENGTH",
+            "BIND_REQUEST_AUTHENTICATION_CREDENTIALS_VALUE",
+        };
+
+    /** A string representation of all the BindResponse states */
+    private static String[] BindResponseString =
+        new String[]
+        {
+            "BIND_RESPONSE_TAG", "BIND_RESPONSE_LENGTH", "BIND_RESPONSE_VALUE",
+            "BIND_RESPONSE_MESSAGE_ID_TAG", "SERVER_SASL_CREDS_TAG", "SERVER_SASL_CREDS_LENGTH",
+            "SERVER_SASL_CREDS_VALUE", "LAST_STATE"
+        };
+
+    //~ Instance fields ----------------------------------------------------------------------------
+
+    /** The instance */
+    private static LdapStatesEnum instance = new LdapStatesEnum();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * This is a private constructor. This class is a singleton
+     *
+     */
+    private LdapStatesEnum()
+    {
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get an instance of this class
+     * @return An instance on this class
+     */
+    public static IStates getInstance()
+    {
+        return instance;
+    }
+
+    /**
+     * Get the string representing the state
+     * 
+     * @param grammar DOCUMENT ME!
+     * @param state The state number
+     * @return The String representing the state
+     */
+    public String getState( int grammar, int state )
+    {
+
+        if ( ( state & GRAMMAR_SWITCH_MASK ) != 0 )
+        {
+            return ( state == -1 ) ? "END_STATE"
+                : GrammarSwitchString[( ( state & GRAMMAR_SWITCH_MASK ) >> 8 ) - 1];
+        }
+        else
+        {
+
+            switch ( grammar )
+            {
+
+                case LDAP_MESSAGE_GRAMMAR :
+                    return ( ( state == -1 ) ? "END_STATE" : LdapMessageString[state] );
+
+                case LDAP_RESULT_GRAMMAR :
+                    return ( ( state == -1 ) ? "END_STATE" : LdapResultString[state] );
+
+                case LDAP_CONTROL_GRAMMAR :
+                    return ( ( state == -1 ) ? "END_STATE" : LdapControlString[state] );
+
+                case BIND_REQUEST_GRAMMAR :
+                    return ( ( state == -1 ) ? "END_STATE" : BindRequestString[state] );
+
+                case BIND_RESPONSE_GRAMMAR :
+                    return ( ( state == -1 ) ? "END_STATE" : BindResponseString[state] );
+
+                default :
+                    return "UNKNOWN";
+            }
+        }
+    }
+}