directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1089607 - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ apacheds/trunk/core/src/test/java/org/apache/directory/ser...
Date Wed, 06 Apr 2011 20:02:32 GMT
Author: elecharny
Date: Wed Apr  6 20:02:31 2011
New Revision: 1089607

URL: http://svn.apache.org/viewvc?rev=1089607&view=rev
Log:
o Modified the hasObjectClass method to deal with more than one objectclass
o Added a isSchemaAware method in Entry
o Removed unused constructors
o factorized some constructors
o Fixed tests

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
    directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
    directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifAttributesReader.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
Wed Apr  6 20:02:31 2011
@@ -163,9 +163,9 @@ public class ClonedServerEntry implement
     }
 
 
-    public boolean hasObjectClass( Attribute objectClass )
+    public boolean hasObjectClass( Attribute... objectClasses )
     {
-        return clonedEntry.hasObjectClass( objectClass );
+        return clonedEntry.hasObjectClass( objectClasses );
     }
 
 
@@ -307,11 +307,20 @@ public class ClonedServerEntry implement
     }
 
 
-    public boolean hasObjectClass( String objectClass )
+    public boolean hasObjectClass( String... objectClasses )
     {
-        return clonedEntry.hasObjectClass( objectClass );
+        return clonedEntry.hasObjectClass( objectClasses );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSchemaAware()
+    {
+        return clonedEntry.isSchemaAware();
+    }
+    
 
     public Iterator<Attribute> iterator()
     {

Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
(original)
+++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
Wed Apr  6 20:02:31 2011
@@ -223,7 +223,7 @@ public class SchemaAwareEntryTest
 
     /**
      * Test for method DefaultEntry( registries, Dn, AttributeType, upId )
-     */
+     *
     @Test
     public void testDefaultClientEntryRegistriesDNUpIdArray() throws Exception
     {

Modified: directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java
(original)
+++ directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java
Wed Apr  6 20:02:31 2011
@@ -31,8 +31,6 @@ import java.util.Set;
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
 import org.apache.directory.server.core.DefaultDnFactory;
 import org.apache.directory.server.core.DnFactory;
 import org.apache.directory.server.core.normalization.FilterNormalizingVisitor;
@@ -55,6 +53,9 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Unit test cases for the SubtreeEvaluator.
@@ -130,7 +131,7 @@ public class SubtreeEvaluatorTest
         SubtreeSpecification ss = modifier.getSubtreeSpecification();
         Dn apDn = dnFactory.create( "ou=system" );
         Dn entryDn = dnFactory.create( "ou=users,ou=system" );
-        Entry entry = new DefaultEntry( schemaManager, entryDn, "objectClass" );
+        Entry entry = new DefaultEntry( schemaManager, entryDn );
 
         assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
 
@@ -150,7 +151,7 @@ public class SubtreeEvaluatorTest
         SubtreeSpecification ss = modifier.getSubtreeSpecification();
         Dn apDn = dnFactory.create( "ou=system" );
         Dn entryDn = dnFactory.create( "ou=users,ou=system" );
-        Entry entry = new DefaultEntry( schemaManager, entryDn, "objectClass" );
+        Entry entry = new DefaultEntry( schemaManager, entryDn );
 
         assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
 
@@ -172,7 +173,7 @@ public class SubtreeEvaluatorTest
         SubtreeSpecification ss = modifier.getSubtreeSpecification();
         Dn apDn = dnFactory.create( "ou=system" );
         Dn entryDn = dnFactory.create( "ou=users,ou=system" );
-        Entry entry = new DefaultEntry( schemaManager, entryDn, "objectClass" );
+        Entry entry = new DefaultEntry( schemaManager, entryDn );
 
         assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
 
@@ -207,7 +208,7 @@ public class SubtreeEvaluatorTest
         SubtreeSpecification ss = modifier.getSubtreeSpecification();
         Dn apDn = dnFactory.create( "ou=system" );
         Dn entryDn = dnFactory.create( "ou=users,ou=system" );
-        Entry entry = new DefaultEntry( schemaManager, entryDn, "objectClass" );
+        Entry entry = new DefaultEntry( schemaManager, entryDn );
 
         assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
 
@@ -242,7 +243,7 @@ public class SubtreeEvaluatorTest
         SubtreeSpecification ss = modifier.getSubtreeSpecification();
         Dn apDn = dnFactory.create( "ou=system" );
         Dn entryDn = dnFactory.create( "ou=users,ou=system" );
-        Entry entry = new DefaultEntry( schemaManager, entryDn, "objectClass" );
+        Entry entry = new DefaultEntry( schemaManager, entryDn );
 
         assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
 

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryTest.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryTest.java
Wed Apr  6 20:02:31 2011
@@ -235,81 +235,6 @@ public class SchemaAwareEntryTest
 
 
     /**
-     * Test method for DefaultEntry( Dn, String... )
-     */
-    @Test
-    public void testDefaultClientEntryLdapDNStringArray()
-    {
-        Entry entry = new DefaultEntry( EXAMPLE_DN, "ObjectClass", "cn", "sn" );
-        
-        assertNotNull( entry );
-        assertNotNull( entry.getDn() );
-        assertEquals( EXAMPLE_DN, entry.getDn() );
-        assertEquals( 3, entry.size() );
-        assertTrue( entry.containsAttribute( "OBJECTCLASS" ) );
-        assertTrue( entry.containsAttribute( "CN" ) );
-        assertTrue( entry.containsAttribute( "SN" ) );
-
-        try
-        {
-            new DefaultEntry( EXAMPLE_DN, "ObjectClass", (String)null, "sn" );
-            fail();
-        }
-        catch( IllegalArgumentException iae )
-        {
-            assertTrue( true );
-        }
-
-        try
-        {
-            new DefaultEntry( EXAMPLE_DN, "ObjectClass", " ", "sn" );
-            fail();
-        }
-        catch( IllegalArgumentException iae )
-        {
-            assertTrue( true );
-        }
-    }
-
-
-    /**
-     * Test method for DefaultEntry( Dn, EntryAttribute... )
-     */
-    @Test
-    public void testDefaultClientEntryLdapDNEntryAttributeArray()
-    {
-        Attribute attrOC = new DefaultAttribute( "objectClass", "top", "person" );
-        Attribute attrCN = new DefaultAttribute( "cn", "test1", "test2" );
-        Attribute attrPWD = new DefaultAttribute( "userPassword", BYTES1, BYTES2 );
-        
-        Entry entry = new DefaultEntry( EXAMPLE_DN, attrOC, attrCN, attrPWD );
-        
-        assertNotNull( entry );
-        assertNotNull( entry.getDn() );
-        assertEquals( EXAMPLE_DN, entry.getDn() );
-        assertEquals( 3, entry.size() );
-        assertTrue( entry.containsAttribute( "OBJECTCLASS" ) );
-        assertTrue( entry.containsAttribute( "CN" ) );
-        assertTrue( entry.containsAttribute( "userPassword" ) );
-        
-        entry = new DefaultEntry( EXAMPLE_DN, attrOC, attrCN, attrOC );
-        assertNotNull( entry );
-        assertNotNull( entry.getDn() );
-        assertEquals( EXAMPLE_DN, entry.getDn() );
-        assertEquals( 2, entry.size() );
-        assertTrue( entry.containsAttribute( "OBJECTCLASS" ) );
-        assertTrue( entry.containsAttribute( "CN" ) );
-        
-        entry = new DefaultEntry( EXAMPLE_DN, attrOC, (Attribute)null );
-        assertNotNull( entry );
-        assertNotNull( entry.getDn() );
-        assertEquals( EXAMPLE_DN, entry.getDn() );
-        assertEquals( 1, entry.size() );
-        assertTrue( entry.containsAttribute( "OBJECTCLASS" ) );
-    }
-
-
-    /**
      * Test method for add( EntryAttribute... )
      */
     @Test

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
Wed Apr  6 20:02:31 2011
@@ -35,6 +35,7 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.model.ldif.LdapLdifException;
 import org.apache.directory.shared.ldap.model.ldif.LdifAttributesReader;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.model.name.Dn;
@@ -91,8 +92,7 @@ public final class DefaultEntry implemen
      */
     public DefaultEntry()
     {
-        schemaManager = null;
-        dn = Dn.EMPTY_DN;
+        this( (SchemaManager)null );
     }
 
 
@@ -112,7 +112,10 @@ public final class DefaultEntry implemen
         dn = Dn.EMPTY_DN;
 
         // Initialize the ObjectClass object
-        initObjectClassAT();
+        if ( schemaManager != null )
+        {
+            initObjectClassAT();
+        }
     }
 
 
@@ -165,15 +168,9 @@ public final class DefaultEntry implemen
      * @param dn The Dn for this serverEntry. Can be null.
      * @param upIds The list of attributes to create.
      */
-    public DefaultEntry( Dn dn, String... upIds )
+    public DefaultEntry( String dn, Object... elements ) throws LdapException
     {
-        this.dn = dn;
-
-        for ( String upId : upIds )
-        {
-            // Add a new AttributeType without value
-            set( upId );
-        }
+        this( null, dn, elements );
     }
 
 
@@ -184,9 +181,9 @@ public final class DefaultEntry implemen
      * @param dn The Dn for this serverEntry. Can be null.
      * @param upIds The list of attributes to create.
      */
-    public DefaultEntry( String dn, Object... elements ) throws LdapException
+    public DefaultEntry( SchemaManager schemaManager, String dn, Object... elements ) throws
LdapException
     {
-        this( null, dn, elements );
+        this( schemaManager, new Dn( schemaManager, dn ), elements );
     }
 
 
@@ -197,70 +194,19 @@ public final class DefaultEntry implemen
      * @param dn The Dn for this serverEntry. Can be null.
      * @param upIds The list of attributes to create.
      */
-    public DefaultEntry( SchemaManager schemaManager, String dn, Object... elements ) throws
LdapException
+    public DefaultEntry( SchemaManager schemaManager, Dn dn, Object... elements ) throws
LdapException
     {
-        StringBuilder sb = new StringBuilder();
-        int pos = 0;
-        boolean valueExpected = false;
-
-        for ( Object element : elements )
-        {
-            if ( !valueExpected )
-            {
-                if ( !( element instanceof String ) )
-                {
-                    throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n.err(
-                        I18n.ERR_12085, ( pos + 1 ) ) );
-                }
-
-                String attribute = ( String ) element;
-                sb.append( attribute );
-
-                if ( attribute.indexOf( ':' ) != -1 )
-                {
-                    sb.append( '\n' );
-                }
-                else
-                {
-                    valueExpected = true;
-                }
-            }
-            else
-            {
-                if ( element instanceof String )
-                {
-                    sb.append( ": " ).append( ( String ) element ).append( '\n' );
-                }
-                else if ( element instanceof byte[] )
-                {
-                    sb.append( ":: " );
-                    sb.append( new String( Base64.encode( ( byte[] ) element ) ) );
-                    sb.append( '\n' );
-                }
-                else
-                {
-                    throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n.err(
-                        I18n.ERR_12086, ( pos + 1 ) ) );
-                }
-
-                valueExpected = false;
-            }
-        }
-
-        if ( valueExpected )
-        {
-            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n
-                .err( I18n.ERR_12087 ) );
-        }
-
-        LdifAttributesReader reader = new LdifAttributesReader();
-        DefaultEntry entry = (DefaultEntry)reader.parseEntry( schemaManager, sb.toString()
);
-        this.dn = new Dn( schemaManager, dn );
+        DefaultEntry entry = (DefaultEntry)createEntry( schemaManager, elements );
+        
+        this.dn = dn;
         this.attributes = entry.attributes;
         this.schemaManager = schemaManager;
         
