001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.shared.ldap.codec;
021    
022    
023    import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
024    import org.apache.directory.shared.asn1.ber.grammar.IStates;
025    
026    
027    /**
028     * This class store the Ldap grammar's constants. It is also used for debugging
029     * purpose
030     * 
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev: 749713 $, $Date: 2009-03-03 20:49:17 +0100 (Tue, 03 Mar 2009) $, 
033     */
034    public class LdapStatesEnum implements IStates
035    {
036        // ~ Static fields/initializers
037        // -----------------------------------------------------------------
038        public static final int START_STATE =                       0;
039        public static final int LDAP_MESSAGE_STATE =                1;
040        public static final int MESSAGE_ID_STATE =                  2;
041        public static final int BIND_REQUEST_STATE =                3;
042        public static final int BIND_RESPONSE_STATE =               4;
043        public static final int UNBIND_REQUEST_STATE =              5;
044        public static final int SEARCH_REQUEST_STATE =              6;
045        public static final int SEARCH_RESULT_ENTRY_STATE =         7;
046        public static final int SEARCH_RESULT_DONE_STATE =          8;
047        public static final int SEARCH_RESULT_REFERENCE_STATE =     9;
048        public static final int MODIFY_REQUEST_STATE =              10;
049        public static final int MODIFY_RESPONSE_STATE =             11;
050        public static final int ADD_REQUEST_STATE =                 12;
051        public static final int ADD_RESPONSE_STATE =                13;
052        public static final int DEL_REQUEST_STATE =                 14;
053        public static final int DEL_RESPONSE_STATE =                15;
054        public static final int MODIFY_DN_REQUEST_STATE =           16;
055        public static final int MODIFY_DN_RESPONSE_STATE =          17;
056        public static final int COMPARE_REQUEST_STATE =             18;
057        public static final int COMPARE_RESPONSE_STATE =            19;
058        public static final int ABANDON_REQUEST_STATE =             20;
059        public static final int EXTENDED_REQUEST_STATE =            21;
060        public static final int EXTENDED_RESPONSE_STATE =           22;
061        public static final int VERSION_STATE =                     23;
062        public static final int NAME_STATE =                        24;
063        public static final int SIMPLE_STATE =                      25;
064        public static final int SASL_STATE =                        26;
065        public static final int MECHANISM_STATE =                   27;
066        public static final int CREDENTIALS_STATE =                 28;
067        public static final int RESULT_CODE_BR_STATE =              29;
068        public static final int MATCHED_DN_BR_STATE =               30;
069        public static final int ERROR_MESSAGE_BR_STATE =            31;
070        public static final int REFERRALS_BR_STATE =                32;
071        public static final int REFERRAL_BR_STATE =                 33;
072        public static final int SERVER_SASL_CREDENTIALS_STATE =     34;
073        public static final int RESULT_CODE_STATE =                 35;
074        public static final int MATCHED_DN_STATE =                  36;
075        public static final int ERROR_MESSAGE_STATE =               37;
076        public static final int REFERRALS_STATE =                   38;
077        public static final int REFERRAL_STATE =                    39;
078        public static final int REQUEST_NAME_STATE =                40;
079        public static final int REQUEST_VALUE_STATE =               41;
080        public static final int RESPONSE_NAME_STATE =               42;
081        public static final int RESPONSE_STATE =                    43;
082        public static final int RESULT_CODE_ER_STATE =              44;
083        public static final int MATCHED_DN_ER_STATE =               45;
084        public static final int ERROR_MESSAGE_ER_STATE =            46;
085        public static final int REFERRALS_ER_STATE =                47;
086        public static final int REFERRAL_ER_STATE =                 48;
087        public static final int ENTRY_STATE =                       49;
088        public static final int ATTRIBUTES_STATE =                  50;
089        public static final int ATTRIBUTE_STATE =                   51;
090        public static final int TYPE_STATE =                        52;
091        public static final int VALUES_STATE =                      53;
092        public static final int VALUE_STATE =                       54;
093        public static final int OBJECT_STATE =                      55;
094        public static final int MODIFICATIONS_STATE =               56;
095        public static final int MODIFICATIONS_SEQ_STATE =           57;
096        public static final int OPERATION_STATE =                   58;
097        public static final int MODIFICATION_STATE =                59;
098        public static final int TYPE_MOD_STATE =                    60;
099        public static final int VALS_STATE =                        61;
100        public static final int ATTRIBUTE_VALUE_STATE =             62;
101        public static final int ENTRY_MOD_DN_STATE =                63;
102        public static final int NEW_RDN_STATE =                     64;
103        public static final int DELETE_OLD_RDN_STATE =              65;
104        public static final int NEW_SUPERIOR_STATE =                66;
105        public static final int ENTRY_COMP_STATE =                  67;
106        public static final int AVA_STATE =                         68;
107        public static final int ATTRIBUTE_DESC_STATE =              69;
108        public static final int ASSERTION_VALUE_STATE =             70;
109        public static final int BASE_OBJECT_STATE =                 71;
110        public static final int SCOPE_STATE =                       72;
111        public static final int DEREF_ALIAS_STATE =                 73;
112        public static final int SIZE_LIMIT_STATE =                  74;
113        public static final int TIME_LIMIT_STATE =                  75;
114        public static final int TYPES_ONLY_STATE =                  76;
115        public static final int AND_STATE =                         77;
116        public static final int OR_STATE =                          78;
117        public static final int NOT_STATE =                         79;
118        public static final int EQUALITY_MATCH_STATE =              80;
119        public static final int SUBSTRING_FILTER_STATE =            81;
120        public static final int GREATER_OR_EQUAL_STATE =            82;
121        public static final int LESS_OR_EQUAL_STATE =               83;
122        public static final int PRESENT_STATE =                     84;
123        public static final int APPROX_MATCH_STATE =                85;
124        public static final int EXTENSIBLE_MATCH_STATE =            86;
125        public static final int ATTRIBUTE_DESC_FILTER_STATE =       87;
126        public static final int ASSERTION_VALUE_FILTER_STATE =      88;
127        public static final int ATTRIBUTE_DESCRIPTION_LIST_STATE =  89;
128        public static final int ATTRIBUTE_DESCRIPTION_STATE =       90;
129        public static final int TYPE_SUBSTRING_STATE =              91;
130        public static final int SUBSTRINGS_STATE =                  92;
131        public static final int INITIAL_STATE =                     93;
132        public static final int ANY_STATE =                         94;
133        public static final int FINAL_STATE =                       95;
134        public static final int MATCHING_RULE_STATE =               96;
135        public static final int TYPE_MATCHING_RULE_STATE =          97;
136        public static final int MATCH_VALUE_STATE =                 98;
137        public static final int DN_ATTRIBUTES_STATE =               99;
138        public static final int OBJECT_NAME_STATE =                 100;
139        public static final int ATTRIBUTES_SR_STATE =               101;
140        public static final int PARTIAL_ATTRIBUTES_LIST_STATE =     102;
141        public static final int TYPE_SR_STATE =                     103;
142        public static final int VALS_SR_STATE =                     104;
143        public static final int ATTRIBUTE_VALUE_SR_STATE =          105;
144        public static final int REFERENCE_STATE =                   106;
145        public static final int CONTROLS_STATE =                    107;
146        public static final int CONTROL_STATE =                     108;
147        public static final int CONTROL_TYPE_STATE =                109;
148        public static final int CRITICALITY_STATE =                 110;
149        public static final int CONTROL_VALUE_STATE =               111;
150        public static final int INTERMEDIATE_RESPONSE_STATE =       112;
151        public static final int INTERMEDIATE_RESPONSE_NAME_STATE =  113;
152        public static final int INTERMEDIATE_RESPONSE_VALUE_STATE = 114;
153        
154        
155        public static final int LAST_LDAP_STATE = 115;
156    
157        // =========================================================================
158        // States debug strings
159        // =========================================================================
160        /** A string representation of all the states */
161        private static String[] LdapMessageString = new String[]
162            { 
163            "START_STATE",
164            "LDAP_MESSAGE_STATE",
165            "MESSAGE_ID_STATE",
166            "BIND_REQUEST_STATE",
167            "BIND_RESPONSE_STATE",
168            "UNBIND_REQUEST_STATE",
169            "SEARCH_REQUEST_STATE",
170            "SEARCH_RESULT_ENTRY_STATE",
171            "SEARCH_RESULT_DONE_STATE",
172            "SEARCH_RESULT_REFERENCE_STATE",
173            "MODIFY_REQUEST_STATE",
174            "MODIFY_RESPONSE_STATE",
175            "ADD_REQUEST_STATE",
176            "ADD_RESPONSE_STATE",
177            "DEL_REQUEST_STATE",
178            "DEL_RESPONSE_STATE",
179            "MODIFY_DN_REQUEST_STATE",
180            "MODIFY_DN_RESPONSE_STATE",
181            "COMPARE_REQUEST_STATE",
182            "COMPARE_RESPONSE_STATE",
183            "ABANDON_REQUEST_STATE",
184            "EXTENDED_REQUEST_STATE",
185            "EXTENDED_RESPONSE_STATE",
186            "VERSION_STATE",
187            "NAME_STATE",
188            "SIMPLE_STATE",
189            "SASL_STATE",
190            "MECHANISM_STATE",
191            "CREDENTIALS_STATE",
192            "RESULT_CODE_BR_STATE",
193            "MATCHED_DN_BR_STATE",
194            "ERROR_MESSAGE_BR_STATE",
195            "REFERRALS_BR_STATE",
196            "REFERRAL_BR_STATE",
197            "SERVER_SASL_CREDENTIALS_STATE",
198            "RESULT_CODE_STATE",
199            "MATCHED_DN_STATE",
200            "ERROR_MESSAGE_STATE",
201            "REFERRALS_STATE",
202            "REFERRAL_STATE",
203            "REQUEST_NAME_STATE",
204            "REQUEST_VALUE_STATE",
205            "RESPONSE_NAME_STATE",
206            "RESPONSE_STATE",
207            "RESULT_CODE_ER_STATE",
208            "MATCHED_DN_ER_STATE",
209            "ERROR_MESSAGE_ER_STATE",
210            "REFERRALS_ER_STATE",
211            "REFERRAL_ER_STATE",
212            "ENTRY_STATE",
213            "ATTRIBUTES_STATE",
214            "ATTRIBUTE_STATE",
215            "TYPE_STATE",
216            "VALUES_STATE",
217            "VALUE_STATE",
218            "OBJECT_STATE",
219            "MODIFICATIONS_STATE",
220            "MODIFICATIONS_SEQ_STATE",
221            "OPERATION_STATE",
222            "MODIFICATION_STATE",
223            "TYPE_MOD_STATE",
224            "VALS_STATE",
225            "ATTRIBUTE_VALUE_STATE",
226            "ENTRY_MOD_DN_STATE",
227            "NEW_RDN_STATE",
228            "DELETE_OLD_RDN_STATE",
229            "NEW_SUPERIOR_STATE",
230            "ENTRY_COMP_STATE",
231            "AVA_STATE",
232            "ATTRIBUTE_DESC_STATE",
233            "ASSERTION_VALUE_STATE",
234            "BASE_OBJECT_STATE",
235            "SCOPE_STATE",
236            "DEREF_ALIAS_STATE",
237            "SIZE_LIMIT_STATE",
238            "TIME_LIMIT_STATE",
239            "TYPES_ONLY_STATE",
240            "AND_STATE",
241            "OR_STATE",
242            "NOT_STATE",
243            "EQUALITY_MATCH_STATE",
244            "SUBSTRINGS_FILTER_STATE",
245            "GREATER_OR_EQUAL_STATE",
246            "LESS_OR_EQUAL_STATE",
247            "PRESENT_STATE",
248            "APPROX_MATCH_STATE",
249            "EXTENSIBLE_MATCH_STATE",
250            "SUBSTRING_FILTER_STATE",
251            "ATTRIBUTE_DESC_FILTER_STATE",
252            "ASSERTION_VALUE_FILTER_STATE",
253            "ATTRIBUTE_DESCRIPTION_LIST_STATE",
254            "ATTRIBUTE_DESCRIPTION_STATE",
255            "TYPE_SUBSTRING_STATE",
256            "SUBSTRINGS_STATE",
257            "INITIAL_STATE",
258            "ANY_STATE",
259            "FINAL_STATE",
260            "MATCHING_RULE_STATE",
261            "TYPE_MATCHING_RULE_STATE",
262            "MATCH_VALUE_STATE",
263            "DN_ATTRIBUTES_STATE",
264            "OBJECT_NAME_STATE",
265            "ATTRIBUTES_SR_STATE",
266            "PARTIAL_ATTRIBUTES_LIST_STATE",
267            "TYPE_SR_STATE",
268            "VALS_SR_STATE",
269            "ATTRIBUTE_VALUE_SR_STATE",
270            "REFERENCE_STATE",
271            "CONTROLS_STATE",
272            "CONTROL_STATE",
273            "CONTROL_TYPE_STATE",
274            "CRITICALITY_STATE",
275            "CONTROL_VALUE_STATE",
276            "INTERMEDIATE_RESPONSE_STATE",
277            "INTERMEDIATE_RESPONSE_NAME_STATE",
278            "INTERMEDIATE_RESPONSE_VALUE_STATE",
279            "LAST_LDAP_STATE",
280            };
281    
282        /** The instance */
283        private static LdapStatesEnum instance = new LdapStatesEnum();
284    
285    
286        // ~ Constructors
287        // -------------------------------------------------------------------------------
288    
289        /**
290         * This is a private constructor. This class is a singleton
291         */
292        private LdapStatesEnum()
293        {
294        }
295    
296    
297        // ~ Methods
298        // ------------------------------------------------------------------------------------
299    
300        /**
301         * Get an instance of this class
302         * 
303         * @return An instance on this class
304         */
305        public static IStates getInstance()
306        {
307            return instance;
308        }
309    
310    
311        /**
312         * Get the grammar name
313         * 
314         * @param grammar
315         *            The grammar code
316         * @return The grammar name
317         */
318        public String getGrammarName( int grammar )
319        {
320            return "LDAP_MESSAGE_GRAMMAR";
321        }
322    
323    
324        /**
325         * Get the grammar name
326         * 
327         * @param grammar
328         *            The grammar class
329         * @return The grammar name
330         */
331        public String getGrammarName( IGrammar grammar )
332        {
333            if ( grammar instanceof LdapMessageGrammar )
334            {
335                return "LDAP_MESSAGE_GRAMMAR";
336            }
337            else
338            {
339                return "UNKNOWN GRAMMAR";
340            }
341        }
342    
343    
344        /**
345         * Get the string representing the state
346         * 
347         * @param state The state number
348         * @return The String representing the state
349         */
350        public String getState( int state )
351        {
352            return ( ( state == GRAMMAR_END ) ? "LDAP_MESSAGE_END_STATE" : LdapMessageString[state] );
353        }
354    }