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.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   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
29   */
30  public enum ModificationOperation
31  {
32      /** Added attribute value */
33      ADD_ATTRIBUTE(0),
34      
35      /** Removed attribute value */
36      REMOVE_ATTRIBUTE(1),
37      
38      /** Replaced attribute value */
39      REPLACE_ATTRIBUTE(2);
40  
41      /** Internal value */
42      private int value;
43  
44  
45      /**
46       * Creates a new instance of ModificationOperation.
47       */
48      ModificationOperation( int value )
49      {
50          this.value = value;
51      }
52  
53  
54      /**
55       * @return The integer value associated with the element. This value
56       * is equivalent to the one found in DirContext.
57       */
58      public int getValue()
59      {
60          return value;
61      }
62  
63  
64      /**
65       * Get the ModificationOperation from an int value
66       *
67       * @param value the ModificationOperation int value
68       * @return the associated ModifciationOperation instance
69       */
70      public static ModificationOperation getOperation( int value )
71      {
72          if ( value == ADD_ATTRIBUTE.value )
73          {
74              return ADD_ATTRIBUTE;
75          }
76          else if ( value == REMOVE_ATTRIBUTE.value )
77          {
78              return REMOVE_ATTRIBUTE;
79          }
80          else if ( value == REPLACE_ATTRIBUTE.value )
81          {
82              return REPLACE_ATTRIBUTE;
83          }
84          else
85          {
86              return null;
87          }
88      }
89  
90  
91      /**
92       * @see Object#toString()
93       */
94      @Override
95      public String toString()
96      {
97          switch ( this )
98          {
99              case ADD_ATTRIBUTE:
100                 return "add";
101 
102             case REPLACE_ATTRIBUTE:
103                 return "replace";
104 
105             case REMOVE_ATTRIBUTE:
106                 return "remove";
107 
108             default:
109                 return "";
110         }
111     }
112 }