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.shared.ldap.model.entry;
021
022/**
023 * An enum storing the different modification operation which can be used
024 * in a Modification. There is a one to one mapping with the DirContext.ADD_ATTRIBUTE,
025 * DirContext.REMOVE_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE
026 *
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public enum ModificationOperation
030{
031    ADD_ATTRIBUTE( 0 ),
032    REMOVE_ATTRIBUTE( 1 ),
033    REPLACE_ATTRIBUTE( 2 );
034
035    /** Internal value */
036    private int value;
037    
038    
039    /**
040     * Creates a new instance of ModificationOperation.
041     */
042    private ModificationOperation( int value )
043    {
044        this.value = value;
045    }
046    
047    
048    /**
049     * @return The integer value associated with the element. This value
050     * is equivalent to the one found in DirContext.
051     */
052    public int getValue()
053    {
054        return value;
055    }
056    
057    
058    /**
059     * Get the ModificationOperation from an int value
060     *
061     * @param value the ModificationOperation int value
062     * @return the associated ModifciationOperation instance
063     */
064    public static ModificationOperation getOperation( int value )
065    {
066        if ( value == ADD_ATTRIBUTE.value )
067        {
068            return ADD_ATTRIBUTE;
069        }
070        else if ( value == REMOVE_ATTRIBUTE.value )
071        {
072            return REMOVE_ATTRIBUTE;
073        }
074        else if ( value == REPLACE_ATTRIBUTE.value )
075        {
076            return REPLACE_ATTRIBUTE;
077        }
078        else
079        {
080            return null;
081        }
082    }
083    
084    /**
085     * @see Object#toString()
086     */
087    public String toString()
088    {
089        switch ( this )
090        {
091            case ADD_ATTRIBUTE :
092                return "add";
093                
094            case REPLACE_ATTRIBUTE :
095                return "replace";
096                
097            case REMOVE_ATTRIBUTE :
098                return "remove";
099                
100            default :
101                return "";
102        }
103    }
104}