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