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     */
020    package org.apache.directory.shared.ldap.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     * @version $Rev$, $Date$
029     */
030    public 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         * @see Object#toString()
087         */
088        public String toString()
089        {
090            switch ( this )
091            {
092                case ADD_ATTRIBUTE :
093                    return "add";
094                    
095                case REPLACE_ATTRIBUTE :
096                    return "replace";
097                    
098                case REMOVE_ATTRIBUTE :
099                    return "remove";
100                    
101                default :
102                    return "";
103            }
104        }
105    }