View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.extras.controls;
21  
22  
23  /**
24   * This class describes the four possible synchronization mode, out of
25   * which only two are presently valid :
26   * 
27   * <pre>
28   * syncRequestValue ::= SEQUENCE {
29   *     mode ENUMERATED {
30   *         -- 0 unused
31   *         refreshOnly       (1),
32   *         -- 2 reserved
33   *         refreshAndPersist (3)
34   * ...
35   * </pre>
36   * 
37   * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   *
40   */
41  public enum SynchronizationModeEnum
42  {
43      UNUSED(0),
44      REFRESH_ONLY(1),
45      RESERVED(2),
46      REFRESH_AND_PERSIST(3);
47  
48      /** The internal value */
49      private int value;
50  
51  
52      /**
53       * Private constructor so no other instances can be created other than the
54       * public static constants in this class.
55       * 
56       * @param value the integer value of the enumeration.
57       */
58      private SynchronizationModeEnum( int value )
59      {
60          this.value = value;
61      }
62  
63  
64      /**
65       * @return The value associated with the current element.
66       */
67      public int getValue()
68      {
69          return value;
70      }
71  
72  
73      /**
74       * Get the {@link SynchronizationModeEnum} instance from an integer value.
75       * 
76       * @param value The value we want the enum element from
77       * @return The enum element associated with this integer
78       */
79      public static SynchronizationModeEnum getSyncMode( int value )
80      {
81          if ( value == REFRESH_AND_PERSIST.getValue() )
82          {
83              return REFRESH_AND_PERSIST;
84          }
85          else if ( value == REFRESH_ONLY.getValue() )
86          {
87              return REFRESH_ONLY;
88          }
89          else if ( value == UNUSED.getValue() )
90          {
91              return UNUSED;
92          }
93          else
94          {
95              return RESERVED;
96          }
97      }
98  }