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.search.persistentSearch;
021
022
023import org.apache.directory.api.asn1.ber.grammar.Grammar;
024import org.apache.directory.api.asn1.ber.grammar.States;
025
026
027/**
028 * This class store the PSearchControl'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 */
033public enum PersistentSearchStates implements States
034{
035    // ~ Static fields/initializers
036    // -----------------------------------------------------------------
037
038    /** The END_STATE */
039    END_STATE,
040
041    // =========================================================================
042    // Persistent search control grammar states
043    // =========================================================================
044    /** Initial state */
045    START_STATE,
046
047    /** Sequence Value */
048    PSEARCH_SEQUENCE_STATE,
049
050    /** changeTypes Value */
051    CHANGE_TYPES_STATE,
052
053    /** changesOnly Value */
054    CHANGES_ONLY_STATE,
055
056    /** returnECs Value */
057    RETURN_ECS_STATE,
058
059    /** terminal state */
060    LAST_PSEARCH_STATE;
061
062    /**
063     * Get the grammar name
064     * 
065     * @return The grammar name
066     */
067    public String getGrammarName()
068    {
069        return "PSEARCH_GRAMMAR";
070    }
071
072
073    /**
074     * Get the grammar name
075     * 
076     * @param grammar The grammar class
077     * @return The grammar name
078     */
079    public String getGrammarName( Grammar<?> grammar )
080    {
081        if ( grammar instanceof PersistentSearchGrammar )
082        {
083            return "PSEARCH_GRAMMAR";
084        }
085
086        return "UNKNOWN GRAMMAR";
087    }
088
089
090    /**
091     * Get the string representing the state
092     * 
093     * @param state The state number
094     * @return The String representing the state
095     */
096    public String getState( int state )
097    {
098        return ( ( state == END_STATE.ordinal() ) ? "PSEARCH_END_STATE" : name() );
099    }
100
101
102    /**
103     * {@inheritDoc}
104     */
105    public boolean isEndState()
106    {
107        return this == END_STATE;
108    }
109
110
111    /**
112     * {@inheritDoc}
113     */
114    public PersistentSearchStates getStartState()
115    {
116        return START_STATE;
117    }
118}