001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.entry; 021 022 023/** 024 * An enum storing the different modification operation which can be used 025 * in a Modification. There is a one to one mapping with the DirContext.ADD_ATTRIBUTE, 026 * DirContext.REMOVE_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE 027 * 028 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 029 */ 030public enum ModificationOperation 031{ 032 /** Added attribute value */ 033 ADD_ATTRIBUTE(0), 034 035 /** Removed attribute value */ 036 REMOVE_ATTRIBUTE(1), 037 038 /** Replaced attribute value */ 039 REPLACE_ATTRIBUTE(2); 040 041 /** Internal value */ 042 private int value; 043 044 045 /** 046 * Creates a new instance of ModificationOperation. 047 */ 048 ModificationOperation( int value ) 049 { 050 this.value = value; 051 } 052 053 054 /** 055 * @return The integer value associated with the element. This value 056 * is equivalent to the one found in DirContext. 057 */ 058 public int getValue() 059 { 060 return value; 061 } 062 063 064 /** 065 * Get the ModificationOperation from an int value 066 * 067 * @param value the ModificationOperation int value 068 * @return the associated ModifciationOperation instance 069 */ 070 public static ModificationOperation getOperation( int value ) 071 { 072 if ( value == ADD_ATTRIBUTE.value ) 073 { 074 return ADD_ATTRIBUTE; 075 } 076 else if ( value == REMOVE_ATTRIBUTE.value ) 077 { 078 return REMOVE_ATTRIBUTE; 079 } 080 else if ( value == REPLACE_ATTRIBUTE.value ) 081 { 082 return REPLACE_ATTRIBUTE; 083 } 084 else 085 { 086 return null; 087 } 088 } 089 090 091 /** 092 * @see Object#toString() 093 */ 094 @Override 095 public String toString() 096 { 097 switch ( this ) 098 { 099 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}