-        // Initialize the ObjectClass object
-        initObjectClassAT();
+        if ( schemaManager != null )
+        {
+            this.dn.apply( schemaManager );
+            initObjectClassAT();
+        }
     }
 
 
@@ -326,134 +272,71 @@ public final class DefaultEntry implemen
     }
 
 
-    /**
-     * Creates a new instance of DefaultEntry, with a
-     * Dn, a list of ID and schema aware.
-     * <p>
-     * No attributes will be created except the ObjectClass attribute,
-     * which will contains "top".
-     * <p>
-     * If any of the AttributeType does not exist, they are simply discarded.
-     *
-     * @param schemaManager The reference to the schemaManager
-     * @param dn The Dn for this serverEntry. Can be null.
-     * @param upIds The list of attributes to create.
-     */
-    public DefaultEntry( SchemaManager schemaManager, Dn dn, String... upIds )
-    {
-        this.schemaManager = schemaManager;
-
-        if ( dn == null )
-        {
-            this.dn = Dn.EMPTY_DN;
-        }
-        else
-        {
-            this.dn = dn;
-            normalizeDN( this.dn );
-        }
-
-        initObjectClassAT();
-
-        set( upIds );
-    }
-
-
-    /**
-     * <p>
-     * Creates a new instance of DefaultEntry, with a
-     * Dn and a list of EntryAttributes.
-     * </p>
-     *
-     * @param dn The Dn for this serverEntry. Can be null
-     * @param attributes The list of attributes to create
-     */
-    public DefaultEntry( Dn dn, Attribute... attributes )
+    //-------------------------------------------------------------------------
+    // Helper methods
+    //-------------------------------------------------------------------------
+    private Entry createEntry( SchemaManager schemaManager, Object... elements ) throws LdapInvalidAttributeValueException,
LdapLdifException
     {
-        this.dn = dn;
+        StringBuilder sb = new StringBuilder();
+        int pos = 0;
+        boolean valueExpected = false;
 
-        for ( Attribute attribute : attributes )
+        for ( Object element : elements )
         {
-            if ( attribute == null )
+            if ( !valueExpected )
             {
-                continue;
-            }
-
-            // Store a new ClientAttribute
-            this.attributes.put( attribute.getId(), attribute );
-        }
-    }
-
+                if ( !( element instanceof String ) )
+                {
+                    throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n.err(
+                        I18n.ERR_12085, ( pos + 1 ) ) );
+                }
 
