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