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