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