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 * We have added the INCREMENT operation (RFC 4525) 029 * 030 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 031 */ 032public enum ModificationOperation 033{ 034 /** Added attribute value */ 035 ADD_ATTRIBUTE(0), 036 037 /** Removed attribute value */ 038 REMOVE_ATTRIBUTE(1), 039 040 /** Replaced attribute value */ 041 REPLACE_ATTRIBUTE(2), 042 043 /** Increment operation, RFC 4525 */ 044 INCREMENT_ATTRIBUTE(3); 045 046 /** Internal value */ 047 private int value; 048 049 050 /** 051 * Creates a new instance of ModificationOperation. 052 * 053 * @param value The value 054 */ 055 ModificationOperation( int value ) 056 { 057 this.value = value; 058 } 059 060 061 /** 062 * @return The integer value associated with the element. This value 063 * is equivalent to the one found in DirContext. 064 */ 065 public int getValue() 066 { 067 return value; 068 } 069 070 071 /** 072 * Get the ModificationOperation from an int value 073 * 074 * @param value the ModificationOperation int value 075 * @return the associated ModifciationOperation instance 076 */ 077 public static ModificationOperation getOperation( int value ) 078 { 079 if ( value == ADD_ATTRIBUTE.value ) 080 { 081 return ADD_ATTRIBUTE; 082 } 083 else if ( value == REMOVE_ATTRIBUTE.value ) 084 { 085 return REMOVE_ATTRIBUTE; 086 } 087 else if ( value == REPLACE_ATTRIBUTE.value ) 088 { 089 return REPLACE_ATTRIBUTE; 090 } 091 else if ( value == INCREMENT_ATTRIBUTE.value ) 092 { 093 return INCREMENT_ATTRIBUTE; 094 } 095 else 096 { 097 return null; 098 } 099 } 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}