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.ldif;
021    
022    
023    /**
024     * A type safe enumeration for an LDIF record's change type.
025     *
026     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027     * @version $Rev$, $Date$
028     */
029    public enum ChangeType
030    {
031        Add( 0 ),
032        Modify( 1 ),
033        ModDn( 2 ),
034        ModRdn( 3 ),
035        Delete( 4 );
036        
037        /** Add ordinal value */
038        public static final int ADD_ORDINAL = 0;
039    
040        /** Modify ordinal value */
041        public static final int MODIFY_ORDINAL = 1;
042    
043        /** ModDN ordinal value */
044        public static final int MODDN_ORDINAL = 2;
045    
046        /** ModRDN ordinal value */
047        public static final int MODRDN_ORDINAL = 3;
048    
049        /** Delete ordinal value */
050        public static final int DELETE_ORDINAL = 4;
051    
052        /* the ordinal value for a change type */
053        private final int changeType;
054        
055        
056        /**
057         * Creates a new instance of ChangeType.
058         *
059         * @param changeType
060         */
061        private ChangeType( int changeType )
062        {
063            this.changeType = changeType;
064        }
065    
066    
067        /**
068         * Get's the ordinal value for a ChangeType.
069         * 
070         * @return the changeType
071         */
072        public int getChangeType()
073        {
074            return changeType;
075        }
076        
077        public static ChangeType getChangeType( int val )
078        {
079            switch( val )
080            {
081                case 0: return Add;
082                
083                case 1: return Modify;
084                
085                case 2: return ModDn;
086                
087                case 3: return ModRdn;
088                
089                case 4: return Delete;
090                
091                default:
092                    throw new IllegalArgumentException( "Unknown change type value " + val );
093            }
094        }
095    }