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