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.extended.operations.gracefulDisconnect;
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 GracefulDisconnect'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 (Sat, 11 Apr 2009) $, 
033     */
034    public class GracefulDisconnectStatesEnum implements IStates
035    {
036        // ~ Static fields/initializers
037        // -----------------------------------------------------------------
038    
039        // =========================================================================
040        // GracefulDisconnect grammar states
041        // =========================================================================
042        /** Initial state */
043        public static final int START_STATE = 0;
044    
045        /** Sequence */
046        public static final int GRACEFUL_DISCONNECT_SEQUENCE_STATE = 1;
047    
048        /** Time offline */
049        public static final int TIME_OFFLINE_STATE = 2;
050    
051        /** Delay */
052        public static final int DELAY_STATE = 3;
053    
054        /** Replicated contexts */
055        public static final int REPLICATED_CONTEXTS_STATE = 4;
056    
057        /** Referral */
058        public static final int REFERRAL_STATE = 5;
059    
060        /** terminal state */
061        public static final int LAST_GRACEFUL_DISCONNECT_STATE = 6;
062    
063        // =========================================================================
064        // States debug strings
065        // =========================================================================
066        /** A string representation of all the states */
067        private static String[] GracefulDisconnectString = new String[]
068            { 
069            "START_STATE", 
070            "GRACEFUL_DISCONNECT_SEQUENCE_STATE",
071            "TIME_OFFLINE_STATE", 
072            "DELAY_STATE", 
073            "REPLICATED_CONTEXTS_STATE",
074            "REFERRAL_STATE"
075            };
076    
077        /** The instance */
078        private static GracefulDisconnectStatesEnum instance = new GracefulDisconnectStatesEnum();
079    
080    
081        // ~ Constructors
082        // -------------------------------------------------------------------------------
083    
084        /**
085         * This is a private constructor. This class is a singleton
086         */
087        private GracefulDisconnectStatesEnum()
088        {
089        }
090    
091    
092        // ~ Methods
093        // ------------------------------------------------------------------------------------
094    
095        /**
096         * Get an instance of this class
097         * 
098         * @return An instance on this class
099         */
100        public static IStates getInstance()
101        {
102            return instance;
103        }
104    
105    
106        /**
107         * Get the grammar name
108         * 
109         * @param grammar The grammar code
110         * @return The grammar name
111         */
112        public String getGrammarName( int grammar )
113        {
114            return "GRACEFUL_DISCONNECT_GRAMMAR";
115        }
116    
117    
118        /**
119         * Get the grammar name
120         * 
121         * @param grammar The grammar class
122         * @return The grammar name
123         */
124        public String getGrammarName( IGrammar grammar )
125        {
126            if ( grammar instanceof GracefulDisconnectGrammar )
127            {
128                return "GRACEFUL_DISCONNECT_GRAMMAR";
129            }
130    
131            return "UNKNOWN GRAMMAR";
132        }
133    
134    
135        /**
136         * Get the string representing the state
137         * 
138         * @param state The state number
139         * @return The String representing the state
140         */
141        public String getState( int state )
142        {
143            return ( ( state == GRAMMAR_END ) ? "GRACEFUL_DISCONNECT_END_STATE" : GracefulDisconnectString[state] );
144        }
145    }