-    /**
-     * Creates a new instance of DefaultEntry, with a
-     * Dn, a list of ServerAttributes and schema aware.
-     * <p>
-     * No attributes will be created except the ObjectClass attribute,
-     * which will contains "top".
-     * <p>
-     * If any of the AttributeType does not exist, they are simply discarded.
-     *
-     * @param schemaManager The reference to the schemaManager
-     * @param dn The Dn for this serverEntry. Can be null
-     * @param attributes The list of attributes to create
-     */
-    public DefaultEntry( SchemaManager schemaManager, Dn dn, Attribute... attributes )
-    {
-        this.schemaManager = schemaManager;
-        
-        if ( dn == null )
-        {
-            this.dn = Dn.EMPTY_DN;
-        }
-        else
-        {
-            this.dn = dn;
-            normalizeDN( this.dn );
-        }
+                String attribute = ( String ) element;
+                sb.append( attribute );
 
-        if ( schemaManager == null )
-        {
-            if ( attributes != null )
-            {
-                for ( Attribute attribute : attributes )
+                if ( attribute.indexOf( ':' ) != -1 )
                 {
-                    if ( attribute == null )
-                    {
-                        continue;
-                    }
-    
-                    // Store a new ClientAttribute
-                    this.attributes.put( attribute.getId(), attribute );
+                    sb.append( '\n' );
+                }
+                else
+                {
+                    valueExpected = true;
                 }
             }
-        }
-        else
-        {
-            initObjectClassAT();
-    
-            if ( attributes != null )
+            else
             {
-                for ( Attribute attribute : attributes )
+                if ( element instanceof String )
                 {
-                    // Store a new ServerAttribute
-                    try
-                    {
-                        put( attribute );
-                    }
-                    catch ( LdapException ne )
-                    {
-                        LOG.warn( "The ServerAttribute '{}' does not exist. It has been discarded",
attribute );
-                    }
+                    sb.append( ": " ).append( ( String ) element ).append( '\n' );
+                }
+                else if ( element instanceof byte[] )
+                {
+                    sb.append( ":: " );
+                    sb.append( new String( Base64.encode( ( byte[] ) element ) ) );
+                    sb.append( '\n' );
+                }
+                else
+                {
+                    throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n.err(
+                        I18n.ERR_12086, ( pos + 1 ) ) );
                 }
+
+                valueExpected = false;
             }
         }
