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.search.controls.entryChange;
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 EntryChangeControl's grammar constants. It is also used
029 * for debugging purposes.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev: 764131 $, $Date: 2009-04-11 03:03:00 +0200 (Sam, 11 avr 2009) $,
033 */
034 public class EntryChangeControlStatesEnum implements IStates
035 {
036 // ~ Static fields/initializers
037 // -----------------------------------------------------------------
038
039 // =========================================================================
040 // Entry change control grammar states
041 // =========================================================================
042
043 /** Sequence Tag */
044 public static final int START_STATE = 0;
045
046 /** Sequence */
047 public static final int EC_SEQUENCE_STATE = 1;
048
049 /** changeType */
050 public static final int CHANGE_TYPE_STATE = 2;
051
052 /** previousDN */
053 public static final int PREVIOUS_DN_STATE = 3;
054
055 /** changeNumber */
056 public static final int CHANGE_NUMBER_STATE = 4;
057
058 /** terminal state */
059 public static final int LAST_EC_STATE = 5;
060
061 // =========================================================================
062 // States debug strings
063 // =========================================================================
064 /** A string representation of all the states */
065 private static String[] EcString = new String[]
066 {
067 "START_STATE",
068 "EC_SEQUENCE_STATE",
069 "CHANGE_TYPE_STATE",
070 "PREVIOUS_DN_STATE",
071 "CHANGE_NUMBER_STATE"
072 };
073
074 /** The instance */
075 private static EntryChangeControlStatesEnum instance = new EntryChangeControlStatesEnum();
076
077
078 // ~ Constructors
079 // -------------------------------------------------------------------------------
080
081 /**
082 * This is a private constructor. This class is a singleton
083 */
084 private EntryChangeControlStatesEnum()
085 {
086 }
087
088
089 // ~ Methods
090 // ------------------------------------------------------------------------------------
091
092 /**
093 * Get an instance of this class
094 *
095 * @return An instance on this class
096 */
097 public static IStates getInstance()
098 {
099 return instance;
100 }
101
102
103 /**
104 * Get the grammar name
105 *
106 * @param grammar The grammar code
107 * @return The grammar name
108 */
109 public String getGrammarName( int grammar )
110 {
111 return "EC_GRAMMAR";
112 }
113
114
115 /**
116 * Get the grammar name
117 *
118 * @param grammar The grammar class
119 * @return The grammar name
120 */
121 public String getGrammarName( IGrammar grammar )
122 {
123 if ( grammar instanceof EntryChangeControlGrammar )
124 {
125 return "EC_GRAMMAR";
126 }
127
128 return "UNKNOWN GRAMMAR";
129 }
130
131
132 /**
133 * Get the string representing the state
134 *
135 * @param state The state number
136 * @return The String representing the state
137 */
138 public String getState( int state )
139 {
140 return ( ( state == GRAMMAR_END ) ? "EC_END_STATE" : EcString[state] );
141 }
142 }