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