-    }
 
+        if ( valueExpected )
+        {
+            throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
I18n
+                .err( I18n.ERR_12087 ) );
+        }
 
-    //-------------------------------------------------------------------------
-    // Helper methods
-    //-------------------------------------------------------------------------
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Entry entry = reader.parseEntry( schemaManager, sb.toString() );
+        
+        return entry;
+    }
+    
     /**
      * Get the trimmed and lower cased entry ID
      */
@@ -2597,60 +2480,83 @@ public final class DefaultEntry implemen
     /**
      * {@inheritDoc}
      */
-    public boolean hasObjectClass( String objectClass )
+    public boolean hasObjectClass( String... objectClasses )
     {
-        if ( Strings.isEmpty( objectClass ) )
+        if ( ( objectClasses == null ) || ( objectClasses.length == 0 ) || ( objectClasses[0]
== null ) )
         {
             return false;
         }
         
-        if ( schemaManager != null )
+        for ( String objectClass : objectClasses )
         {
-            return contains( objectClassAttributeType, objectClass );
-        }
-        else
-        {
-            return contains( "objectclass", objectClass );
+            if ( schemaManager != null )
+            {
+                if ( !contains( objectClassAttributeType, objectClass ) )
+                {
+                    return false;
+                }
+            }
+            else
+            {
+                if ( !contains( "objectclass", objectClass ) )
+                {
+                    return false;
+                }
+            }
         }
+        
+        return true;
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public boolean hasObjectClass( Attribute objectClass )
+    public boolean hasObjectClass( Attribute... objectClasses )
     {
-        if ( objectClass == null )
-        {
-            return false;
-        }
-
-        // We have to check that we are checking the ObjectClass attributeType
-        if ( !objectClass.getAttributeType().equals( objectClassAttributeType ) )
-        {
-            return false;
-        }
-
-        Attribute attribute = attributes.get( objectClassAttributeType.getOid() );
-
-        if ( attribute == null )
+        if ( ( objectClasses == null ) || ( objectClasses.length == 0 ) || ( objectClasses[0]
== null ) )
         {
-            // The entry does not have an ObjectClass attribute
             return false;
         }
-
-        for ( Value<?> value : objectClass )
+        
+        for ( Attribute objectClass:objectClasses )
         {
-            // Loop on all the values, and check if they are present
-            if ( !attribute.contains( value.getString() ) )
+            // We have to check that we are checking the ObjectClass attributeType
+            if ( !objectClass.getAttributeType().equals( objectClassAttributeType ) )
+            {
+                return false;
+            }
+    
+            Attribute attribute = attributes.get( objectClassAttributeType.getOid() );
+    
+            if ( attribute == null )
             {
+                // The entry does not have an ObjectClass attribute
                 return false;
             }
+    
+            for ( Value<?> value : objectClass )
+            {
+                // Loop on all the values, and check if they are present
+                if ( !attribute.contains( value.getString() ) )
+                {
+                    return false;
+                }
+            }
         }
 
         return true;
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isSchemaAware()
+    {
+        return schemaManager != null;
+    }
+
 
     /**
      * @see Object#equals(Object)

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java
Wed Apr  6 20:02:31 2011
@@ -66,23 +66,23 @@ public interface Entry extends Cloneable
 
 
     /**
-     * Tells if an entry as a specific ObjectClass value
+     * Tells if an entry as some specific ObjectClasses values
      * 
-     * @param objectClass The ObjectClassw we want to check
-     * @return <code>true</code> if the ObjectClass value is present 
+     * @param objectClasses The ObjectClasses we want to check
+     * @return <code>true</code> if all the ObjectClasses value are present 
      * in the ObjectClass attribute
      */
-    boolean hasObjectClass( String objectClass );
+    boolean hasObjectClass( String... objectClasses );
 
 
     /**
-     * Tells if an entry has a specific ObjectClass Attribute
+     * Tells if an entry has some specific ObjectClasses Attributes
      * 
-     * @param objectClass The ObjectClass we want to check
-     * @return <code>true</code> if the ObjectClass value is present 
+     * @param objectClasses The ObjectClasses we want to check
+     * @return <code>true</code> if the ObjectClasses Attribute are present 
      * in the ObjectClass attribute
      */
-    boolean hasObjectClass( Attribute objectClass );
+    boolean hasObjectClass( Attribute... objectClasses );
 
     
     /**
@@ -843,4 +843,11 @@ public interface Entry extends Cloneable
      * @return the number of attributes
      */
     int size();
+    
+    
+    /**
+     * Tells if the Entry is schema aware
+     * @return true if the Entry is schema aware
+     */
+    boolean isSchemaAware();
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java
Wed Apr  6 20:02:31 2011
@@ -703,22 +703,31 @@ public class ImmutableEntry implements E
     /**
      * {@inheritDoc}
      */
-    public boolean hasObjectClass( String objectClass )
+    public boolean hasObjectClass( String... objectClasses )
     {
-        return entry.hasObjectClass( objectClass );
+        return entry.hasObjectClass( objectClasses );
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public boolean hasObjectClass( Attribute objectClass )
+    public boolean hasObjectClass( Attribute... objectClasses )
     {
-        return entry.hasObjectClass( objectClass );
+        return entry.hasObjectClass( objectClasses );
     }
 
 
     /**
+     * {@inheritDoc}
+     */
+    public boolean isSchemaAware()
+    {
+        return entry.isSchemaAware();
+    }
+    
+    
+    /**
      * @see Object#equals(Object)
      */
     public boolean equals( Object o )

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifAttributesReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifAttributesReader.java?rev=1089607&r1=1089606&r2=1089607&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifAttributesReader.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifAttributesReader.java
Wed Apr  6 20:02:31 2011
@@ -325,16 +325,7 @@ public class LdifAttributesReader extend
             return null;
         }
 
-        Entry entry = null;
-
-        if ( schemaManager != null )
-        {
-            entry = new DefaultEntry( schemaManager );
-        }
-        else
-        {
-            entry = new DefaultEntry();
-        }
+        Entry entry = new DefaultEntry( schemaManager );
 
         // Now, let's iterate through the other lines
         for ( String line : lines )
@@ -583,7 +574,7 @@ public class LdifAttributesReader extend
 
         if ( Strings.isEmpty(ldif) )
         {
-            return new DefaultEntry();
+            return new DefaultEntry( schemaManager );
         }
 
         StringReader strIn = new StringReader( ldif );



Mime
View raw message