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.codec.search.controls;
021    
022    
023    /**
024     * Enumeration type for entry changes associates with the persistent search
025     * control and the entry change control. Used for the following ASN1
026     * enumeration:
027     * 
028     * <pre>
029     *   changeType ENUMERATED 
030     *   {
031     *       add             (1),
032     *       delete          (2),
033     *       modify          (4),
034     *       modDN           (8)
035     *   }
036     * </pre>
037     * 
038     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
039     * @version $Rev: 452497 $
040     */
041    public class ChangeType
042    {
043        public static final int ADD_VALUE = 1;
044    
045        public static final int DELETE_VALUE = 2;
046    
047        public static final int MODIFY_VALUE = 4;
048    
049        public static final int MODDN_VALUE = 8;
050    
051        public static final ChangeType ADD = new ChangeType( "ADD", ADD_VALUE );
052    
053        public static final ChangeType DELETE = new ChangeType( "DELETE", DELETE_VALUE );
054    
055        public static final ChangeType MODIFY = new ChangeType( "MODIFY", MODIFY_VALUE );
056    
057        public static final ChangeType MODDN = new ChangeType( "MODDN", MODDN_VALUE );
058        
059        private final String label;
060    
061        private final int value;
062    
063    
064        private ChangeType(String label, int value)
065        {
066            this.label = label;
067            this.value = value;
068        }
069    
070    
071        public int getValue()
072        {
073            return value;
074        }
075    
076    
077        public String toString()
078        {
079            return label;
080        }
081    
082    
083        /**
084         * Gets the changeType enumeration type for an integer value.
085         * 
086         * @param value the value to get the enumeration for
087         * @return the enueration type for the value if the value is valid
088         * @throws IllegalArgumentException if the value is undefined
089         */
090        public static ChangeType getChangeType( int value )
091        {
092            switch ( value )
093            {
094                case ( ADD_VALUE ):
095                    return ADD;
096                case ( DELETE_VALUE ):
097                    return DELETE;
098                case ( MODIFY_VALUE ):
099                    return MODIFY;
100                case ( MODDN_VALUE ):
101                    return MODDN;
102                default:
103                    throw new IllegalArgumentException( "Undefined changeType value: " + value );
104            }
105        }
106    }