directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r618644 - 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/ shared/branches/bigbang/ldap/src/...
Date Tue, 05 Feb 2008 13:33:51 GMT
Author: elecharny
Date: Tue Feb  5 05:33:48 2008
New Revision: 618644

URL: http://svn.apache.org/viewvc?rev=618644&view=rev
Log:
Added ServerEntry serialization and tests

Added:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java
Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
    directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/AbstractServerAttribute.java
Tue Feb  5 05:33:48 2008
@@ -29,10 +29,6 @@
 import javax.naming.NamingException;
 import javax.naming.directory.InvalidAttributeValueException;
 
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -770,84 +766,69 @@
         return attributeId.equalsIgnoreCase( attributeType.getOid() );
     }
     
-    /**
-     * @see Externalizable#writeExternal(ObjectOutput)
-     * 
-     * We have to store the UPid, and all the values, if any.
-     */
-    public void writeExternal( ObjectOutput out ) throws IOException
-    {
-        // Do nothing : we can't restore the AttributeType ...
-    }
 
-    
     /**
-     * @see Externalizable#readExternal(ObjectInput)
-     */
-    public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
-    {
-        if ( in.available() == 0 )
-        {
-            String message = "Cannot read an null Attribute";
-            LOG.error( message );
-            throw new IOException( message );
-        }
-        else
-        {
-            // Read the HR flag
-            boolean hr = in.readBoolean();
-            
-            // Read the UPid
-            upId = in.readUTF();
-
-            // Read the number of values
-            int nbValues = in.readInt();
-            
-            switch ( nbValues )
-            {
-                case -1 :
-                    values = null;
-                    break;
-                    
-                case 0 :
-                    values = new ArrayList<ServerValue<?>>();
-                    break;
-                    
-                default :
-                    values = new ArrayList<ServerValue<?>>();
-                
-                    for ( int i = 0; i < nbValues; i++ )
-                    {
-                        if ( hr )
-                        {
-                            ServerStringValue value = new ServerStringValue( attributeType
);
-                        }
-                    }
-                    
-                    break;
-            }
-                    
-            if ( nbValues != 0 )
-            {
-                
-            }
-            else
-            {
-                
-            }
+     * Gets the hashcode of this ServerAttribute.
+     *
+     * @see java.lang.Object#hashCode()
+      */
+     public int hashCode()
+     {
+         int result = 37;
+         
+         result = result*17 + attributeType.hashCode();
+         
+         for ( ServerValue<?> value:values )
+         {
+             result = result*17 + value.hashCode();
+         }
+
+         return result;
+     }
+     
+     
+     /**
+      * @see Object#equals(Object)
+      */
+     public boolean equals( Object o )
+     {
+         if ( this == o )
+         {
+             return true;
+         }
+         
+         if ( !(o instanceof ServerAttribute ) )
+         {
+             return false;
+         }
+         
+         ServerAttribute attribute = (ServerAttribute)o;
+         
+         if ( attributeType != attribute.getType() )
+         {
+             return false;
+         }
+         
+         if ( size() != attribute.size() )
+         {
+             return false;
+         }
+         
+         for ( ServerValue<?> value:this )
+         {
+             try
+             {
+                 if ( !attribute.contains( value ) )
+                 {
+                     return false;
+                 }
+             }
+             catch ( NamingException ne )
+             {
+                 return false;
+             }
+         }
 
-            String wrapped = in.readUTF();
-            /**
-            set( wrapped );
-            
-            normalizedValue = in.readUTF();
-            
-            if ( ( normalizedValue.length() == 0 ) &&  ( wrapped.length() != 0 )
)
-            {
-                // In this case, the normalized value is equal to the UP value
-                normalizedValue = wrapped;
-            }
-            */
-        }
-    }
+         return true;
+     }
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
Tue Feb  5 05:33:48 2008
@@ -745,6 +745,7 @@
         return values.iterator();
     }
     
+    
     /**
      * @see Object#toString() 
      */

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
Tue Feb  5 05:33:48 2008
@@ -1089,16 +1089,16 @@
      * @return <code>true</code> if the value is found within the attribute
      * @throws NamingException If there is a problem
      */
