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