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 2008/08/15 01:12:13 UTC
svn commit: r686082 [5/7] - in /directory:
apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/
apacheds/branches/bigbang/c...
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/ClientStringValue.java Thu Aug 14 16:12:09 2008
@@ -309,8 +309,23 @@
*/
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
- // TODO implement this method
- return;
+ // Read the wrapped value, if it's not null
+ if ( in.readBoolean() )
+ {
+ wrapped = in.readUTF();
+ }
+
+ // Read the isNormalized flag
+ normalized = in.readBoolean();
+
+ if ( normalized )
+ {
+ // Read the normalized value, if not null
+ if ( in.readBoolean() )
+ {
+ normalizedValue = in.readUTF();
+ }
+ }
}
@@ -319,7 +334,40 @@
*/
public void writeExternal( ObjectOutput out ) throws IOException
{
- // TODO Implement this method
+ // Write the wrapped value, if it's not null
+ if ( wrapped != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( wrapped );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ // Write the isNormalized flag
+ if ( normalized )
+ {
+ out.writeBoolean( true );
+
+ // Write the normalized value, if not null
+ if ( normalizedValue != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( normalizedValue );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ // and flush the data
+ out.flush();
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientAttribute.java Thu Aug 14 16:12:09 2008
@@ -19,6 +19,9 @@
package org.apache.directory.shared.ldap.entry.client;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -1359,4 +1362,77 @@
return sb.toString();
}
+
+
+ /**
+ * @see Externalizable#writeExternal(ObjectOutput)
+ * <p>
+ *
+ * This is the place where we serialize attributes, and all theirs
+ * elements.
+ *
+ * The inner structure is :
+ *
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException
+ {
+ // Write the UPId (the id will be deduced from the upID)
+ out.writeUTF( upId );
+
+ // Write the HR flag, if not null
+ if ( isHR != null )
+ {
+ out.writeBoolean( true );
+ out.writeBoolean( isHR );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ // Write the number of values
+ out.writeInt( size() );
+
+ if ( size() > 0 )
+ {
+ // Write each value
+ for ( Value<?> value:values )
+ {
+ // Write the value
+ out.writeObject( value );
+ }
+ }
+
+ out.flush();
+ }
+
+
+ /**
+ * @see Externalizable#readExternal(ObjectInput)
+ */
+ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+ {
+ // Read the ID and the UPId
+ upId = in.readUTF();
+
+ // Compute the id
+ setUpId( upId );
+
+ // Read the HR flag, if not null
+ if ( in.readBoolean() )
+ {
+ isHR = in.readBoolean();
+ }
+
+ // Read the number of values
+ int nbValues = in.readInt();
+
+ if ( nbValues > 0 )
+ {
+ for ( int i = 0; i < nbValues; i++ )
+ {
+ values.add( (Value<?>)in.readObject() );
+ }
+ }
+ }
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java Thu Aug 14 16:12:09 2008
@@ -19,7 +19,6 @@
package org.apache.directory.shared.ldap.entry.client;
-import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -53,7 +52,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public final class DefaultClientEntry extends AbstractEntry<String> implements ClientEntry, Externalizable
+public final class DefaultClientEntry extends AbstractEntry<String> implements ClientEntry
{
/** Used for serialization */
private static final long serialVersionUID = 2L;
@@ -71,6 +70,7 @@
*/
public DefaultClientEntry()
{
+ dn = LdapDN.EMPTY_LDAPDN;
}
@@ -935,20 +935,18 @@
* @see Externalizable#writeExternal(ObjectOutput)<p>
*
* This is the place where we serialize entries, and all theirs
- * elements. the reason why we don't call the underlying methods
- * (<code>ClientAttribute.write(), Value.write()</code>) is that we need
- * access to the registries to read back the values.
+ * elements.
* <p>
* The structure used to store the entry is the following :
- * <li><b>[DN length]</b> : can be -1 if we don't have a DN, 0 if the
- * DN is empty, otherwise contains the DN's length.<p>
- * <b>NOTE :</b>This should be unnecessary, as the DN should always exists
- * <p>
+ * <li>
+ * <b>[DN]</b> : If it's null, stores an empty DN
+ * </li>
+ * <li>
+ * <b>[attributes number]</b> : the number of attributes.
* </li>
* <li>
- * <b>DN</b> : The entry's DN. Can be empty (rootDSE=<p>
+ * <b>[attribute]*</b> : each attribute, if we have some
* </li>
- * We have to store the UPid, and all the values, if any.
*/
public void writeExternal( ObjectOutput out ) throws IOException
{
@@ -956,7 +954,7 @@
if ( dn == null )
{
// Write an empty DN
- LdapDN.EMPTY_LDAPDN.writeExternal( out );
+ out.writeObject( LdapDN.EMPTY_LDAPDN );
}
else
{
@@ -965,42 +963,14 @@
}
// Then the attributes.
- if ( attributes == null )
- {
- // A negative number denotes no attributes
- out.writeInt( -1 );
- }
- else
+ // Store the attributes' nulber first
+ out.writeInt( attributes.size() );
+
+ // Iterate through the keys.
+ for ( EntryAttribute attribute:attributes.values() )
{
- // Store the attributes' nulber first
- out.writeInt( attributes.size() );
-
- // Iterate through the keys. We store the Attribute
- // here, to be able to restore it in the readExternal :
- // we need access to the registries, which are not available
- // in the ClientAttribute class.
- for ( EntryAttribute attribute:attributes.values() )
- {
- // Store the UP id
- out.writeUTF( attribute.getUpId() );
-
- // The number of values
- int nbValues = attribute.size();
-
- if ( nbValues == 0 )
- {
- out.writeInt( 0 );
- }
- else
- {
- out.writeInt( nbValues );
-
- for ( Value<?> value:attribute )
- {
- out.writeObject( value );
- }
- }
- }
+ // Store the attribute
+ out.writeObject( attribute );
}
out.flush();
@@ -1013,28 +983,16 @@
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
// Read the DN
- LdapDN dn = (LdapDN)in.readObject();
+ dn = (LdapDN)in.readObject();
// Read the number of attributes
int nbAttributes = in.readInt();
- attributes = new HashMap<String, EntryAttribute>();
-
// Read the attributes
for ( int i = 0; i < nbAttributes; i++ )
{
- String upId = in.readUTF();
-
- EntryAttribute attribute = new DefaultClientAttribute( upId );
-
- // Read the number of values
- int nbValues = in.readInt();
-
- for ( int j = 0; j < nbValues; j++ )
- {
- Value<?> value = (Value<?>)in.readObject();
- attribute.add( value );
- }
+ // Read each attribute
+ EntryAttribute attribute = (DefaultClientAttribute)in.readObject();
attributes.put( attribute.getId(), attribute );
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifEntry.java Thu Aug 14 16:12:09 2008
@@ -20,24 +20,28 @@
package org.apache.directory.shared.ldap.ldif;
-import java.io.Serializable;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.naming.InvalidNameException;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
import javax.naming.ldap.Control;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientEntry;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -56,23 +60,20 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class LdifEntry implements Cloneable, Serializable
+public class LdifEntry implements Cloneable, Externalizable
{
private static final long serialVersionUID = 2L;
/** Used in toArray() */
- public static final ModificationItemImpl[] EMPTY_MODS = new ModificationItemImpl[0];
+ public static final Modification[] EMPTY_MODS = new Modification[0];
/** the change type */
private ChangeType changeType;
/** the modification item list */
- private List<ModificationItemImpl> modificationList;
+ private List<Modification> modificationList;
- private Map<String, ModificationItemImpl> modificationItems;
-
- /** the dn of the ldif entry */
- private String dn;
+ private Map<String, Modification> modificationItems;
/** The new superior */
private String newSuperior;
@@ -83,8 +84,8 @@
/** The delete old rdn flag */
private boolean deleteOldRdn;
- /** attributes of the entry */
- private Attributes attributes;
+ /** the entry */
+ private ClientEntry entry;
/** The control */
@@ -96,24 +97,38 @@
public LdifEntry()
{
changeType = ChangeType.Add; // Default LDIF content
- modificationList = new LinkedList<ModificationItemImpl>();
- modificationItems = new HashMap<String, ModificationItemImpl>();
- dn = null;
- attributes = new AttributesImpl( true );
+ modificationList = new LinkedList<Modification>();
+ modificationItems = new HashMap<String, Modification>();
+ entry = new DefaultClientEntry( null );
control = null;
}
+
+ /**
+ * Set the Distinguished Name
+ *
+ * @param dn
+ * The Distinguished Name
+ */
+ public void setDn( LdapDN dn )
+ {
+ entry.setDn( (LdapDN)dn.clone() );
+ }
+
+
/**
* Set the Distinguished Name
*
* @param dn
* The Distinguished Name
*/
- public void setDn( String dn )
+ public void setDn( String dn ) throws InvalidNameException
{
- this.dn = dn;
+ LdapDN ldapDn = new LdapDN( dn );
+ entry.setDn( ldapDn );
}
+
/**
* Set the modification type
*
@@ -161,12 +176,12 @@
*
* @param modification The modification to be added
*/
- public void addModificationItem( ModificationItemImpl modification )
+ public void addModificationItem( Modification modification )
{
if ( changeType == ChangeType.Modify )
{
modificationList.add( modification );
- modificationItems.put( modification.getAttribute().getID(), modification );
+ modificationItems.put( modification.getAttribute().getId(), modification );
}
}
@@ -178,13 +193,13 @@
*
* @param attr The attribute to be added
*/
- public void addModificationItem( int modOp, Attribute attr )
+ public void addModificationItem( int modOp, EntryAttribute attr )
{
if ( changeType == ChangeType.Modify )
{
- ModificationItemImpl item = new ModificationItemImpl( modOp, attr );
+ Modification item = new ClientModification( modOp, attr );
modificationList.add( item );
- modificationItems.put( attr.getID(), item );
+ modificationItems.put( attr.getId(), item );
}
}
@@ -203,9 +218,19 @@
{
if ( changeType == ChangeType.Modify )
{
- Attribute attr = new AttributeImpl( id, value );
+ EntryAttribute attr = null;
+
+ if ( value == null )
+ {
+ value = new ClientStringValue( null );
+ attr = new DefaultClientAttribute( id, (Value<?>)value );
+ }
+ else
+ {
+ attr = (EntryAttribute)value;
+ }
- ModificationItemImpl item = new ModificationItemImpl( modOp, attr );
+ Modification item = new ClientModification( modOp, attr );
modificationList.add( item );
modificationItems.put( id, item );
}
@@ -217,9 +242,9 @@
* @param attr
* The attribute to be added
*/
- public void addAttribute( Attribute attr )
+ public void addAttribute( EntryAttribute attr ) throws NamingException
{
- attributes.put( attr );
+ entry.put( attr );
}
/**
@@ -232,17 +257,15 @@
* The attribute value
*
*/
- public void addAttribute( String id, Object value )
+ public void addAttribute( String id, Object value ) throws NamingException
{
- Attribute attr = get( id );
-
- if ( attr != null )
+ if ( value instanceof String )
{
- attr.add( value );
+ entry.add( id, (String)value );
}
else
{
- attributes.put( id, value );
+ entry.add( id, (byte[])value );
}
}
@@ -256,17 +279,15 @@
* The attribute value
*
*/
- public void putAttribute( String id, Object value )
+ public void putAttribute( String id, Object value ) throws NamingException
{
- Attribute attribute = attributes.get( id );
-
- if ( attribute != null )
+ if ( value instanceof String )
{
- attribute.add( value );
+ entry.add( id, (String)value );
}
else
{
- attributes.put( id, value );
+ entry.add( id, (byte[])value );
}
}
@@ -284,7 +305,7 @@
/**
* @return The list of modification items
*/
- public List<ModificationItemImpl> getModificationItems()
+ public List<Modification> getModificationItems()
{
return modificationList;
}
@@ -295,7 +316,7 @@
*
* @return modification items as an array.
*/
- public ModificationItemImpl[] getModificationItemsArray()
+ public Modification[] getModificationItemsArray()
{
return modificationList.toArray( EMPTY_MODS );
}
@@ -304,9 +325,9 @@
/**
* @return The entry Distinguished name
*/
- public String getDn()
+ public LdapDN getDn()
{
- return dn;
+ return entry.getDn();
}
/**
@@ -324,26 +345,26 @@
* The attribute Id
* @return The attribute if it exists
*/
- public Attribute get( String attributeId )
+ public EntryAttribute get( String attributeId )
{
if ( "dn".equalsIgnoreCase( attributeId ) )
{
- return new AttributeImpl( "dn", dn );
+ return new DefaultClientAttribute( "dn", entry.getDn().getUpName() );
}
- return attributes.get( attributeId );
+ return entry.get( attributeId );
}
/**
- * Get the entry's attributes
+ * Get the entry's entry
*
- * @return An Attributes
+ * @return the stored Entry
*/
- public Attributes getAttributes()
+ public Entry getEntry()
{
if ( isEntry() )
{
- return attributes;
+ return entry;
}
else
{
@@ -488,10 +509,10 @@
if ( modificationList != null )
{
- for ( ModificationItemImpl modif:modificationList )
+ for ( Modification modif:modificationList )
{
- ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(),
- (Attribute) modif.getAttribute().clone() );
+ Modification modifClone = new ClientModification( modif.getOperation(),
+ (EntryAttribute) modif.getAttribute().clone() );
clone.modificationList.add( modifClone );
}
}
@@ -500,17 +521,17 @@
{
for ( String key:modificationItems.keySet() )
{
- ModificationItemImpl modif = modificationItems.get( key );
- ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(),
- (Attribute) modif.getAttribute().clone() );
+ Modification modif = modificationItems.get( key );
+ Modification modifClone = new ClientModification( modif.getOperation(),
+ (EntryAttribute) modif.getAttribute().clone() );
clone.modificationItems.put( key, modifClone );
}
}
- if ( attributes != null )
+ if ( entry != null )
{
- clone.attributes = (Attributes)attributes.clone();
+ clone.entry = (ClientEntry)entry.clone();
}
return clone;
@@ -523,42 +544,29 @@
private String dumpAttributes()
{
StringBuffer sb = new StringBuffer();
- Attribute attribute = null;
- try
+ for ( EntryAttribute attribute:entry )
{
- for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll();
- attrs.hasMoreElements(); )
+ if ( attribute == null )
{
- attribute = attrs.nextElement();
- if ( attribute == null )
+ sb.append( " Null attribute\n" );
+ continue;
+ }
+
+ sb.append( " ").append( attribute.getId() ).append( ":\n" );
+
+ for ( Value<?> value:attribute )
+ {
+ if ( value instanceof ClientStringValue )
{
- sb.append( " Null attribute\n" );
- continue;
+ sb.append( " " ).append( value.get() ).append('\n' );
}
-
- sb.append( " ").append( attribute.getID() ).append( ":\n" );
- Object value = null;
-
- for ( NamingEnumeration<?> values = attribute.getAll();
- values.hasMoreElements(); )
+ else
{
- value = values.nextElement();
- if ( value instanceof String )
- {
- sb.append( " " ).append( (String)value ).append('\n' );
- }
- else
- {
- sb.append( " " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
- }
+ sb.append( " " ).append( StringTools.dumpBytes( (byte[])value.get() ) ).append('\n' );
}
}
}
- catch ( NamingException ne )
- {
- return "";
- }
return sb.toString();
}
@@ -571,21 +579,21 @@
{
StringBuffer sb = new StringBuffer();
- for ( ModificationItemImpl modif:modificationList )
+ for ( Modification modif:modificationList )
{
sb.append( " Operation: " );
- switch ( modif.getModificationOp() )
+ switch ( modif.getOperation() )
{
- case DirContext.ADD_ATTRIBUTE :
+ case ADD_ATTRIBUTE :
sb.append( "ADD\n" );
break;
- case DirContext.REMOVE_ATTRIBUTE :
+ case REMOVE_ATTRIBUTE :
sb.append( "REMOVE\n" );
break;
- case DirContext.REPLACE_ATTRIBUTE :
+ case REPLACE_ATTRIBUTE :
sb.append( "REPLACE \n" );
break;
@@ -593,32 +601,22 @@
break; // Do nothing
}
- Attribute attribute = modif.getAttribute();
+ EntryAttribute attribute = modif.getAttribute();
- sb.append( " Attribute: " ).append( attribute.getID() ).append( '\n' );
+ sb.append( " Attribute: " ).append( attribute.getId() ).append( '\n' );
if ( attribute.size() != 0 )
{
- try
+ for ( Value<?> value:attribute )
{
- Object value = null;
- for ( NamingEnumeration<?> values = attribute.getAll();
- values.hasMoreElements(); )
+ if ( value instanceof ClientStringValue )
{
- value = values.nextElement();
- if ( value instanceof String )
- {
- sb.append( " " ).append( (String)value ).append('\n' );
- }
- else
- {
- sb.append( " " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
- }
+ sb.append( " " ).append( (String)value.get() ).append('\n' );
+ }
+ else
+ {
+ sb.append( " " ).append( StringTools.dumpBytes( (byte[]) value.get() ) ).append('\n' );
}
- }
- catch ( NamingException ne )
- {
- return "";
}
}
}
@@ -633,7 +631,18 @@
public String toString()
{
StringBuffer sb = new StringBuffer();
- sb.append( "Entry : " ).append( dn ).append( '\n' );
+ sb.append( "Entry : " );
+
+ if ( entry.getDn() == null )
+ {
+ sb.append( "" );
+ }
+ else
+ {
+ sb.append( entry.getDn().getUpName() ).append( '\n' );
+ }
+
+ sb.append( '\n' );
if ( control != null )
{
@@ -688,9 +697,9 @@
{
int result = 37;
- if ( dn != null )
+ if ( entry.getDn() != null )
{
- result = result*17 + dn.hashCode();
+ result = result*17 + entry.getDn().hashCode();
}
if ( changeType != null )
@@ -702,9 +711,9 @@
{
case Add :
// Checks the attributes
- if ( attributes != null )
+ if ( entry != null )
{
- result = result * 17 + attributes.hashCode();
+ result = result * 17 + entry.hashCode();
}
break;
@@ -718,7 +727,7 @@
{
result = result * 17 + modificationList.hashCode();
- for ( ModificationItem modification:modificationList )
+ for ( Modification modification:modificationList )
{
result = result * 17 + modification.hashCode();
}
@@ -777,26 +786,20 @@
return false;
}
- LdifEntry entry = (LdifEntry)o;
+ LdifEntry otherEntry = (LdifEntry)o;
// Check the DN
- try
- {
- LdapDN thisDn = new LdapDN( dn );
- LdapDN dnEntry = new LdapDN( entry.dn );
-
- if ( !thisDn.equals( dnEntry ) )
- {
- return false;
- }
- }
- catch ( InvalidNameException ine )
+ LdapDN thisDn = entry.getDn();
+ LdapDN dnEntry = otherEntry.getDn();
+
+ if ( !thisDn.equals( dnEntry ) )
{
return false;
}
+
// Check the changeType
- if ( changeType != entry.changeType )
+ if ( changeType != otherEntry.changeType )
{
return false;
}
@@ -806,9 +809,9 @@
{
case Add :
// Checks the attributes
- if ( attributes == null )
+ if ( entry == null )
{
- if ( entry.attributes != null )
+ if ( otherEntry.entry != null )
{
return false;
}
@@ -818,17 +821,17 @@
}
}
- if ( entry.attributes == null )
+ if ( otherEntry.entry == null )
{
return false;
}
- if ( attributes.size() != entry.attributes.size() )
+ if ( entry.size() != otherEntry.entry.size() )
{
return false;
}
- if ( !attributes.equals( entry.attributes ) )
+ if ( !entry.equals( otherEntry.entry ) )
{
return false;
}
@@ -836,7 +839,7 @@
break;
case Delete :
- // Nothing to do, is the DNs are equals
+ // Nothing to do, if the DNs are equals
break;
case Modify :
@@ -845,7 +848,7 @@
// First, deal with special cases
if ( modificationList == null )
{
- if ( entry.modificationList != null )
+ if ( otherEntry.modificationList != null )
{
return false;
}
@@ -855,12 +858,12 @@
}
}
- if ( entry.modificationList == null )
+ if ( otherEntry.modificationList == null )
{
return false;
}
- if ( modificationList.size() != entry.modificationList.size() )
+ if ( modificationList.size() != otherEntry.modificationList.size() )
{
return false;
}
@@ -868,9 +871,9 @@
// Now, compares the contents
int i = 0;
- for ( ModificationItemImpl modification:modificationList )
+ for ( Modification modification:modificationList )
{
- if ( ! modification.equals( entry.modificationList.get( i ) ) )
+ if ( ! modification.equals( otherEntry.modificationList.get( i ) ) )
{
return false;
}
@@ -883,7 +886,7 @@
case ModDn :
case ModRdn :
// Check the deleteOldRdn flag
- if ( deleteOldRdn != entry.deleteOldRdn )
+ if ( deleteOldRdn != otherEntry.deleteOldRdn )
{
return false;
}
@@ -892,7 +895,7 @@
try
{
Rdn thisNewRdn = new Rdn( newRdn );
- Rdn entryNewRdn = new Rdn( entry.newRdn );
+ Rdn entryNewRdn = new Rdn( otherEntry.newRdn );
if ( !thisNewRdn.equals( entryNewRdn ) )
{
@@ -908,7 +911,7 @@
try
{
LdapDN thisNewSuperior = new LdapDN( newSuperior );
- LdapDN entryNewSuperior = new LdapDN( entry.newSuperior );
+ LdapDN entryNewSuperior = new LdapDN( otherEntry.newSuperior );
if ( ! thisNewSuperior.equals( entryNewSuperior ) )
{
@@ -928,11 +931,153 @@
if ( control != null )
{
- return control.equals( entry.control );
+ return control.equals( otherEntry.control );
}
else
{
- return entry.control == null;
+ return otherEntry.control == null;
+ }
+ }
+
+
+ /**
+ * @see Externalizable#readExternal(ObjectInput)
+ *
+ * @param in The stream from which the LdifEntry is read
+ * @throws IOException If the stream can't be read
+ * @throws ClassNotFoundException If the LdifEntry can't be created
+ */
+ public void readExternal( ObjectInput in ) throws IOException , ClassNotFoundException
+ {
+ // Read the changeType
+ int type = in.readInt();
+ changeType = ChangeType.getChangeType( type );
+ entry = (ClientEntry)in.readObject();
+
+ switch ( changeType )
+ {
+ case Add :
+ // Fallback
+ case Delete :
+ // we don't have anything to read, but the control
+ break;
+
+ case ModDn :
+ // Fallback
+ case ModRdn :
+ deleteOldRdn = in.readBoolean();
+
+ if ( in.readBoolean() )
+ {
+ newRdn = in.readUTF();
+ }
+
+ if ( in.readBoolean() )
+ {
+ newSuperior = in.readUTF();
+ }
+
+ break;
+
+ case Modify :
+ // Read the modification
+ int nbModifs = in.readInt();
+
+
+ for ( int i = 0; i < nbModifs; i++ )
+ {
+ int operation = in.readInt();
+ String modStr = in.readUTF();
+ DefaultClientAttribute value = (DefaultClientAttribute)in.readObject();
+
+ addModificationItem( operation, modStr, value );
+ }
+
+ break;
+ }
+
+ if ( in.available() > 0 )
+ {
+ // We have a control
+ control = (Control)in.readObject();
}
}
+
+
+ /**
+ * @see Externalizable#readExternal(ObjectInput)<p>
+ *
+ *@param out The stream in which the ChangeLogEvent will be serialized.
+ *
+ *@throws IOException If the serialization fail
+ */
+ public void writeExternal( ObjectOutput out ) throws IOException
+ {
+ // Write the changeType
+ out.writeInt( changeType.getChangeType() );
+
+ // Write the entry
+ out.writeObject( entry );
+
+ // Write the data
+ switch ( changeType )
+ {
+ case Add :
+ // Fallback
+ case Delete :
+ // we don't have anything to write, but the control
+ break;
+
+ case ModDn :
+ // Fallback
+ case ModRdn :
+ out.writeBoolean( deleteOldRdn );
+
+ if ( newRdn != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( newRdn );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ if ( newSuperior != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( newSuperior );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+ break;
+
+ case Modify :
+ // Read the modification
+ out.writeInt( modificationList.size() );
+
+ for ( Modification modification:modificationList )
+ {
+ out.writeInt( modification.getOperation().getValue() );
+ out.writeUTF( modification.getAttribute().getId() );
+
+ EntryAttribute attribute = modification.getAttribute();
+ out.writeObject( attribute );
+ }
+
+ break;
+ }
+
+ if ( control != null )
+ {
+ // Write the control
+ out.writeObject( control );
+
+ }
+
+ // and flush the result
+ out.flush();
+ }
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Thu Aug 14 16:12:09 2008
@@ -47,7 +47,10 @@
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.LdapDnParser;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.Base64;
@@ -985,7 +988,7 @@
int state = MOD_SPEC;
String modified = null;
int modificationType = 0;
- Attribute attribute = null;
+ EntryAttribute attribute = null;
// The following flag is used to deal with empty modifications
boolean isEmptyValue = true;
@@ -1030,7 +1033,7 @@
modified = StringTools.trim( line.substring( "add:".length() ) );
modificationType = DirContext.ADD_ATTRIBUTE;
- attribute = new AttributeImpl( modified );
+ attribute = new DefaultClientAttribute( modified );
state = ATTRVAL_SPEC;
}
@@ -1044,7 +1047,7 @@
modified = StringTools.trim( line.substring( "delete:".length() ) );
modificationType = DirContext.REMOVE_ATTRIBUTE;
- attribute = new AttributeImpl( modified );
+ attribute = new DefaultClientAttribute( modified );
state = ATTRVAL_SPEC_OR_SEP;
}
@@ -1058,7 +1061,7 @@
modified = StringTools.trim( line.substring( "replace:".length() ) );
modificationType = DirContext.REPLACE_ATTRIBUTE;
- attribute = new AttributeImpl( modified );
+ attribute = new DefaultClientAttribute( modified );
state = ATTRVAL_SPEC_OR_SEP;
}
@@ -1090,7 +1093,14 @@
Object attributeValue = parseValue( line, colonIndex );
- attribute.add( attributeValue );
+ if ( attributeValue instanceof String )
+ {
+ attribute.add( (String)attributeValue );
+ }
+ else
+ {
+ attribute.add( (byte[])attributeValue );
+ }
isEmptyValue = false;
@@ -1221,7 +1231,9 @@
// The entry must start with a dn: or a dn::
String line = lines.get( 0 );
- String dn = parseDn( line );
+ String name = parseDn( line );
+
+ LdapDN dn = new LdapDN( name );
// Ok, we have found a DN
LdifEntry entry = new LdifEntry();
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Thu Aug 14 16:12:09 2008
@@ -24,15 +24,19 @@
import java.util.ArrayList;
import java.util.List;
-import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -84,6 +88,7 @@
LDIF_SAFE_OTHER_CHARS_ALPHABET[13] = false; // 13 (CR)
}
+
/**
* Checks if the input String contains only safe values, that is, the data
* does not need to be encoded for use with LDIF. The rules for checking safety
@@ -112,6 +117,12 @@
*/
public static boolean isLDIFSafe( String str )
{
+ if ( str == null )
+ {
+ // A null string is LDIF safe
+ return true;
+ }
+
// Checking the first char
char currentChar = str.charAt(0);
@@ -135,6 +146,7 @@
return ( currentChar != ' ' );
}
+
/**
* Convert an Attributes as LDIF
* @param attrs the Attributes to convert
@@ -143,6 +155,54 @@
*/
public static String convertToLdif( Attributes attrs ) throws NamingException
{
+ return convertToLdif( AttributeUtils.toClientEntry( attrs, null ), DEFAULT_LINE_LENGTH );
+ }
+
+
+ /**
+ * Convert an Attributes as LDIF
+ * @param attrs the Attributes to convert
+ * @return the corresponding LDIF code as a String
+ * @throws NamingException If a naming exception is encountered.
+ */
+ public static String convertToLdif( Attributes attrs, int length ) throws NamingException
+ {
+ return convertToLdif( AttributeUtils.toClientEntry( attrs, null ), length );
+ }
+
+
+ /**
+ * Convert an Attributes as LDIF
+ * @param attrs the Attributes to convert
+ * @return the corresponding LDIF code as a String
+ * @throws NamingException If a naming exception is encountered.
+ */
+ public static String convertToLdif( Attributes attrs, LdapDN dn, int length ) throws NamingException
+ {
+ return convertToLdif( AttributeUtils.toClientEntry( attrs, dn ), length );
+ }
+
+
+ /**
+ * Convert an Attributes as LDIF
+ * @param attrs the Attributes to convert
+ * @return the corresponding LDIF code as a String
+ * @throws NamingException If a naming exception is encountered.
+ */
+ public static String convertToLdif( Attributes attrs, LdapDN dn ) throws NamingException
+ {
+ return convertToLdif( AttributeUtils.toClientEntry( attrs, dn ), DEFAULT_LINE_LENGTH );
+ }
+
+
+ /**
+ * Convert an Entry as LDIF
+ * @param attrs the Entry to convert
+ * @return the corresponding LDIF code as a String
+ * @throws NamingException If a naming exception is encountered.
+ */
+ public static String convertToLdif( Entry attrs ) throws NamingException
+ {
return convertToLdif( attrs, DEFAULT_LINE_LENGTH );
}
@@ -161,32 +221,27 @@
return reader.parseAttributes( ldif );
}
+
/**
- * Convert an Attributes as LDIF
- * @param attrs the Attributes to convert
+ * Convert an Entry as LDIF
+ * @param entry the Entry to convert
* @param length the expected line length
* @return the corresponding LDIF code as a String
* @throws NamingException If a naming exception is encountered.
*/
- public static String convertToLdif( Attributes attrs, int length ) throws NamingException
+ public static String convertToLdif( Entry entry, int length ) throws NamingException
{
StringBuilder sb = new StringBuilder();
- NamingEnumeration<? extends Attribute> ne = attrs.getAll();
-
- while ( ne.hasMore() )
+ for ( EntryAttribute attribute:entry )
{
- Object attribute = ne.next();
-
- if ( attribute instanceof Attribute )
- {
- sb.append( convertToLdif( (Attribute) attribute, length ) );
- }
+ sb.append( convertToLdif( attribute, length ) );
}
return sb.toString();
}
+
/**
* Convert an Entry to LDIF
* @param entry the entry to convert
@@ -210,13 +265,13 @@
StringBuilder sb = new StringBuilder();
// First, dump the DN
- if ( isLDIFSafe( entry.getDn() ) )
+ if ( isLDIFSafe( entry.getDn().getUpName() ) )
{
sb.append( stripLineToNChars( "dn: " + entry.getDn(), length ) );
}
else
{
- sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn() ), length ) );
+ sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getUpName() ), length ) );
}
sb.append( '\n' );
@@ -229,7 +284,7 @@
switch ( entry.getChangeType() )
{
case Delete :
- if ( entry.getAttributes() != null )
+ if ( entry.getEntry() != null )
{
throw new NamingException( "Invalid Entry : a deleted entry should not contain attributes" );
}
@@ -237,18 +292,14 @@
break;
case Add :
- if ( ( entry.getAttributes() == null ) )
+ if ( ( entry.getEntry() == null ) )
{
throw new NamingException( "Invalid Entry : a added or modified entry should contain attributes" );
}
// Now, iterate through all the attributes
- NamingEnumeration<? extends Attribute> ne = entry.getAttributes().getAll();
-
- while ( ne.hasMore() )
+ for ( EntryAttribute attribute:entry.getEntry() )
{
- Attribute attribute = ne.next();
-
sb.append( convertToLdif( attribute, length ) );
}
@@ -256,7 +307,7 @@
case ModDn :
case ModRdn :
- if ( entry.getAttributes() != null )
+ if ( entry.getEntry() != null )
{
throw new NamingException( "Invalid Entry : a modifyDN operation entry should not contain attributes" );
}
@@ -278,30 +329,30 @@
// Stores the optional newSuperior
if ( ! StringTools.isEmpty( entry.getNewSuperior() ) )
{
- Attribute newSuperior = new AttributeImpl( "newsuperior", entry.getNewSuperior() );
+ EntryAttribute newSuperior = new DefaultClientAttribute( "newsuperior", entry.getNewSuperior() );
sb.append( convertToLdif( newSuperior, length ) );
}
// Stores the new RDN
- Attribute newRdn = new AttributeImpl( "newrdn", entry.getNewRdn() );
+ EntryAttribute newRdn = new DefaultClientAttribute( "newrdn", entry.getNewRdn() );
sb.append( convertToLdif( newRdn, length ) );
break;
case Modify :
- for ( ModificationItem modification:entry.getModificationItems() )
+ for ( Modification modification:entry.getModificationItems() )
{
- switch ( modification.getModificationOp() )
+ switch ( modification.getOperation() )
{
- case DirContext.ADD_ATTRIBUTE :
+ case ADD_ATTRIBUTE :
sb.append( "add: " );
break;
- case DirContext.REMOVE_ATTRIBUTE :
+ case REMOVE_ATTRIBUTE :
sb.append( "delete: " );
break;
- case DirContext.REPLACE_ATTRIBUTE :
+ case REPLACE_ATTRIBUTE :
sb.append( "replace: " );
break;
@@ -310,7 +361,7 @@
}
- sb.append( modification.getAttribute().getID() );
+ sb.append( modification.getAttribute().getId() );
sb.append( '\n' );
sb.append( convertToLdif( modification.getAttribute() ) );
@@ -352,61 +403,63 @@
/**
- * Converts an Attribute as LDIF
- * @param attr the Attribute to convert
+ * Converts an EntryAttribute to LDIF
+ * @param attr the >EntryAttribute to convert
* @return the corresponding LDIF code as a String
* @throws NamingException If a naming exception is encountered.
*/
- public static String convertToLdif( Attribute attr ) throws NamingException
+ public static String convertToLdif( EntryAttribute attr ) throws NamingException
{
return convertToLdif( attr, DEFAULT_LINE_LENGTH );
}
/**
- * Converts an Attribute as LDIF
- * @param attr the Attribute to convert
+ * Converts an EntryAttribute as LDIF
+ * @param attr the EntryAttribute to convert
* @param length the expected line length
* @return the corresponding LDIF code as a String
* @throws NamingException If a naming exception is encountered.
*/
- public static String convertToLdif( Attribute attr, int length ) throws NamingException
+ public static String convertToLdif( EntryAttribute attr, int length ) throws NamingException
{
StringBuilder sb = new StringBuilder();
- // iterating on the attribute's values
- for ( int i = 0; i < attr.size(); i++ )
+ for ( Value<?> value:attr )
{
StringBuilder lineBuffer = new StringBuilder();
- lineBuffer.append( attr.getID() );
-
- Object value = attr.get( i );
+ lineBuffer.append( attr.getId() );
// First, deal with null value (which is valid)
if ( value == null )
{
lineBuffer.append( ':' );
}
- else if ( value instanceof byte[] )
+ else if ( value instanceof ClientBinaryValue )
{
// It is binary, so we have to encode it using Base64 before adding it
- char[] encoded = Base64.encode( ( byte[] ) value );
+ char[] encoded = Base64.encode( ( byte[] ) value.get() );
lineBuffer.append( ":: " + new String( encoded ) );
}
- else if ( value instanceof String )
+ else if ( value instanceof ClientStringValue )
{
// It's a String but, we have to check if encoding isn't required
- String str = (String) value;
+ String str = (String) value.get();
if ( !LdifUtils.isLDIFSafe( str ) )
{
- lineBuffer.append( ":: " + encodeBase64( (String)value ) );
+ lineBuffer.append( ":: " + encodeBase64( str ) );
}
else
{
- lineBuffer.append( ": " + value );
+ lineBuffer.append( ":" );
+
+ if ( str != null)
+ {
+ lineBuffer.append( " " ).append( str );
+ }
}
}
@@ -488,7 +541,7 @@
{
LdifEntry entry = new LdifEntry();
entry.setChangeType( ChangeType.Delete );
- entry.setDn( dn.getUpName() );
+ entry.setDn( dn );
return entry;
}
@@ -501,17 +554,16 @@
* @param deletedEntry The entry which has been deleted
* @return A reverse LDIF
*/
- public static LdifEntry reverseDel( LdapDN dn, Attributes deletedEntry )
+ public static LdifEntry reverseDel( LdapDN dn, Entry deletedEntry ) throws NamingException
{
LdifEntry entry = new LdifEntry();
- entry.setDn( dn.getUpName() );
+ entry.setDn( dn );
entry.setChangeType( ChangeType.Add );
- NamingEnumeration<? extends Attribute> attributes = deletedEntry.getAll();
- while ( attributes.hasMoreElements() )
+ for ( EntryAttribute attribute:deletedEntry )
{
- entry.addAttribute( attributes.nextElement() );
+ entry.addAttribute( attribute );
}
return entry;
@@ -556,7 +608,7 @@
newDn.add( modifiedDn.getRdn() );
entry.setChangeType( ChangeType.ModDn );
- entry.setDn( newDn.getUpName() );
+ entry.setDn( newDn );
entry.setNewSuperior( currentParent.getUpName() );
entry.setDeleteOldRdn( false );
return entry;
@@ -601,7 +653,7 @@
entry.setChangeType( ChangeType.ModRdn );
entry.setDeleteOldRdn( reverseDoDeleteOldRdn( t0, t1_rdn ) );
- entry.setDn( newDn.getUpName() );
+ entry.setDn( newDn );
entry.setNewRdn( t0_dn.getRdn().getUpName() );
return entry;
}
@@ -670,7 +722,7 @@
LdapDN reverseDn = ( LdapDN ) t1_parentDn.clone();
reverseDn.add( t1_rdn );
- reverse.setDn( reverseDn.getUpName() );
+ reverse.setDn( reverseDn );
reverse.setNewSuperior( reverseNewSuperiorDn.getUpName() );
reverse.setNewRdn( reverseNewRdn.getUpName() );
reverse.setChangeType( ChangeType.ModRdn );
@@ -730,46 +782,46 @@
* @return A reversed LDIF
* @throws NamingException If something went wrong
*/
- public static LdifEntry reverseModify( LdapDN dn, List<ModificationItemImpl> forwardModifications,
- Attributes modifiedEntry ) throws NamingException
+ public static LdifEntry reverseModify( LdapDN dn, List<Modification> forwardModifications,
+ Entry modifiedEntry ) throws NamingException
{
// First, protect the original entry by cloning it : we will modify it
- Attributes clonedEntry = ( Attributes ) modifiedEntry.clone();
+ Entry clonedEntry = ( Entry ) modifiedEntry.clone();
LdifEntry entry = new LdifEntry();
entry.setChangeType( ChangeType.Modify );
- entry.setDn( dn.getUpName() );
+ entry.setDn( dn );
// As the reversed modifications should be pushed in reversed order,
// we create a list to temporarily store the modifications.
- List<ModificationItemImpl> reverseModifications = new ArrayList<ModificationItemImpl>();
+ List<Modification> reverseModifications = new ArrayList<Modification>();
// Loop through all the modifications. For each modification, we will
// have to apply it to the modified entry in order to be able to generate
// the reversed modification
- for ( ModificationItem modification : forwardModifications )
+ for ( Modification modification : forwardModifications )
{
- switch ( modification.getModificationOp() )
+ switch ( modification.getOperation() )
{
- case DirContext.ADD_ATTRIBUTE :
- Attribute mod = modification.getAttribute();
+ case ADD_ATTRIBUTE :
+ EntryAttribute mod = modification.getAttribute();
- Attribute previous = modifiedEntry.get( mod.getID() );
+ EntryAttribute previous = modifiedEntry.get( mod.getId() );
if ( mod.equals( previous ) )
{
continue;
}
- ModificationItemImpl reverseModification = new ModificationItemImpl( DirContext.REMOVE_ATTRIBUTE, mod );
+ Modification reverseModification = new ClientModification( ModificationOperation.REMOVE_ATTRIBUTE, mod );
reverseModifications.add( 0, reverseModification );
break;
- case DirContext.REMOVE_ATTRIBUTE :
+ case REMOVE_ATTRIBUTE :
mod = modification.getAttribute();
- previous = modifiedEntry.get( mod.getID() );
+ previous = modifiedEntry.get( mod.getId() );
if ( previous == null )
{
@@ -779,19 +831,19 @@
if ( mod.get() == null )
{
- reverseModification = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, previous );
+ reverseModification = new ClientModification( ModificationOperation.ADD_ATTRIBUTE, previous );
reverseModifications.add( 0, reverseModification );
continue;
}
- reverseModification = new ModificationItemImpl( DirContext.ADD_ATTRIBUTE, mod );
+ reverseModification = new ClientModification( ModificationOperation.ADD_ATTRIBUTE, mod );
reverseModifications.add( 0, reverseModification );
break;
- case DirContext.REPLACE_ATTRIBUTE :
+ case REPLACE_ATTRIBUTE :
mod = modification.getAttribute();
- previous = modifiedEntry.get( mod.getID() );
+ previous = modifiedEntry.get( mod.getId() );
/*
* The server accepts without complaint replace
@@ -804,28 +856,28 @@
*/
if ( mod.get() == null && previous == null )
{
- reverseModification = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE,
- new AttributeImpl( mod.getID() ) );
+ reverseModification = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE,
+ new DefaultClientAttribute( mod.getId() ) );
reverseModifications.add( 0, reverseModification );
continue;
}
if ( mod.get() == null )
{
- reverseModification = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, previous );
+ reverseModification = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, previous );
reverseModifications.add( 0, reverseModification );
continue;
}
if ( previous == null )
{
- Attribute emptyAttribute = new AttributeImpl( mod.getID() );
- reverseModification = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, emptyAttribute );
+ EntryAttribute emptyAttribute = new DefaultClientAttribute( mod.getId() );
+ reverseModification = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, emptyAttribute );
reverseModifications.add( 0, reverseModification );
continue;
}
- reverseModification = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, previous );
+ reverseModification = new ClientModification( ModificationOperation.REPLACE_ATTRIBUTE, previous );
reverseModifications.add( 0, reverseModification );
break;
@@ -846,7 +898,7 @@
}
// Now, push the reversed list into the entry
- for ( ModificationItemImpl modification:reverseModifications )
+ for ( Modification modification:reverseModifications )
{
entry.addModificationItem( modification );
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java Thu Aug 14 16:12:09 2008
@@ -1524,6 +1524,7 @@
if ( size() == 0 )
{
+ normalized = true;
return this;
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java Thu Aug 14 16:12:09 2008
@@ -24,7 +24,6 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -108,7 +107,7 @@
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class Rdn implements Cloneable, Comparable, Serializable, Iterable<AttributeTypeAndValue>
+public class Rdn implements Cloneable, Comparable, Externalizable, Iterable<AttributeTypeAndValue>
{
/** The LoggerFactory used by this class */
protected static final Logger LOG = LoggerFactory.getLogger( Rdn.class );
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaUtils.java Thu Aug 14 16:12:09 2008
@@ -30,8 +30,11 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.schema.syntax.AbstractAdsSchemaDescription;
import org.apache.directory.shared.ldap.schema.syntax.AbstractSchemaDescription;
@@ -56,48 +59,48 @@
* @return the resultant entry after the modifications have taken place
* @throws NamingException if there are problems accessing attributes
*/
- public static Attributes getTargetEntry( List<? extends ModificationItem> mods, Attributes entry )
+ public static Entry getTargetEntry( List<? extends Modification> mods, Entry entry )
throws NamingException
{
- Attributes targetEntry = ( Attributes ) entry.clone();
+ Entry targetEntry = entry.clone();
- for ( ModificationItem mod : mods )
+ for ( Modification mod : mods )
{
- String id = mod.getAttribute().getID();
+ String id = mod.getAttribute().getId();
- switch ( mod.getModificationOp() )
+ switch ( mod.getOperation() )
{
- case ( DirContext.REPLACE_ATTRIBUTE ):
+ case REPLACE_ATTRIBUTE :
targetEntry.put( mod.getAttribute() );
break;
- case ( DirContext.ADD_ATTRIBUTE ):
- Attribute combined = new AttributeImpl( id );
- Attribute toBeAdded = mod.getAttribute();
- Attribute existing = entry.get( id );
+ case ADD_ATTRIBUTE :
+ EntryAttribute combined = mod.getAttribute().clone();
+ EntryAttribute toBeAdded = mod.getAttribute();
+ EntryAttribute existing = entry.get( id );
if ( existing != null )
{
- for ( int jj = 0; jj < existing.size(); jj++ )
+ for ( Value<?> value:existing )
{
- combined.add( existing.get( jj ) );
+ combined.add( value );
}
}
- for ( int jj = 0; jj < toBeAdded.size(); jj++ )
+ for ( Value<?> value:toBeAdded )
{
- combined.add( toBeAdded.get( jj ) );
+ combined.add( value );
}
targetEntry.put( combined );
break;
- case ( DirContext.REMOVE_ATTRIBUTE ):
- Attribute toBeRemoved = mod.getAttribute();
+ case REMOVE_ATTRIBUTE :
+ EntryAttribute toBeRemoved = mod.getAttribute();
if ( toBeRemoved.size() == 0 )
{
- targetEntry.remove( id );
+ targetEntry.removeAttributes( id );
}
else
{
@@ -105,9 +108,9 @@
if ( existing != null )
{
- for ( int jj = 0; jj < toBeRemoved.size(); jj++ )
+ for ( Value<?> value:toBeRemoved )
{
- existing.remove( toBeRemoved.get( jj ) );
+ existing.remove( value );
}
}
}
@@ -115,7 +118,7 @@
break;
default:
- throw new IllegalStateException( "undefined modification type: " + mod.getModificationOp() );
+ throw new IllegalStateException( "undefined modification type: " + mod.getOperation() );
}
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java Thu Aug 14 16:12:09 2008
@@ -30,12 +30,19 @@
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
+import javax.naming.directory.InvalidAttributeIdentifierException;
import javax.naming.directory.ModificationItem;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
@@ -1046,15 +1053,15 @@
* @param modification the Modification to be applied
* @throws NamingException if some operation fails.
*/
- public static void applyModification( Attributes entry, ModificationItem modification ) throws NamingException
+ public static void applyModification( Entry entry, Modification modification ) throws NamingException
{
- Attribute modAttr = modification.getAttribute();
- String modificationId = modAttr.getID();
+ EntryAttribute modAttr = modification.getAttribute();
+ String modificationId = modAttr.getId();
- switch ( modification.getModificationOp() )
+ switch ( modification.getOperation() )
{
- case DirContext.ADD_ATTRIBUTE :
- Attribute modifiedAttr = entry.get( modificationId ) ;
+ case ADD_ATTRIBUTE :
+ EntryAttribute modifiedAttr = entry.get( modificationId ) ;
if ( modifiedAttr == null )
{
@@ -1065,26 +1072,24 @@
{
// The attribute exists : the values can be different,
// so we will just add the new values to the existing ones.
- NamingEnumeration<?> values = modAttr.getAll();
-
- while ( values.hasMoreElements() )
+ for ( Value<?> value:modAttr )
{
// If the value already exist, nothing is done.
// Note that the attribute *must* have been
// normalized before.
- modifiedAttr.add( values.nextElement() );
+ modifiedAttr.add( value );
}
}
break;
- case DirContext.REMOVE_ATTRIBUTE :
+ case REMOVE_ATTRIBUTE :
if ( modAttr.get() == null )
{
// We have no value in the ModificationItem attribute :
// we have to remove the whole attribute from the initial
// entry
- entry.remove( modificationId );
+ entry.removeAttributes( modificationId );
}
else
{
@@ -1097,31 +1102,29 @@
break;
}
- NamingEnumeration<?> values = modAttr.getAll();
-
- while ( values.hasMoreElements() )
+ for ( Value<?> value:modAttr )
{
// If the value does not exist, nothing is done.
// Note that the attribute *must* have been
// normalized before.
- modifiedAttr.remove( values.nextElement() );
+ modifiedAttr.remove( value );
}
if ( modifiedAttr.size() == 0 )
{
// If this was the last value, remove the attribute
- entry.remove( modifiedAttr.getID() );
+ entry.removeAttributes( modifiedAttr.getId() );
}
}
break;
- case DirContext.REPLACE_ATTRIBUTE :
+ case REPLACE_ATTRIBUTE :
if ( modAttr.get() == null )
{
// If the modification does not have any value, we have
// to delete the attribute from the entry.
- entry.remove( modificationId );
+ entry.removeAttributes( modificationId );
}
else
{
@@ -1256,4 +1259,98 @@
return null;
}
+
+
+
+
+ /**
+ * Convert a BasicAttributes or a AttributesImpl to a ServerEntry
+ *
+ * @param attributes the BasicAttributes or AttributesImpl instance to convert
+ * @param registries The registries, needed ro build a ServerEntry
+ * @param dn The DN which is needed by the ServerEntry
+ * @return An instance of a ServerEntry object
+ *
+ * @throws InvalidAttributeIdentifierException If we get an invalid attribute
+ */
+ public static Entry toClientEntry( Attributes attributes, LdapDN dn )
+ throws InvalidAttributeIdentifierException
+ {
+ if ( ( attributes instanceof BasicAttributes ) || ( attributes instanceof AttributesImpl ) )
+ {
+ try
+ {
+ Entry entry = new DefaultClientEntry( dn );
+
+ for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); )
+ {
+ Attribute attr = attrs.nextElement();
+
+ EntryAttribute entryAttribute = toClientAttribute( attr );
+
+ if ( entryAttribute != null )
+ {
+ entry.put( entryAttribute );
+ }
+ }
+
+ return entry;
+ }
+ catch ( NamingException ne )
+ {
+ throw new InvalidAttributeIdentifierException( ne.getMessage() );
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Convert a BasicAttribute or a AttributeImpl to a EntryAttribute
+ *
+ * @param attribute the BasicAttributes or AttributesImpl instance to convert
+ * @param attributeType
+ * @return An instance of a ClientEntry object
+ *
+ * @throws InvalidAttributeIdentifierException If we had an incorrect attribute
+ */
+ public static EntryAttribute toClientAttribute( Attribute attribute )
+ {
+ if ( attribute == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ EntryAttribute clientAttribute = new DefaultClientAttribute( attribute.getID() );
+
+ for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements(); )
+ {
+ Object value = values.nextElement();
+
+ if ( value instanceof String )
+ {
+ clientAttribute.add( (String)value );
+ }
+ else if ( value instanceof byte[] )
+ {
+ clientAttribute.add( (byte[])value );
+ }
+ else
+ {
+ clientAttribute.add( (String)null );
+ }
+ }
+
+ return clientAttribute;
+ }
+ catch ( NamingException ne )
+ {
+ return null;
+ }
+ }
}
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Thu Aug 14 16:12:09 2008
@@ -145,6 +145,55 @@
false, false, false, false, false, false, false, false // 78 -> 7F
};
+
+ /**
+ * [0x01-0x1F] | 0x21 | [0x24-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
+ */
+ private static final boolean[] LUTF1 =
+ {
+ false, true, true, true, true, true, true, true, // 00 -> 07 '\0'
+ true, true, true, true, true, true, true, true, // 08 -> 0F
+ true, true, true, true, true, true, true, true, // 10 -> 17
+ true, true, true, true, true, true, true, true, // 18 -> 1F
+ false, true, false, false, true, true, true, true, // 20 -> 27 ( ' ', '"', '#' )
+ true, true, true, false, false, true, true, true, // 28 -> 2F ( '+', ',' )
+ true, true, true, true, true, true, true, true, // 30 -> 37
+ true, true, true, false, false, true, false, true, // 38 -> 3F ( ';', '<', '>' )
+ true, true, true, true, true, true, true, true, // 40 -> 47
+ true, true, true, true, true, true, true, true, // 48 -> 4F
+ true, true, true, true, true, true, true, true, // 50 -> 57
+ true, true, true, true, false, true, true, true, // 58 -> 5F ( '\' )
+ true, true, true, true, true, true, true, true, // 60 -> 67
+ true, true, true, true, true, true, true, true, // 68 -> 6F
+ true, true, true, true, true, true, true, true, // 70 -> 77
+ true, true, true, true, true, true, true, true // 78 -> 7F
+ };
+
+
+ /**
+ * [0x01-0x21] | [0x23-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
+ */
+ private static final boolean[] SUTF1 =
+ {
+ false, true, true, true, true, true, true, true, // 00 -> 07 '\0'
+ true, true, true, true, true, true, true, true, // 08 -> 0F
+ true, true, true, true, true, true, true, true, // 10 -> 17
+ true, true, true, true, true, true, true, true, // 18 -> 1F
+ true, true, false, true, true, true, true, true, // 20 -> 27 ( '"' )
+ true, true, true, false, false, true, true, true, // 28 -> 2F ( '+', ',' )
+ true, true, true, true, true, true, true, true, // 30 -> 37
+ true, true, true, false, false, true, false, true, // 38 -> 3F ( ';', '<', '>' )
+ true, true, true, true, true, true, true, true, // 40 -> 47
+ true, true, true, true, true, true, true, true, // 48 -> 4F
+ true, true, true, true, true, true, true, true, // 50 -> 57
+ true, true, true, true, false, true, true, true, // 58 -> 5F ( '\' )
+ true, true, true, true, true, true, true, true, // 60 -> 67
+ true, true, true, true, true, true, true, true, // 68 -> 6F
+ true, true, true, true, true, true, true, true, // 70 -> 77
+ true, true, true, true, true, true, true, true // 78 -> 7F
+ };
+
+
/**
* ' ' | '"' | '#' | '+' | ',' | ';' | '<' | '=' | '>' | '\' |
* 0x22 | 0x23 | 0x2B | 0x2C | 0x3B | 0x3C | 0x3D | 0x3E | 0x5C
@@ -279,6 +328,46 @@
/**
+ * Check if the current character is a LUTF1 (Lead UTF ascii char)<br/>
+ * <LUTF1> ::= 0x01-1F | 0x21 | 0x24-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
+ *
+ * @param bytes The buffer containing the data
+ * @param index Current position in the buffer
+ * @return <code>true</code> if the current character is a LUTF1
+ */
+ public static boolean isLUTF1( byte[] bytes, int index )
+ {
+ if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
+ {
+ return false;
+ }
+
+ byte c = bytes[index];
+ return ( ( ( c | 0x7F ) == 0x7F ) && LUTF1[c & 0x7f] );
+ }
+
+
+ /**
+ * Check if the current character is a SUTF1 (Stringchar UTF ascii char)<br/>
+ * <LUTF1> ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
+ *
+ * @param bytes The buffer containing the data
+ * @param index Current position in the buffer
+ * @return <code>true</code> if the current character is a SUTF1
+ */
+ public static boolean isSUTF1( byte[] bytes, int index )
+ {
+ if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
+ {
+ return false;
+ }
+
+ byte c = bytes[index];
+ return ( ( ( c | 0x7F ) == 0x7F ) && SUTF1[c & 0x7f] );
+ }
+
+
+ /**
* Check if the given char is a pair char only
* <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
*
@@ -414,6 +503,39 @@
/**
+ * Check if the current character is an ascii String Char.<br/>
+ * <p>
+ * <asciistringchar> ::= [0x00-0x7F] - [,=+<>#;\"\n\r]
+ * </p>
+ *
+ * @param bytes The buffer which contains the data
+ * @param index Current position in the buffer
+ * @return The current char if it is a String Char, or '#' (this is simpler
+ * than throwing an exception :)
+ */
+ public static int isAciiStringChar( byte[] bytes, int index )
+ {
+ if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) )
+ {
+ return -1;
+ }
+ else
+ {
+ byte c = bytes[index];
+
+ if ( ( c | 0x3F ) == 0x3F )
+ {
+ return STRING_CHAR[ c ];
+ }
+ else
+ {
+ return StringTools.countBytesPerChar( bytes, index );
+ }
+ }
+ }
+
+
+ /**
* Check if the current character is a Quote Char We are testing Unicode
* chars <quotechar> ::= [0x00-0xFFFF] - [\"]
*
Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/Position.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/Position.java?rev=686082&r1=686081&r2=686082&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/Position.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/util/Position.java Thu Aug 14 16:12:09 2008
@@ -21,16 +21,20 @@
/**
*
- * This class is used to store the position of a token in a string. It's very
- * usefull while parsing a DN.
+ * This class is used to store the position of a token in a string.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*
*/
public class Position
{
+ /** The starting position in the string */
public int start = 0;
- public int length =0;
+
+ /** The current token length */
+ public int length = 0;
+
+ /** The token end position in the string */
public int end = 0;
public String toString()