-    public boolean contains( ServerAttribute attribute, Value<?> value ) throws NamingException
+    public boolean contains( AttributeType attributeType, Value<?> value ) throws NamingException
     {
-        if ( attribute == null )
+        if ( attributeType == null )
         {
             return false;
         }
         
-        if ( serverAttributeMap.containsKey( attribute.getType() ) )
+        if ( serverAttributeMap.containsKey( attributeType ) )
         {
-            return serverAttributeMap.get( attribute.getType() ).contains( (ServerValue<?>)value
);
+            return serverAttributeMap.get( attributeType ).contains( (ServerValue<?>)value
);
         }
         else
         {
@@ -1282,7 +1282,15 @@
         else
         {
             objectClassAttribute.add( values );
-            attribute.add( values );
+            
+            if ( attribute == null )
+            {
+                serverAttributeMap.put(  OBJECT_CLASS_AT, objectClassAttribute ); 
+            }
+            else
+            {
+                attribute.add( values );
+            }
         }
     }
     
@@ -1823,7 +1831,69 @@
             }
         }
     }
+    
+    
+    /**
+    * Gets the hashcode of this ServerEntry.
+    *
+    * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int result = 37;
+        
+        result = result*17 + dn.hashCode();
+        
+        for ( ServerAttribute attribute:serverAttributeMap.values() )
+        {
+            result = result*17 + attribute.hashCode();
+        }
 
+        return result;
+    }
+
+    
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        
+        if ( ! ( o instanceof DefaultServerEntry ) )
+        {
+            return false;
+        }
+        
+        DefaultServerEntry other = (DefaultServerEntry)o;
+        
+        if ( !dn.equals( other.getDn() ) )
+        {
+            return false;
+        }
+        
+        if ( size() != other.size() )
+        {
+            return false;
+        }
+        
+        for ( ServerAttribute attribute:other )
+        {
+            ServerAttribute attr = this.get( attribute.getType() );
+            
+            if ( attr == null )
+            {
+                return false;
+            }
+            
+            if ( !attribute.equals( attr ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
         
     /**
      * @see Object#toString()

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
Tue Feb  5 05:33:48 2008
@@ -109,6 +109,25 @@
     }
 
 
+    /**
+     * Creates a ServerStringValue with an initial wrapped String value and
+     * a normalized value.
+     *
+     * @param attributeType the schema type associated with this ServerStringValue
+     * @param wrapped the value to wrap which can be null
+     * @param normalizedValue the normalized value
+     */
+    /** No protection */ ServerBinaryValue( AttributeType attributeType, byte[] wrapped,
byte[] normalizedValue, boolean same, boolean valid )
+    {
+        setNormalized( true );
+        this.attributeType = attributeType;
+        super.set( wrapped );
+        setNormalizedValue( normalizedValue );
+        this.same = same;
+        this.valid = valid;
+    }
+
+
     // -----------------------------------------------------------------------
     // Value<String> Methods
     // -----------------------------------------------------------------------
