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 */
44      UNUSED(0),
45      
46      /** Refresh only mode */
47      REFRESH_ONLY(1),
48  
49      /** Unused */
50      RESERVED(2),
51      
52      /** Refresh and Persist mode */
53      REFRESH_AND_PERSIST(3);
54  
55      /** The internal value */
56      private int value;
57  
58  
59      /**
60       * Private constructor so no other instances can be created other than the
61       * public static constants in this class.
62       * 
63       * @param value the integer value of the enumeration.
64       */
65      SynchronizationModeEnum( int value )
66      {
67          this.value = value;
68      }
69  
70  
71      /**
72       * @return The value associated with the current element.
73       */
74      public int getValue()
75      {
76          return value;
77      }
78  
79  
80      /**
81       * Get the {@link SynchronizationModeEnum} instance from an integer value.
82       * 
83       * @param value The value we want the enum element from
84       * @return The enum element associated with this integer
85       */
86      public static SynchronizationModeEnum getSyncMode( int value )
87      {
88          if ( value == REFRESH_AND_PERSIST.getValue() )
89          {
90              return REFRESH_AND_PERSIST;
91          }
92          else if ( value == REFRESH_ONLY.getValue() )
93          {
94              return REFRESH_ONLY;
95          }
96          else if ( value == UNUSED.getValue() )
97          {
98              return UNUSED;
99          }
100         else
101         {
102             return RESERVED;
103         }
104     }
105 }