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