@@ -215,6 +234,25 @@
 
 
     /**
+     * Sets this value's wrapped value to a copy of the src array.
+     *
+     * @param wrapped the byte array to use as the wrapped value
+     */
+    private void setNormalizedValue( byte[] normalizedValue )
+    {
+        if ( normalizedValue != null )
+        {
+            this.normalizedValue = new byte[ normalizedValue.length ];
+            System.arraycopy( normalizedValue, 0, this.normalizedValue, 0, normalizedValue.length
);
+        }
+        else
+        {
+            this.normalizedValue = null;
+        }
+    }
+
+
+    /**
      * Gets a direct reference to the normalized representation for the
      * wrapped value of this ServerValue wrapper. Implementations will most
      * likely leverage the attributeType this value is associated with to
@@ -256,6 +294,15 @@
         return valid;
     }
 
+    
+    /**
+     * @return Tells if the wrapped value and the normalized value are the same 
+     */
+    public final boolean isSame()
+    {
+        return same;
+    }
+    
 
     /**
      *
@@ -419,24 +466,6 @@
         }
 
         return compareTo( (ServerValue<byte[]>)other ) == 0;
-        
-        /*
-        // now unlike regular values we have to compare the normalized values
-        try
-        {
-            return Arrays.equals( getNormalizedReference(), other.getNormalizedReference()
);
-        }
-        catch ( NamingException e )
-        {
-            // 1st this is a warning because we're recovering from it and secondly
-            // we build big string since waste is not an issue when exception handling
-            LOG.warn( "Failed to get normalized value while trying to compare StringValues:
"
-                    + toString() + " and " + other.toString() , e );
-
-            // recover by comparing non-normalized values
-            return Arrays.equals( getReference(), other.getReference() );
-        }
-        */
     }
 
 

Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java?rev=618644&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
(added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
Tue Feb  5 05:33:48 2008
@@ -0,0 +1,325 @@
+/*
+ *  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.server.core.entry;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.name.DnSerializer;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerEntrySerializer
+{
+    /** The registries reference */
+    private Registries registries;
+
+    /** Flag used for ServerStringValue */
+    private static final boolean HR_VALUE = true;
+    
+    /** Flag used for streamed values */
+    private static final boolean STREAMED_VALUE = true;
+
+    
+    /**
+     * Creates a new instance of ServerEntrySerializer.
+     *
+     * @param registries The reference to the global registries
+     */
+    public ServerEntrySerializer( Registries registries )
+    {
+        this.registries = registries;
+    }
+    
+    /**
+     * @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>ServerAttribute.write(), Value.write()</code>) is that we need
+     * access to the registries to read back the values.
+     * <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>
+     * <li>
+     * <b>DN</b> : The entry's DN. Can be empty (rootDSE=<p>
+     * </li>
+     * We have to store the UPid, and all the values, if any.
+     */
+    public void serialize( ServerEntry entry, ObjectOutput out ) throws IOException, NamingException
+    {
+        // First, the DN
+        if ( entry.getDn() == null )
+        {
+            // Write an empty DN
+            DnSerializer.serialize( LdapDN.EMPTY_LDAPDN, out );
+        }
+        else
+        {
+            // Write the DN
+            DnSerializer.serialize( entry.getDn(), out );
+        }
+        
+        // Then the attributes.
+        out.writeInt( entry.size() );
+            
+        // Iterate through the attrbutes. 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 ServerAttribute class.
+        for ( ServerAttribute attribute:entry )
+        {
+            // We store the OID, as the AttributeType might have no name
+            out.writeUTF( attribute.getType().getOid() );
+            
+            // And store the attribute.
+            // Store the UP id
+            out.writeUTF( attribute.getUpId() );
+            
+            // The number of values
+            out.writeInt( attribute.size() );
+
+            for ( ServerValue<?> value:attribute )
+            {
+                serializeValue( value, out );
+            }
+        }
+
+        // Note : we don't store the ObjectClassAttribute. I has already
+        // been stored as an attribute.
+        
+        out.flush();
+    }
+    
+    
+    /**
+     * We will write the value and the normalized value, only
+     * if the normalized value is different.
+     * 
+     * The data will be stored following this structure :
+     *
+     *  [is valid]
+     *  [HR flag]
+     *  [Streamed flag]
+     *  [UP value]
+     *  [Norm value] (will be null if normValue == upValue)
+     */
+    private void serializeValue( ServerValue<?> value, ObjectOutput out ) throws IOException,
NamingException
+    {
+        out.writeBoolean( value.isValid() );
+        
+        if ( value instanceof ServerStringValue )
+        {
+            out.writeBoolean( HR_VALUE );
+            out.writeBoolean( !STREAMED_VALUE );
+            ServerStringValue ssv = (ServerStringValue)value;
+
+            if ( ssv.get() == null )
+            {
+                // Write two empry string for UP nad normalized
+                out.writeUTF( "" );
+                out.writeUTF( "" );
+            }
+            else
+            {
+                // Save the UP value and the normalized value
+                out.writeUTF( ssv.get() );
+                ssv.normalize();
+                out.writeUTF( ssv.getNormalized() );
+            }
+        }
+        else if ( value instanceof ServerBinaryValue )
+        {
+            out.writeBoolean( !HR_VALUE );
+            out.writeBoolean( !STREAMED_VALUE );
+            ServerBinaryValue sbv = (ServerBinaryValue)value;
+            
+            if ( sbv.get() == null )
+            {
+                out.writeInt( 0 );
+                out.writeInt( 0 ); 
+            }
+            else
+            {
+                // Save the UP value and the normalized value if !=
+                out.writeInt( sbv.get().length );
+                out.write( sbv.get() );
+                
+                out.writeBoolean( sbv.isSame() );
+    
+                if ( !sbv.isSame() )
+                {
+                    sbv.normalize();
+                    
+                    out.writeInt( sbv.getNormalizedReference().length );
+                    out.write( sbv.getNormalizedReference() );
+                }
+            }
+        }
+        
+        out.flush();
+    }
+
+    
+    /**
+     * We will write the value and the normalized value, only
+     * if the normalized value is different.
+     * 
+     * The data will be stored following this structure :
+     *
+     *  [is valid]
+     *  [HR flag]
+     *  [Streamed flag]
+     *  [UP value]
+     *  [Norm value] (will be null if normValue == upValue)
+     */
+    private ServerValue<?> deserializeValue( ObjectInput in, AttributeType attributeType
) throws IOException, NamingException
+    {
+        boolean isValid = in.readBoolean();
+        boolean isHR = in.readBoolean();
+        boolean isStreamed = in.readBoolean();
+        
+        if ( isHR )
+        {
+            if ( !isStreamed )
+            {
+                String value = in.readUTF();
+                
+                if ( value.length() == 0 )
+                {
+                    value = null;
+                }
+                
+                String normalized = in.readUTF();
+                
+                if ( normalized.length() == 0 )
+                {
+                    normalized = null;
+                }
+                
+                
+                ServerValue<?> ssv = new ServerStringValue( attributeType, value, normalized,
isValid );
+                
+                return ssv;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else
+        {
+            if ( !isStreamed )
+            {
+                int length = in.readInt();
+                
+                byte[] value = new byte[length];
+                
+                if ( length != 0 )
+                {
+                    in.read( value );
+                }
+                
+                byte[] normalized = null;
+                boolean same = in.readBoolean();
+                
+                // Now, if the normalized value is different from the wrapped value,
+                // read the normalized value.
+                if ( !same )
+                {
+                    length = in.readInt();
+                    
+                    normalized = new byte[length];
+                   if ( length != 0 )
+                   {
+                       in.read( normalized );
+                   }
+                }
+                else
+                {
+                    normalized = value;
+                }
+                
+                ServerValue<?> sbv = new ServerBinaryValue( attributeType, value, normalized,
same, isValid );
+                
+                return sbv;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+
+    
+    /**
+     *  Deserialize a ServerEntry
+     */
+    public ServerEntry deserialize( ObjectInput in  ) throws IOException, NamingException,
ClassNotFoundException
+    {
+        // First, read the DN
+        LdapDN dn = DnSerializer.deserialize( in );
+        
+        // Read the number of attributes
+        int nbAttrs = in.readInt();
+        
+        ServerEntry serverEntry = new DefaultServerEntry( registries, dn );
+
+        // Read all the attributes
+        for ( int i = 0; i < nbAttrs; i++ )
+        {
+            // The oid
+            String oid = in.readUTF();
+            
+            AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( oid
);
+            
+            // The UP id
+            String upId = in.readUTF();
+            
+            // The number of values
+            int nbValues = in.readInt();
+            
+            ServerAttribute serverAttribute = new DefaultServerAttribute( upId, attributeType
);
+            
+            for ( int j = 0; j < nbValues; j++ )
+            {
+                ServerValue<?> value = deserializeValue( in, attributeType );
+                serverAttribute.add( value );
+            }
+            
+            serverEntry.put( serverAttribute );
+        }
+        
+        return serverEntry;
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
Tue Feb  5 05:33:48 2008
@@ -105,6 +105,24 @@
     }
 
 
+    /**
+     * Creates a ServerStringValue with an initial wrapped String value and
+     * a normalized value.
+     *
+     * @param attributeType the schema type associated with this ServerStringValue
+     * @param wrapped the value to wrap which can be null
+     * @param normalizedValue the normalized value
+     */
+    /** No protection */ ServerStringValue( AttributeType attributeType, String wrapped,
String normalizedValue, boolean valid )
+    {
+        setNormalized( true );
+        this.attributeType = attributeType;
+        super.set( wrapped );
+        this.normalizedValue = normalizedValue;
+        this.valid = valid;
+    }
+
+
     // -----------------------------------------------------------------------
     // Value<String> Methods
     // -----------------------------------------------------------------------

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
Tue Feb  5 05:33:48 2008
@@ -19,16 +19,9 @@
  */
 package org.apache.directory.server.core.entry;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.naming.InvalidNameException;
@@ -54,10 +47,7 @@
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
-import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
-import org.apache.directory.shared.ldap.schema.OidNormalizer;
 import org.apache.directory.shared.ldap.util.StringTools;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import static org.junit.Assert.assertNotNull;
@@ -112,7 +102,7 @@
         DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
         
         ObjectClassAttribute oc = new ObjectClassAttribute( registries );
-        oc.add( "top", "person", "inetOrgPerson" );
+        oc.add( "top", "person", "inetOrgPerson", "organizationalPerson" );
         
         entry.addObjectClass( oc );
         entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
@@ -149,7 +139,7 @@
         DefaultServerEntry entry = new DefaultServerEntry( registries,dn );
         
         ObjectClassAttribute oc = new ObjectClassAttribute( registries );
-        oc.add( "top", "person", "inetOrgPerson" );
+        oc.add( "top", "person", "inetOrgPerson", "organizationalPerson" );
         
         entry.addObjectClass( oc );
         //entry.put( "cn", registries.getAttributeTypeRegistry().lookup( "cn" ), "test" );
@@ -1817,123 +1807,5 @@
     {
         
     }
-    
-    
-    private ByteArrayOutputStream serializeEntry( ServerEntry entry ) throws IOException
-    {
-        ObjectOutputStream oOut = null;
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-
-        try
-        {
-            oOut = new ObjectOutputStream( out );
-            oOut.writeObject( entry );
-        }
-        catch ( IOException ioe )
-        {
-            throw ioe;
-        }
-        finally
-        {
-            try
-            {
-                if ( oOut != null )
-                {
-                    oOut.flush();
-                    oOut.close();
-                }
-            }
-            catch ( IOException ioe )
-            {
-                throw ioe;
-            }
-        }
-        
-        return out;
-    }
-    
-    
-    private ServerEntry deserializeEntry( ByteArrayOutputStream out ) throws IOException,
ClassNotFoundException
-    {
-        ObjectInputStream oIn = null;
-        ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
-
-        try
-        {
-            oIn = new ObjectInputStream( in );
-
-            ServerEntry entry = ( ServerEntry ) oIn.readObject();
-            
-            return entry;
-        }
-        catch ( IOException ioe )
-        {
-            throw ioe;
-        }
-        finally
-        {
-            try
-            {
-                if ( oIn != null )
-                {
-                    oIn.close();
-                }
-            }
-            catch ( IOException ioe )
-            {
-                throw ioe;
-            }
-        }
-    }
-
-    
-    private Map<String, OidNormalizer> oids;
-    private Map<String, OidNormalizer> oidOids;
-
-    /**
-     * Initialize OIDs maps for normalization
-     */
-    @Before public void initMapOids()
-    {
-        oids = new HashMap<String, OidNormalizer>();
-
-        oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
-        oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer()
) );
-        oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer()
) );
-        oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
-        oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer()
) );
-        oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() )
);
-    
-    
-        // Another map where we store OIDs instead of names.
-        oidOids = new HashMap<String, OidNormalizer>();
-
-        oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer()
) );
-        oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
new DeepTrimToLowerNormalizer() ) );
-        oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
new DeepTrimToLowerNormalizer() ) );
-        oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
-        oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
-        oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
-    }
-    
-    
-    /**
-     * Test the serialization
-     */
-    @Test public void testSerialize() throws Exception
-    {
-        LdapDN dn = new LdapDN( "ou=test, dc=com" );
-        dn.normalize( oids );
-        
-        ServerEntry entry = new DefaultServerEntry( registries, dn );
-        
-        entry.put( "ObjectClass", "top", "person" );
-        entry.put( "cn", "A CN" );
-        entry.put( "ou", "test" );
-        entry.put( "l", (String)null );
-        
-        //assertEquals( entry, deserializeEntry( serializeEntry( entry ) ) );
-    }
-
 }
 

