1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.ldif; 21 22 23 import org.apache.directory.api.i18n.I18n; 24 25 26 /** 27 * A type safe enumeration for an LDIF record's change type. 28 * 29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 30 */ 31 public enum ChangeType 32 { 33 /** The Add changeType */ 34 Add(0), 35 36 /** The Modify changeType */ 37 Modify(1), 38 39 /** The ModDn changeType */ 40 ModDn(2), 41 42 /** The ModRdn changeType */ 43 ModRdn(3), 44 45 /** The Delete changeType */ 46 Delete(4), 47 48 /** A place-holder when we have no changeType */ 49 None(-1); 50 51 /** Add ordinal value */ 52 public static final int ADD_ORDINAL = 0; 53 54 /** Modify ordinal value */ 55 public static final int MODIFY_ORDINAL = 1; 56 57 /** ModDN ordinal value */ 58 public static final int MODDN_ORDINAL = 2; 59 60 /** ModRDN ordinal value */ 61 public static final int MODRDN_ORDINAL = 3; 62 63 /** Delete ordinal value */ 64 public static final int DELETE_ORDINAL = 4; 65 66 /** None ordinal value */ 67 public static final int NONE_ORDINAL = -1; 68 69 /** the ordinal value for a change type */ 70 private final int changeType; 71 72 73 /** 74 * Creates a new instance of ChangeType. 75 * 76 * @param changeType The associated value 77 */ 78 private ChangeType( int changeType ) 79 { 80 this.changeType = changeType; 81 } 82 83 84 /** 85 * Get's the ordinal value for a ChangeType. 86 * 87 * @return the changeType 88 */ 89 public int getChangeType() 90 { 91 return changeType; 92 } 93 94 95 /** 96 * Get the ChangeType instance from an integer value 97 * 98 * @param val The value for the ChangeType we are looking for 99 * @return The associated ChangeType instance 100 */ 101 public static ChangeType getChangeType( int val ) 102 { 103 switch ( val ) 104 { 105 case -1: 106 return None; 107 108 case 0: 109 return Add; 110 111 case 1: 112 return Modify; 113 114 case 2: 115 return ModDn; 116 117 case 3: 118 return ModRdn; 119 120 case 4: 121 return Delete; 122 123 default: 124 throw new IllegalArgumentException( I18n.err( I18n.ERR_12001_UNKNOWN_CHANGE_TYPE, val ) ); 125 } 126 } 127 }