Author: akarasulu Date: Wed Sep 19 00:18:50 2007 New Revision: 577180 URL: http://svn.apache.org/viewvc?rev=577180&view=rev Log: addiing enum for LDIF change type Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java (with props) Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java?rev=577180&view=auto ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java (added) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java Wed Sep 19 00:18:50 2007 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.shared.ldap.ldif; + + +/** + * A type safe enumeration for an LDIF record's change type. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public enum ChangeType +{ + Add( 0 ), + Modify( 1 ), + ModDn( 2 ), + ModRdn( 3 ), + Delete( 4 ); + + public static final int ADD_ORDINAL = 0; + public static final int MODIFY_ORDINAL = 1; + public static final int MODDN_ORDINAL = 2; + public static final int MODRDN_ORDINAL = 3; + public static final int DELETE_ORDINAL = 4; + + /* the ordinal value for a change type */ + private final int changeType; + + + /** + * Creates a new instance of ChangeType. + * + * @param changeType + */ + private ChangeType( int changeType ) + { + this.changeType = changeType; + } + + + /** + * Get's the ordinal value for a ChangeType. + * + * @return the changeType + */ + public final int getChangeType() + { + return changeType; + } +} Propchange: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java ------------------------------------------------------------------------------ svn:executable = * Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java?rev=577180&r1=577179&r2=577180&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/Entry.java Wed Sep 19 00:18:50 2007 @@ -49,7 +49,7 @@ public class Entry implements Cloneable { /** the change type */ - private int changeType; + private ChangeType changeType; /** the modification item list */ private List modificationList; @@ -71,17 +71,7 @@ /** attributes of the entry */ private Attributes attributeList; - /** The possible change types */ - public final static int ADD = 0; - - public final static int MODIFY = 1; - - public final static int MODDN = 2; - - public final static int MODRDN = 3; - - public final static int DELETE = 4; - + /** The control */ private Control control; @@ -90,7 +80,7 @@ */ public Entry() { - changeType = ADD; // Default LDIF content + changeType = ChangeType.Add; // Default LDIF content modificationList = new LinkedList(); modificationItems = new HashMap(); dn = null; @@ -116,7 +106,7 @@ * The change type * */ - public void setChangeType( int changeType ) + public void setChangeType( ChangeType changeType ) { this.changeType = changeType; } @@ -131,23 +121,23 @@ { if ( "add".equals( changeType ) ) { - this.changeType = ADD; + this.changeType = ChangeType.Add; } else if ( "modify".equals( changeType ) ) { - this.changeType = MODIFY; + this.changeType = ChangeType.Modify; } else if ( "moddn".equals( changeType ) ) { - this.changeType = MODDN; + this.changeType = ChangeType.ModDn; } else if ( "modrdn".equals( changeType ) ) { - this.changeType = MODRDN; + this.changeType = ChangeType.ModRdn; } else if ( "delete".equals( changeType ) ) { - this.changeType = DELETE; + this.changeType = ChangeType.Delete; } } @@ -158,7 +148,7 @@ */ public void addModificationItem( ModificationItemImpl modification ) { - if ( changeType == MODIFY ) + if ( changeType == ChangeType.Modify ) { modificationList.add( modification ); modificationItems.put( modification.getAttribute().getID(), modification ); @@ -177,7 +167,7 @@ */ public void addModificationItem( int modOp, Attribute attr ) throws NamingException { - if ( changeType == MODIFY ) + if ( changeType == ChangeType.Modify ) { if ( modificationItems.containsKey( attr.getID() ) ) { @@ -214,7 +204,7 @@ */ public void addModificationItem( int modOp, String id, Object value ) throws NamingException { - if ( changeType == MODIFY ) + if ( changeType == ChangeType.Modify ) { Attribute attr = new AttributeImpl( id, value ); @@ -308,7 +298,7 @@ * @return The change type. One of : ADD = 0; MODIFY = 1; MODDN = 2; MODRDN = * 3; DELETE = 4; */ - public int getChangeType() + public ChangeType getChangeType() { return changeType; } @@ -433,7 +423,7 @@ */ public boolean isChangeAdd() { - return changeType == ADD; + return changeType == ChangeType.Add; } /** @@ -441,7 +431,7 @@ */ public boolean isChangeDelete() { - return changeType == DELETE; + return changeType == ChangeType.Delete; } /** @@ -449,7 +439,7 @@ */ public boolean isChangeModDn() { - return changeType == MODDN; + return changeType == ChangeType.ModDn; } /** @@ -457,7 +447,7 @@ */ public boolean isChangeModRdn() { - return changeType == MODRDN; + return changeType == ChangeType.ModRdn; } /** @@ -465,12 +455,12 @@ */ public boolean isChangeModify() { - return changeType == MODIFY; + return changeType == ChangeType.Modify; } public boolean isEntry() { - return changeType == ADD; + return changeType == ChangeType.Add; } /** @@ -624,7 +614,7 @@ return sb.toString(); } - + /** * Return a String representing the Entry @@ -639,27 +629,27 @@ sb.append( " Control : " ).append( control ).append( '\n' ); } - switch ( changeType ) + switch ( changeType.getChangeType() ) { - case ADD : + case ChangeType.ADD_ORDINAL : sb.append( " Change type is ADD\n" ); sb.append( " Attributes : \n" ); sb.append( dumpAttributes() ); break; - case MODIFY : + case ChangeType.MODIFY_ORDINAL : sb.append( " Change type is MODIFY\n" ); sb.append( " Modifications : \n" ); sb.append( dumpModificationItems() ); break; - case DELETE : + case ChangeType.DELETE_ORDINAL : sb.append( " Change type is DELETE\n" ); break; - case MODDN : - case MODRDN : - sb.append( " Change type is ").append( changeType == MODDN ? "MODDN\n" : "MODRDN\n" ); + case ChangeType.MODDN_ORDINAL : + case ChangeType.MODRDN_ORDINAL : + sb.append( " Change type is ").append( changeType == ChangeType.ModDn ? "MODDN\n" : "MODRDN\n" ); sb.append( " Delete old RDN : " ).append( deleteOldRdn ? "true\n" : "false\n" ); sb.append( " New RDN : " ).append( newRdn ).append( '\n' ); Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=577180&r1=577179&r2=577180&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Wed Sep 19 00:18:50 2007 @@ -434,31 +434,31 @@ * The line which contains the changeType * @return The operation. */ - private int parseChangeType( String line ) + private ChangeType parseChangeType( String line ) { - int operation = Entry.ADD; + ChangeType operation = ChangeType.Add; String modOp = StringTools.trim( line.substring( "changetype:".length() + 1 ) ); if ( "add".equalsIgnoreCase( modOp ) ) { - operation = Entry.ADD; + operation = ChangeType.Add; } else if ( "delete".equalsIgnoreCase( modOp ) ) { - operation = Entry.DELETE; + operation = ChangeType.Delete; } else if ( "modify".equalsIgnoreCase( modOp ) ) { - operation = Entry.MODIFY; + operation = ChangeType.Modify; } else if ( "moddn".equalsIgnoreCase( modOp ) ) { - operation = Entry.MODDN; + operation = ChangeType.ModDn; } else if ( "modrdn".equalsIgnoreCase( modOp ) ) { - operation = Entry.MODRDN; + operation = ChangeType.ModRdn; } return operation; @@ -1094,19 +1094,19 @@ * The associated control, if any * @return A modification entry */ - private void parseChange( Entry entry, Iterator iter, int operation, Control control ) throws NamingException + private void parseChange( Entry entry, Iterator iter, ChangeType operation, Control control ) throws NamingException { // The changetype and operation has already been parsed. entry.setChangeType( operation ); - switch ( operation ) + switch ( operation.getChangeType() ) { - case Entry.DELETE: + case ChangeType.DELETE_ORDINAL: // The change type will tell that it's a delete operation, // the dn is used as a key. return; - case Entry.ADD: + case ChangeType.ADD_ORDINAL: // We will iterate through all attribute/value pairs while ( iter.hasNext() ) { @@ -1117,12 +1117,12 @@ return; - case Entry.MODIFY: + case ChangeType.MODIFY_ORDINAL: parseModify( entry, iter ); return; - case Entry.MODRDN:// They are supposed to have the same syntax ??? - case Entry.MODDN: + case ChangeType.MODRDN_ORDINAL:// They are supposed to have the same syntax ??? + case ChangeType.MODDN_ORDINAL: // First, parse the modrdn part parseModRdn( entry, iter ); @@ -1141,7 +1141,7 @@ } else { - if ( operation == Entry.MODDN ) + if ( operation == ChangeType.ModDn ) { log.error( "A moddn operation must contains a \"newsuperior:\"" ); throw new NamingException( "Bad moddn operation, no newsuperior" ); @@ -1150,7 +1150,7 @@ } else { - if ( operation == Entry.MODDN ) + if ( operation == ChangeType.ModDn ) { log.error( "A moddn operation must contains a \"newsuperior:\"" ); throw new NamingException( "Bad moddn operation, no newsuperior" ); @@ -1210,7 +1210,7 @@ // after a change operation boolean changeTypeSeen = false; - int operation = Entry.ADD; + ChangeType operation = ChangeType.Add; String lowerLine = null; Control control = null; @@ -1244,7 +1244,6 @@ // Parse the control control = parseControl( line.substring( "control:".length() ) ); entry.setControl( control ); - } else if ( lowerLine.startsWith( "changetype:" ) ) {