Added: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java?rev=618644&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java
(added)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ServerEntrySerializerTest.java
Tue Feb  5 05:33:48 2008
@@ -0,0 +1,202 @@
+/*
+ *  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.server.core.entry;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.schema.bootstrap.ApacheSchema;
+import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
+import org.apache.directory.server.schema.bootstrap.CoreSchema;
+import org.apache.directory.server.schema.bootstrap.CosineSchema;
+import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.bootstrap.SystemSchema;
+import org.apache.directory.server.schema.registries.DefaultOidRegistry;
+import org.apache.directory.server.schema.registries.DefaultRegistries;
+import org.apache.directory.server.schema.registries.OidRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
+import org.apache.directory.shared.ldap.schema.OidNormalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test the ServerEntry serialization/deserialization class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerEntrySerializerTest
+{
+    private static BootstrapSchemaLoader loader;
+    private static Registries registries;
+    private static OidRegistry oidRegistry;
+    private static Map<String, OidNormalizer> oids;
+    private static Map<String, OidNormalizer> oidOids;
+
+    /**
+     * Initialize the registries once for the whole test suite
+     */
+    @BeforeClass
+    public static void setup() throws NamingException
+    {
+        loader = new BootstrapSchemaLoader();
+        oidRegistry = new DefaultOidRegistry();
+        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
+        
+        // load essential bootstrap schemas 
+        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
+        bootstrapSchemas.add( new ApachemetaSchema() );
+        bootstrapSchemas.add( new ApacheSchema() );
+        bootstrapSchemas.add( new CoreSchema() );
+        bootstrapSchemas.add( new SystemSchema() );
+        bootstrapSchemas.add( new InetorgpersonSchema() );
+        bootstrapSchemas.add( new CosineSchema() );
+        loader.loadWithDependencies( bootstrapSchemas, registries );
+        
+        oids = new HashMap<String, OidNormalizer>();
+
+        oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
+        oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer()
) );
+        oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer()
) );
+        oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
+        oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer()
) );
+        oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() )
);
+    
+    
+        // Another map where we store OIDs instead of names.
+        oidOids = new HashMap<String, OidNormalizer>();
+
+        oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer()
) );
+        oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
new DeepTrimToLowerNormalizer() ) );
+        oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
new DeepTrimToLowerNormalizer() ) );
+        oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
+        oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
+        oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer()
) );
+    }
+
+    
+    @Test public void testSerializeEmtpyServerEntry() throws IOException, NamingException,
ClassNotFoundException
+    {
+        LdapDN dn = LdapDN.EMPTY_LDAPDN;
+        ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+        ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        ses.serialize( entry, out );
+        
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+        
+        ServerEntry result = ses.deserialize( in );
+        
+        assertEquals( entry, result );
+    }
+
+    @Test public void testSerializeDNServerEntry() throws IOException, NamingException, ClassNotFoundException
+    {
+        LdapDN dn = new LdapDN( "cn=text, dc=example, dc=com" );
+        dn.normalize( oids );
+        
+        ServerEntry entry = new DefaultServerEntry( registries, dn );
+
+        ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        ses.serialize( entry, out );
+        
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+        
+        ServerEntry result = ses.deserialize( in );
+        
+        assertEquals( entry, result );
+    }
+
+
+    @Test public void testSerializeServerEntryOC() throws IOException, NamingException, ClassNotFoundException
+    {
+        LdapDN dn = new LdapDN( "cn=text, dc=example, dc=com" );
+        dn.normalize( oids );
+        
+        ServerEntry entry = new DefaultServerEntry( registries, dn );
+        entry.add( "objectClass", "top", "person", "inetOrgPerson", "organizationalPerson"
);
+
+        ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        ses.serialize( entry, out );
+        
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+        
+        ServerEntry result = ses.deserialize( in );
+        
+        assertEquals( entry, result );
+    }
+
+
+    @Test public void testSerializeServerEntry() throws IOException, NamingException, ClassNotFoundException
+    {
+        LdapDN dn = new LdapDN( "cn=text, dc=example, dc=com" );
+        dn.normalize( oids );
+        
+        ServerEntry entry = new DefaultServerEntry( registries, dn );
+        entry.add( "objectClass", "top", "person", "inetOrgPerson", "organizationalPerson"
);
+        entry.add( "cn", "text", "test" );
+        entry.add( "SN", (String)null );
+        entry.add( "userPassword", StringTools.getBytesUtf8( "password" ) );
+
+        ServerEntrySerializer ses = new ServerEntrySerializer( registries );
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        ses.serialize( entry, out );
+        
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+        
+        ServerEntry result = ses.deserialize( in );
+        
+        assertEquals( entry, result );
+    }
+}

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
Tue Feb  5 05:33:48 2008
@@ -20,6 +20,7 @@
 
 
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
 
 import javax.naming.NamingException;
 
