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 ADD_ATTRIBUTE(0), 033 REMOVE_ATTRIBUTE(1), 034 REPLACE_ATTRIBUTE(2); 035 036 /** Internal value */ 037 private int value; 038 039 040 /** 041 * Creates a new instance of ModificationOperation. 042 */ 043 private ModificationOperation( int value ) 044 { 045 this.value = value; 046 } 047 048 049 /** 050 * @return The integer value associated with the element. This value 051 * is equivalent to the one found in DirContext. 052 */ 053 public int getValue() 054 { 055 return value; 056 } 057 058 059 /** 060 * Get the ModificationOperation from an int value 061 * 062 * @param value the ModificationOperation int value 063 * @return the associated ModifciationOperation instance 064 */ 065 public static ModificationOperation getOperation( int value ) 066 { 067 if ( value == ADD_ATTRIBUTE.value ) 068 { 069 return ADD_ATTRIBUTE; 070 } 071 else if ( value == REMOVE_ATTRIBUTE.value ) 072 { 073 return REMOVE_ATTRIBUTE; 074 } 075 else if ( value == REPLACE_ATTRIBUTE.value ) 076 { 077 return REPLACE_ATTRIBUTE; 078 } 079 else 080 { 081 return null; 082 } 083 } 084 085 086 /** 087 * @see Object#toString() 088 */ 089 public String toString() 090 { 091 switch ( this ) 092 { 093 case ADD_ATTRIBUTE: 094 return "add"; 095 096 case REPLACE_ATTRIBUTE: 097 return "replace"; 098 099 case REMOVE_ATTRIBUTE: 100 return "remove"; 101 102 default: 103 return ""; 104 } 105 } 106}