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.extras.controls;
021
022
023/**
024 * This class describes the four possible synchronization mode, out of
025 * which only two are presently valid :
026 * 
027 * <pre>
028 * syncRequestValue ::= SEQUENCE {
029 *     mode ENUMERATED {
030 *         -- 0 unused
031 *         refreshOnly       (1),
032 *         -- 2 reserved
033 *         refreshAndPersist (3)
034 * ...
035 * </pre>
036 * 
037 * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
038 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039 *
040 */
041public enum SynchronizationModeEnum
042{
043    UNUSED(0),
044    REFRESH_ONLY(1),
045    RESERVED(2),
046    REFRESH_AND_PERSIST(3);
047
048    /** The internal value */
049    private int value;
050
051
052    /**
053     * Private constructor so no other instances can be created other than the
054     * public static constants in this class.
055     * 
056     * @param value the integer value of the enumeration.
057     */
058    private SynchronizationModeEnum( int value )
059    {
060        this.value = value;
061    }
062
063
064    /**
065     * @return The value associated with the current element.
066     */
067    public int getValue()
068    {
069        return value;
070    }
071
072
073    /**
074     * Get the {@link SynchronizationModeEnum} instance from an integer value.
075     * 
076     * @param value The value we want the enum element from
077     * @return The enum element associated with this integer
078     */
079    public static SynchronizationModeEnum getSyncMode( int value )
080    {
081        if ( value == REFRESH_AND_PERSIST.getValue() )
082        {
083            return REFRESH_AND_PERSIST;
084        }
085        else if ( value == REFRESH_ONLY.getValue() )
086        {
087            return REFRESH_ONLY;
088        }
089        else if ( value == UNUSED.getValue() )
090        {
091            return UNUSED;
092        }
093        else
094        {
095            return RESERVED;
096        }
097    }
098}