You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2010/06/13 02:39:22 UTC
svn commit: r954149 [1/2] - in /directory/shared/trunk/ldap-ldif/src:
main/java/org/apache/directory/shared/ldap/ldif/
test/java/org/apache/directory/shared/ldap/ldif/
Author: elecharny
Date: Sun Jun 13 00:39:22 2010
New Revision: 954149
URL: http://svn.apache.org/viewvc?rev=954149&view=rev
Log:
o Added a ChangeType.None type for LDIF entry which are content
o Fixed some missing functions in LdifEntry
o Added some tests for LdifReader
Modified:
directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java
directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifReaderTest.java
directory/shared/trunk/ldap-ldif/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java (original)
+++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/ChangeType.java Sun Jun 13 00:39:22 2010
@@ -33,7 +33,8 @@ public enum ChangeType
Modify( 1 ),
ModDn( 2 ),
ModRdn( 3 ),
- Delete( 4 );
+ Delete( 4 ),
+ None(-1);
/** Add ordinal value */
public static final int ADD_ORDINAL = 0;
@@ -50,6 +51,9 @@ public enum ChangeType
/** Delete ordinal value */
public static final int DELETE_ORDINAL = 4;
+ /** None ordinal value */
+ public static final int NONE_ORDINAL = -1;
+
/* the ordinal value for a change type */
private final int changeType;
@@ -79,6 +83,8 @@ public enum ChangeType
{
switch( val )
{
+ case -1: return None;
+
case 0: return Add;
case 1: return Modify;
Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original)
+++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Sun Jun 13 00:39:22 2010
@@ -28,7 +28,9 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
import org.apache.directory.shared.ldap.entry.DefaultEntry;
import org.apache.directory.shared.ldap.entry.DefaultModification;
import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
@@ -86,19 +88,19 @@ public class LdifEntry implements Clonea
private Entry entry;
- /** The control */
- private Control control;
+ /** The controls */
+ private Map<String, Control> controls;
/**
* Creates a new Entry object.
*/
public LdifEntry()
{
- changeType = ChangeType.Add; // Default LDIF content
+ changeType = ChangeType.None; // Default LDIF content
modificationList = new LinkedList<Modification>();
modificationItems = new HashMap<String, Modification>();
entry = new DefaultEntry( (DN)null );
- control = null;
+ controls = null;
}
@@ -312,8 +314,15 @@ public class LdifEntry implements Clonea
/**
* Get the change type
*
- * @return The change type. One of : ADD = 0; MODIFY = 1; MODDN = 2; MODRDN =
- * 3; DELETE = 4;
+ * @return The change type. One of :
+ * <ul>
+ * <li>ADD</li>
+ * <li>MODIFY</li>
+ * <li>MODDN</li>
+ * <li>MODRDN</li>
+ * <li>DELETE</li>
+ * <li>NONE</li>
+ * </ul>
*/
public ChangeType getChangeType()
{
@@ -447,6 +456,25 @@ public class LdifEntry implements Clonea
this.newSuperior = newSuperior;
}
+
+ /**
+ * @return True if there is this is a content ldif
+ */
+ public boolean isLdifContent()
+ {
+ return changeType == ChangeType.None;
+ }
+
+
+ /**
+ * @return True if there is this is a change ldif
+ */
+ public boolean isLdifChange()
+ {
+ return changeType != ChangeType.None;
+ }
+
+
/**
* @return True if the entry is an ADD entry
*/
@@ -454,6 +482,7 @@ public class LdifEntry implements Clonea
{
return changeType == ChangeType.Add;
}
+
/**
* @return True if the entry is a DELETE entry
@@ -463,6 +492,7 @@ public class LdifEntry implements Clonea
return changeType == ChangeType.Delete;
}
+
/**
* @return True if the entry is a MODDN entry
*/
@@ -471,6 +501,7 @@ public class LdifEntry implements Clonea
return changeType == ChangeType.ModDn;
}
+
/**
* @return True if the entry is a MODRDN entry
*/
@@ -479,6 +510,7 @@ public class LdifEntry implements Clonea
return changeType == ChangeType.ModRdn;
}
+
/**
* @return True if the entry is a MODIFY entry
*/
@@ -487,6 +519,7 @@ public class LdifEntry implements Clonea
return changeType == ChangeType.Modify;
}
+
/**
* Tells if the current entry is a added one
*
@@ -494,26 +527,64 @@ public class LdifEntry implements Clonea
*/
public boolean isEntry()
{
- return changeType == ChangeType.Add;
+ return ( changeType == ChangeType.None ) || ( changeType == ChangeType.Add );
+ }
+
+
+ /**
+ * @return true if the entry has some controls
+ */
+ public boolean hasControls()
+ {
+ return controls != null;
+ }
+
+
+ /**
+ * @return The set of controls for this entry
+ */
+ public Map<String, Control> getControls()
+ {
+ return controls;
}
+
/**
* @return The associated control, if any
*/
- public Control getControl()
+ public Control getControl( String oid )
{
- return control;
+ if ( controls != null )
+ {
+ return controls.get( oid );
+ }
+
+ return null;
}
/**
* Add a control to the entry
*
- * @param control
- * The control
+ * @param control The added control
*/
- public void setControl( Control control )
+ public void addControl( Control control )
{
- this.control = control;
+ if ( control == null )
+ {
+ throw new IllegalArgumentException( "The added control must not be null" );
+ }
+
+ if ( changeType == ChangeType.None )
+ {
+ changeType = ChangeType.Add;
+ }
+
+ if ( controls == null )
+ {
+ controls = new ConcurrentHashMap<String, Control>();
+ }
+
+ controls.put( control.getOid(), control );
}
/**
@@ -640,9 +711,12 @@ public class LdifEntry implements Clonea
}
}
- if ( control != null )
+ if ( controls != null )
{
- result = result * 17 + control.hashCode();
+ for ( String control : controls.keySet() )
+ {
+ result = result * 17 + control.hashCode();
+ }
}
return result;
@@ -796,13 +870,53 @@ public class LdifEntry implements Clonea
break; // do nothing
}
- if ( control != null )
+ if ( controls != null )
{
- return control.equals( otherEntry.control );
+ Map<String, Control> otherControls = otherEntry.controls;
+
+ if ( otherControls == null )
+ {
+ return false;
+ }
+
+ if ( controls.size() != otherControls.size() )
+ {
+ return false;
+ }
+
+ for ( String controlOid : controls.keySet() )
+ {
+ if ( !otherControls.containsKey( controlOid ) )
+ {
+ return false;
+ }
+
+ Control thisControl = controls.get( controlOid );
+ Control otherControl = otherControls.get( controlOid );
+
+ if ( thisControl == null )
+ {
+ if ( otherControl != null )
+ {
+ return false;
+ }
+
+ continue;
+ }
+ else
+ {
+ if ( !thisControl.equals( otherControl ) )
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
}
else
{
- return otherEntry.control == null;
+ return otherEntry.controls == null;
}
}
@@ -865,8 +979,37 @@ public class LdifEntry implements Clonea
if ( in.available() > 0 )
{
- // We have a control
- control = (Control)in.readObject();
+ // We have at least a control
+ int nbControls = in.readInt();
+
+ if ( nbControls > 0 )
+ {
+ controls = new ConcurrentHashMap<String, Control>( nbControls );
+
+ for ( int i = 0; i < nbControls; i++ )
+ {
+ String controlOid = in.readUTF();
+ boolean isCritical = in.readBoolean();
+ boolean hasValue = in.readBoolean();
+ Control control = new ControlImpl(controlOid );
+ control.setCritical( isCritical );
+
+ if ( hasValue )
+ {
+ int valueLength = in.readInt();
+ byte[] value = new byte[valueLength];
+
+ if ( valueLength > 0 )
+ {
+ in.read( value );
+ }
+
+ control.setValue( value );
+ }
+
+ controls.put( controlOid, control );
+ }
+ }
}
}
@@ -937,11 +1080,28 @@ public class LdifEntry implements Clonea
break;
}
- if ( control != null )
+ // The controls
+ if ( controls != null )
{
// Write the control
- out.writeObject( control );
+ out.writeInt( controls.size() );
+ for ( Control control : controls.values() )
+ {
+ UTFUtils.writeUTF( out, control.getOid() );
+ out.writeBoolean( control.isCritical() );
+ out.writeBoolean( control.hasValue() );
+
+ if ( control.hasValue() )
+ {
+ out.writeInt( control.getValue().length );
+
+ if ( control.getValue().length > 0 )
+ {
+ out.write( control.getValue() );
+ }
+ }
+ }
}
// and flush the result
Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original)
+++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Sun Jun 13 00:39:22 2010
@@ -1322,7 +1322,7 @@ public class LdifReader implements Itera
// Parse the control
control = parseControl( line.substring( "control:".length() ) );
- entry.setControl( control );
+ entry.addControl( control );
}
else if ( lowerLine.startsWith( "changetype:" ) )
{
Modified: directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=954149&r1=954148&r2=954149&view=diff
==============================================================================
--- directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/trunk/ldap-ldif/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Sun Jun 13 00:39:22 2010
@@ -32,6 +32,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.exception.LdapException;
import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.control.Control;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.Base64;
@@ -344,21 +345,41 @@ public class LdifUtils
// Dump the ChangeType
String changeType = entry.getChangeType().toString().toLowerCase();
- if ( entry.getChangeType() != ChangeType.Modify )
+ if ( entry.getChangeType() != ChangeType.None )
{
+ // First dump the controls if any
+ if ( entry.hasControls() )
+ {
+ for ( Control control : entry.getControls().values() )
+ {
+ StringBuilder controlStr = new StringBuilder();
+
+ controlStr.append( "control: " ).append( control.getOid() );
+ controlStr.append( " " ).append( control.isCritical() );
+
+ if ( control.hasValue() )
+ {
+ controlStr.append( "::" ).append( Base64.encode( control.getValue() ) );
+ }
+
+ sb.append( stripLineToNChars( controlStr.toString(), length ) );
+ sb.append( '\n' );
+ }
+ }
+
sb.append( stripLineToNChars( "changetype: " + changeType, length ) );
sb.append( '\n' );
}
switch ( entry.getChangeType() )
{
- case Delete :
- if ( entry.getEntry() != null )
+ case None :
+ if ( entry.hasControls() )
{
- throw new LdapException( I18n.err( I18n.ERR_12081 ) );
+ sb.append( stripLineToNChars( "changetype: " + ChangeType.Add, length ) );
}
- break;
+ // Fallthrough
case Add :
if ( ( entry.getEntry() == null ) )
@@ -373,6 +394,14 @@ public class LdifUtils
}
break;
+
+ case Delete :
+ if ( entry.getEntry() != null )
+ {
+ throw new LdapException( I18n.err( I18n.ERR_12081 ) );
+ }
+
+ break;
case ModDn :
case ModRdn :