@@ -134,12 +135,12 @@
     /**
      * Checks if an entry contains an attribute with a given value.
      *
-     * @param attribute The Attribute we are looking for
+     * @param attributeType The Attribute type we are looking for
      * @param value The searched value
      * @return <code>true</code> if the value is found within the attribute
      * @throws NamingException If the attribute does not exist
      */
-    boolean contains( T attribute, Value<?> value ) throws NamingException;
+    boolean contains( AttributeType attributeType, Value<?> value ) throws NamingException;
     
     
     /**

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/EntryAttribute.java
Tue Feb  5 05:33:48 2008
@@ -18,7 +18,6 @@
  */
 package org.apache.directory.shared.ldap.entry;
 
-import java.io.Externalizable;
 import java.util.Iterator;
 import java.util.List;
 
@@ -33,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface EntryAttribute<T extends Value<?>> extends Iterable<T>,
 Externalizable, Cloneable
+public interface EntryAttribute<T extends Value<?>> extends Iterable<T>,
 Cloneable
 {
     /**
      * Adds some values to this attribute. If the new values are already present in

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=618644&r1=618643&r2=618644&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Tue Feb  5 05:33:48 2008
@@ -2862,6 +2862,55 @@
     }
 
 
+    /*
+    @Test public void testSerializationPerfs() throws Exception
+    {
+        LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc=
cOm" );
+        dn.normalize( oids );
+
+        long t0 = System.currentTimeMillis();
+        
+        for ( int i = 0; i < 1000; i++ )
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream out = new ObjectOutputStream( baos );
+
+            DnSerializer.serialize( dn, out );
+            
+            byte[] data = baos.toByteArray();
+            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data
) );
+            
+            LdapDN dn1 = DnSerializer.deserialize( in );
+        }
+        
+        long t1 = System.currentTimeMillis();
+        
+        System.out.println( "delta :" + ( t1 - t0) );
+
+        long t2 = System.currentTimeMillis();
+        
+        for ( int i = 0; i < 1000000; i++ )
+        {
+            //ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            //ObjectOutputStream out = new ObjectOutputStream( baos );
+
+            //DnSerializer.serializeString( dn, out );
+            
+            //byte[] data = baos.toByteArray();
+            //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data
) );
+            
+            //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
+            dn.normalize( oids );
+        }
+        
+        long t3 = System.currentTimeMillis();
+
+        System.out.println( "delta :" + ( t3 - t2) );
+
+        //assertEquals( dn, DnSerializer.deserialize( in ) );
+    }
+    */
+
     @Test public void testStaticSerializeEmptyDN() throws Exception
     {
         LdapDN dn = LdapDN.EMPTY_LDAPDN;



Mime
View raw message