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   *    https://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.model.entry;
21  
22  
23  /**
24   * An enum storing the different modification operation which can be used
25   * in a Modification. There is a one to one mapping with the DirContext.ADD_ATTRIBUTE,
26   * DirContext.REMOVE_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE.
27   * 
28   * We have added the INCREMENT operation (RFC 4525)
29   *
30   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31   */
32  public enum ModificationOperation
33  {
34      /** Added attribute value */
35      ADD_ATTRIBUTE(0),
36      
37      /** Removed attribute value */
38      REMOVE_ATTRIBUTE(1),
39      
40      /** Replaced attribute value */
41      REPLACE_ATTRIBUTE(2),
42      
43      /** Increment operation, RFC 4525 */
44      INCREMENT_ATTRIBUTE(3);
45  
46      /** Internal value */
47      private int value;
48  
49  
50      /**
51       * Creates a new instance of ModificationOperation.
52       * 
53       * @param value The value
54       */
55      ModificationOperation( int value )
56      {
57          this.value = value;
58      }
59  
60  
61      /**
62       * @return The integer value associated with the element. This value
63       * is equivalent to the one found in DirContext.
64       */
65      public int getValue()
66      {
67          return value;
68      }
69  
70  
71      /**
72       * Get the ModificationOperation from an int value
73       *
74       * @param value the ModificationOperation int value
75       * @return the associated ModifciationOperation instance
76       */
77      public static ModificationOperation getOperation( int value )
78      {
79          if ( value == ADD_ATTRIBUTE.value )
80          {
81              return ADD_ATTRIBUTE;
82          }
83          else if ( value == REMOVE_ATTRIBUTE.value )
84          {
85              return REMOVE_ATTRIBUTE;
86          }
87          else if ( value == REPLACE_ATTRIBUTE.value )
88          {
89              return REPLACE_ATTRIBUTE;
90          }
91          else if ( value == INCREMENT_ATTRIBUTE.value )
92          {
93              return INCREMENT_ATTRIBUTE;
94          }
95          else
96          {
97              return null;
98          }
99      }
100 
101 
102     /**
103      * @see Object#toString()
104      */
105     @Override
106     public String toString()
107     {
108         switch ( this )
109         {
110             case ADD_ATTRIBUTE:
111                 return "add";
112 
113             case REPLACE_ATTRIBUTE:
114                 return "replace";
115 
116             case REMOVE_ATTRIBUTE:
117                 return "remove";
118 
119             case INCREMENT_ATTRIBUTE:
120                 return "increment";
121                 
122             default:
123                 return "";
124         }
125     }
126 }