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