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 */ 020package org.apache.directory.api.ldap.codec.controls.sort; 021 022 023import org.apache.directory.api.asn1.ber.grammar.Grammar; 024import org.apache.directory.api.asn1.ber.grammar.States; 025 026 027/** 028 * Codec states for SortRequestControl. 029 * 030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 031 */ 032public enum SortRequestStates implements States 033{ 034 START_STATE, 035 036 SEQUENCE_OF_SEQUENCE_STATE, 037 038 SORT_KEY_SEQUENCE_STATE, 039 040 AT_DESC_STATE, 041 042 ORDER_RULE_STATE, 043 044 REVERSE_ORDER_STATE, 045 046 END_STATE; 047 048 /** 049 * Get the grammar name 050 * 051 * @param grammar The grammar code 052 * @return The grammar name 053 */ 054 public String getGrammarName( int grammar ) 055 { 056 return "SORT_REQUEST_GRAMMAR"; 057 } 058 059 060 /** 061 * Get the grammar name 062 * 063 * @param grammar The grammar class 064 * @return The grammar name 065 */ 066 public String getGrammarName( Grammar<?> grammar ) 067 { 068 if ( grammar instanceof SortRequestGrammar ) 069 { 070 return "SORT_REQUEST_GRAMMAR"; 071 } 072 073 return "UNKNOWN GRAMMAR"; 074 } 075 076 077 /** 078 * Get the string representing the state 079 * 080 * @param state The state number 081 * @return The String representing the state 082 */ 083 public String getState( int state ) 084 { 085 return ( ( state == END_STATE.ordinal() ) ? "SORT_REQUEST_END_STATE" : name() ); 086 } 087 088 089 @Override 090 public boolean isEndState() 091 { 092 return ( this == END_STATE ); 093 } 094 095 096 @Override 097 public Enum<?> getStartState() 098 { 099 return START_STATE; 100 } 101 102}