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 2009/08/05 19:40:51 UTC

svn commit: r801332 [2/5] - in /directory/shared/trunk: cursor/src/main/java/org/apache/directory/shared/ldap/cursor/ cursor/src/test/java/org/apache/directory/shared/ldap/cursor/ ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/ ldap/src/...

Modified: directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/SingletonCursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/SingletonCursor.java?rev=801332&r1=801331&r2=801332&view=diff
==============================================================================
--- directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/SingletonCursor.java (original)
+++ directory/shared/trunk/cursor/src/main/java/org/apache/directory/shared/ldap/cursor/SingletonCursor.java Wed Aug  5 17:40:50 2009
@@ -1,307 +1,307 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.shared.ldap.cursor;
-
-
-import java.util.Comparator;
-
-
-/**
- * A Cursor over a single element.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class SingletonCursor<E> extends AbstractCursor<E>
-{
-    /** A flag set to true to a*/
-    private boolean beforeFirst = true;
-    private boolean afterLast;
-    private boolean onSingleton;
-    
-    /** The comparator used for this cursor. */
-    private final Comparator<E> comparator;
-    
-    /** The unique element stored in the cursor */
-    private final E singleton;
-
-
-    /**
-     * Creates a new instance of SingletonCursor.
-     *
-     * @param singleton The unique element to store into this cursor
-     */
-    public SingletonCursor( E singleton )
-    {
-        this( singleton, null );
-    }
-
-
-    /**
-     * Creates a new instance of SingletonCursor, with its associated
-     * conmparator
-     *
-     * @param singleton The unique element to store into this cursor
-     * @param comparator The associated comparator
-     */
-    public SingletonCursor( E singleton, Comparator<E> comparator )
-    {
-        this.singleton = singleton;
-        this.comparator = comparator;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean available()
-    {
-        return onSingleton;
-    }
-    
-
-    /**
-     * {@inheritDoc}
-     */
-    public void before( E element ) throws Exception
-    {
-        checkNotClosed( "before()" );
-
-        if ( comparator == null )
-        {
-            throw new UnsupportedOperationException(
-                    "Without a comparator I cannot advance to just before the specified element." );
-        }
-
-        int comparison = comparator.compare( singleton, element );
-
-        if ( comparison < 0 )
-        {
-            first();
-        }
-        else
-        {
-            beforeFirst();
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void after( E element ) throws Exception
-    {
-        checkNotClosed( "after()" );
-
-        if ( comparator == null )
-        {
-            throw new UnsupportedOperationException(
-                    "Without a comparator I cannot advance to just after the specified element." );
-        }
-
-        int comparison = comparator.compare( singleton, element );
-
-        if ( comparison > 0 )
-        {
-            first();
-        }
-        else
-        {
-            afterLast();
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void beforeFirst() throws Exception
-    {
-        checkNotClosed( "()" );
-        beforeFirst = true;
-        afterLast = false;
-        onSingleton = false;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public void afterLast() throws Exception
-    {
-        checkNotClosed( "()" );
-        beforeFirst = false;
-        afterLast = true;
-        onSingleton = false;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean first() throws Exception
-    {
-        checkNotClosed( "()" );
-        beforeFirst = false;
-        onSingleton = true;
-        afterLast = false;
-        return true;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean last() throws Exception
-    {
-        checkNotClosed( "()" );
-        beforeFirst = false;
-        onSingleton = true;
-        afterLast = false;
-        return true;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isFirst() throws Exception
-    {
-        checkNotClosed( "()" );
-        return onSingleton;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isLast() throws Exception
-    {
-        checkNotClosed( "()" );
-        return onSingleton;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isAfterLast() throws Exception
-    {
-        checkNotClosed( "()" );
-        return afterLast;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isBeforeFirst() throws Exception
-    {
-        checkNotClosed( "()" );
-        return beforeFirst;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean previous() throws Exception
-    {
-        checkNotClosed( "()" );
-        
-        if ( beforeFirst )
-        {
-            return false;
-        }
-
-        if ( afterLast )
-        {
-            beforeFirst = false;
-            onSingleton = true;
-            afterLast = false;
-            return true;
-        }
-
-        // must be on the singleton
-        beforeFirst = true;
-        onSingleton = false;
-        afterLast = false;
-        return false;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean next() throws Exception
-    {
-        checkNotClosed( "()" );
-        
-        if ( beforeFirst )
-        {
-            beforeFirst = false;
-            onSingleton = true;
-            afterLast = false;
-            return true;
-        }
-
-        if ( afterLast )
-        {
-            return false;
-        }
-
-        // must be on the singleton
-        beforeFirst = false;
-        onSingleton = false;
-        afterLast = true;
-        return false;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public E get() throws Exception
-    {
-        checkNotClosed( "()" );
-        
-        if ( onSingleton )
-        {
-            return singleton;
-        }
-
-        if ( beforeFirst )
-        {
-            throw new InvalidCursorPositionException( "Cannot access element if positioned before first." );
-        }
-        else
-        {
-            throw new InvalidCursorPositionException( "Cannot access element if positioned after last." );
-        }
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isElementReused()
-    {
-        return true;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.shared.ldap.cursor;
+
+
+import java.util.Comparator;
+
+
+/**
+ * A Cursor over a single element.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SingletonCursor<E> extends AbstractCursor<E>
+{
+    /** A flag set to true to a*/
+    private boolean beforeFirst = true;
+    private boolean afterLast;
+    private boolean onSingleton;
+    
+    /** The comparator used for this cursor. */
+    private final Comparator<E> comparator;
+    
+    /** The unique element stored in the cursor */
+    private final E singleton;
+
+
+    /**
+     * Creates a new instance of SingletonCursor.
+     *
+     * @param singleton The unique element to store into this cursor
+     */
+    public SingletonCursor( E singleton )
+    {
+        this( singleton, null );
+    }
+
+
+    /**
+     * Creates a new instance of SingletonCursor, with its associated
+     * conmparator
+     *
+     * @param singleton The unique element to store into this cursor
+     * @param comparator The associated comparator
+     */
+    public SingletonCursor( E singleton, Comparator<E> comparator )
+    {
+        this.singleton = singleton;
+        this.comparator = comparator;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean available()
+    {
+        return onSingleton;
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void before( E element ) throws Exception
+    {
+        checkNotClosed( "before()" );
+
+        if ( comparator == null )
+        {
+            throw new UnsupportedOperationException(
+                    "Without a comparator I cannot advance to just before the specified element." );
+        }
+
+        int comparison = comparator.compare( singleton, element );
+
+        if ( comparison < 0 )
+        {
+            first();
+        }
+        else
+        {
+            beforeFirst();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void after( E element ) throws Exception
+    {
+        checkNotClosed( "after()" );
+
+        if ( comparator == null )
+        {
+            throw new UnsupportedOperationException(
+                    "Without a comparator I cannot advance to just after the specified element." );
+        }
+
+        int comparison = comparator.compare( singleton, element );
+
+        if ( comparison > 0 )
+        {
+            first();
+        }
+        else
+        {
+            afterLast();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void beforeFirst() throws Exception
+    {
+        checkNotClosed( "()" );
+        beforeFirst = true;
+        afterLast = false;
+        onSingleton = false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void afterLast() throws Exception
+    {
+        checkNotClosed( "()" );
+        beforeFirst = false;
+        afterLast = true;
+        onSingleton = false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean first() throws Exception
+    {
+        checkNotClosed( "()" );
+        beforeFirst = false;
+        onSingleton = true;
+        afterLast = false;
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean last() throws Exception
+    {
+        checkNotClosed( "()" );
+        beforeFirst = false;
+        onSingleton = true;
+        afterLast = false;
+        return true;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFirst() throws Exception
+    {
+        checkNotClosed( "()" );
+        return onSingleton;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLast() throws Exception
+    {
+        checkNotClosed( "()" );
+        return onSingleton;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isAfterLast() throws Exception
+    {
+        checkNotClosed( "()" );
+        return afterLast;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isBeforeFirst() throws Exception
+    {
+        checkNotClosed( "()" );
+        return beforeFirst;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean previous() throws Exception
+    {
+        checkNotClosed( "()" );
+        
+        if ( beforeFirst )
+        {
+            return false;
+        }
+
+        if ( afterLast )
+        {
+            beforeFirst = false;
+            onSingleton = true;
+            afterLast = false;
+            return true;
+        }
+
+        // must be on the singleton
+        beforeFirst = true;
+        onSingleton = false;
+        afterLast = false;
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean next() throws Exception
+    {
+        checkNotClosed( "()" );
+        
+        if ( beforeFirst )
+        {
+            beforeFirst = false;
+            onSingleton = true;
+            afterLast = false;
+            return true;
+        }
+
+        if ( afterLast )
+        {
+            return false;
+        }
+
+        // must be on the singleton
+        beforeFirst = false;
+        onSingleton = false;
+        afterLast = true;
+        return false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public E get() throws Exception
+    {
+        checkNotClosed( "()" );
+        
+        if ( onSingleton )
+        {
+            return singleton;
+        }
+
+        if ( beforeFirst )
+        {
+            throw new InvalidCursorPositionException( "Cannot access element if positioned before first." );
+        }
+        else
+        {
+            throw new InvalidCursorPositionException( "Cannot access element if positioned after last." );
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isElementReused()
+    {
+        return true;
+    }
+}

Modified: directory/shared/trunk/cursor/src/test/java/org/apache/directory/shared/ldap/cursor/ListCursorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/cursor/src/test/java/org/apache/directory/shared/ldap/cursor/ListCursorTest.java?rev=801332&r1=801331&r2=801332&view=diff
==============================================================================
--- directory/shared/trunk/cursor/src/test/java/org/apache/directory/shared/ldap/cursor/ListCursorTest.java (original)
+++ directory/shared/trunk/cursor/src/test/java/org/apache/directory/shared/ldap/cursor/ListCursorTest.java Wed Aug  5 17:40:50 2009
@@ -1,327 +1,327 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.shared.ldap.cursor;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.Test;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-
-/**
- * Tests the ListCursor class.  The assertXxxx() methods defined in this class
- * can be collected in an abstract test case class that can be used to test
- * the behavior of any Cursor implementation down the line.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class ListCursorTest
-{
-    @Test
-    public void testEmptyList() throws Exception
-    {
-        ListCursor<String> cursor = new ListCursor<String>();
-
-        // close test
-        cursor.close();
-        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
-    }
-
-
-    @Test
-    public void testSingleElementList() throws Exception
-    {
-        ListCursor<String> cursor = new ListCursor<String>( Collections.singletonList( "singleton" ) );
-        cursor.close();
-
-        // close test
-        cursor.close();
-        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
-
-        // bad bounds: start = end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 0 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start = end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( 1, Collections.singletonList( "singleton" ) );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start > end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( 5, Collections.singletonList( "singleton" ) );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: end < start is senseless too in another way :)
-        try
-        {
-            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), -5 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start out of range
-        try
-        {
-            cursor = new ListCursor<String>( -5, Collections.singletonList( "singleton" ) );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: end out of range
-        try
-        {
-            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 5 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-    }
-
-
-    @Test
-    public void testManyElementList() throws Exception
-    {
-        List<String> list = new ArrayList<String>();
-        list.add( "item 1" );
-        list.add( "item 2" );
-        list.add( "item 3" );
-        list.add( "item 4" );
-        list.add( "item 5" );
-
-        // test with bounds of the list itself
-        ListCursor<String> cursor = new ListCursor<String>( list );
-        cursor.close();
-
-        // test with nonzero lower bound
-        cursor = new ListCursor<String>( 1, list );
-        cursor.close();
-
-        // test with nonzero lower bound and upper bound
-        cursor = new ListCursor<String>( 1, list, 4 );
-
-        // close test
-        cursor.close();
-        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
-
-        // bad bounds: start = end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( list, 0 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start = end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( 5, list );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start > end is senseless
-        try
-        {
-            cursor = new ListCursor<String>( 10, list );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: end < start is senseless too in another way :)
-        try
-        {
-            cursor = new ListCursor<String>( list, -5 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: start out of range
-        try
-        {
-            cursor = new ListCursor<String>( -5, list );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-
-        // bad bounds: end out of range
-        try
-        {
-            cursor = new ListCursor<String>( list, 10 );
-            cursor.close();
-            fail( "when the start = end bounds this is senseless and should complain" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            assertNotNull( e );
-        }
-    }
-
-
-    protected void assertClosed( Cursor<?> cursor, String msg, boolean expected )
-    {
-        try
-        {
-            assertEquals( msg, expected, cursor.isClosed() );
-        }
-        catch ( Exception e )
-        {
-            fail( "cursor.isClosed() test should not fail after closing the cursor" );
-        }
-
-        try
-        {
-            cursor.close();
-        }
-        catch ( Exception e )
-        {
-            fail( "cursor.close() after closing the cursor should not fail with exceptions" );
-        }
-
-
-        try
-        {
-            cursor.afterLast();
-            fail( "cursor.afterLast() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.beforeFirst();
-            fail( "cursor.beforeFirst() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.first();
-            fail( "cursor.first() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.get();
-            fail( "cursor.get() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.last();
-            fail( "cursor.last() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.next();
-            fail( "cursor.next() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-
-        try
-        {
-            cursor.previous();
-            fail( "cursor.previous() after closing the cursor should fail with an IOException" );
-        }
-        catch ( Exception e )
-        {
-            assertNotNull( e );
-        }
-    }
-}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.shared.ldap.cursor;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Tests the ListCursor class.  The assertXxxx() methods defined in this class
+ * can be collected in an abstract test case class that can be used to test
+ * the behavior of any Cursor implementation down the line.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ListCursorTest
+{
+    @Test
+    public void testEmptyList() throws Exception
+    {
+        ListCursor<String> cursor = new ListCursor<String>();
+
+        // close test
+        cursor.close();
+        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
+    }
+
+
+    @Test
+    public void testSingleElementList() throws Exception
+    {
+        ListCursor<String> cursor = new ListCursor<String>( Collections.singletonList( "singleton" ) );
+        cursor.close();
+
+        // close test
+        cursor.close();
+        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
+
+        // bad bounds: start = end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 0 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start = end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( 1, Collections.singletonList( "singleton" ) );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start > end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( 5, Collections.singletonList( "singleton" ) );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: end < start is senseless too in another way :)
+        try
+        {
+            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), -5 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start out of range
+        try
+        {
+            cursor = new ListCursor<String>( -5, Collections.singletonList( "singleton" ) );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: end out of range
+        try
+        {
+            cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 5 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+    }
+
+
+    @Test
+    public void testManyElementList() throws Exception
+    {
+        List<String> list = new ArrayList<String>();
+        list.add( "item 1" );
+        list.add( "item 2" );
+        list.add( "item 3" );
+        list.add( "item 4" );
+        list.add( "item 5" );
+
+        // test with bounds of the list itself
+        ListCursor<String> cursor = new ListCursor<String>( list );
+        cursor.close();
+
+        // test with nonzero lower bound
+        cursor = new ListCursor<String>( 1, list );
+        cursor.close();
+
+        // test with nonzero lower bound and upper bound
+        cursor = new ListCursor<String>( 1, list, 4 );
+
+        // close test
+        cursor.close();
+        assertClosed( cursor, "cursor.isCloased() should return true after closing the cursor", true );
+
+        // bad bounds: start = end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( list, 0 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start = end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( 5, list );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start > end is senseless
+        try
+        {
+            cursor = new ListCursor<String>( 10, list );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: end < start is senseless too in another way :)
+        try
+        {
+            cursor = new ListCursor<String>( list, -5 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: start out of range
+        try
+        {
+            cursor = new ListCursor<String>( -5, list );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+
+        // bad bounds: end out of range
+        try
+        {
+            cursor = new ListCursor<String>( list, 10 );
+            cursor.close();
+            fail( "when the start = end bounds this is senseless and should complain" );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            assertNotNull( e );
+        }
+    }
+
+
+    protected void assertClosed( Cursor<?> cursor, String msg, boolean expected )
+    {
+        try
+        {
+            assertEquals( msg, expected, cursor.isClosed() );
+        }
+        catch ( Exception e )
+        {
+            fail( "cursor.isClosed() test should not fail after closing the cursor" );
+        }
+
+        try
+        {
+            cursor.close();
+        }
+        catch ( Exception e )
+        {
+            fail( "cursor.close() after closing the cursor should not fail with exceptions" );
+        }
+
+
+        try
+        {
+            cursor.afterLast();
+            fail( "cursor.afterLast() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.beforeFirst();
+            fail( "cursor.beforeFirst() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.first();
+            fail( "cursor.first() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.get();
+            fail( "cursor.get() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.last();
+            fail( "cursor.last() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.next();
+            fail( "cursor.next() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+
+        try
+        {
+            cursor.previous();
+            fail( "cursor.previous() after closing the cursor should fail with an IOException" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull( e );
+        }
+    }
+}

Modified: directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/UniversalContextFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/UniversalContextFactory.java?rev=801332&r1=801331&r2=801332&view=diff
==============================================================================
--- directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/UniversalContextFactory.java (original)
+++ directory/shared/trunk/ldap-jndi/src/main/java/org/apache/directory/shared/ldap/jndi/UniversalContextFactory.java Wed Aug  5 17:40:50 2009
@@ -1,86 +1,86 @@
-/*
- *   Licensed to the Apache Software Foundation (ASF) under one
- *   or more contributor license agreements.  See the NOTICE file
- *   distributed with this work for additional information
- *   regarding copyright ownership.  The ASF licenses this file
- *   to you under the Apache License, Version 2.0 (the
- *   "License"); you may not use this file except in compliance
- *   with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing,
- *   software distributed under the License is distributed on an
- *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *   KIND, either express or implied.  See the License for the
- *   specific language governing permissions and limitations
- *   under the License.
- *
- */
-package org.apache.directory.shared.ldap.jndi;
-
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-
-
-/**
- * A context factory that delegates calls to the underlying JNDI 
- * implementation of the JVM.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class UniversalContextFactory implements InitialContextFactory
-{
-    private static final String SUN_ICF_FQCN = "com.sun.jndi.ldap.LdapCtxFactory";
-    private static final String IBM_ICF_FQCN = "com.ibm.jndi.LDAPCtxFactory";
-    private static final String BEA_ICF_FQCN = SUN_ICF_FQCN;  // JRocket might use SUN classes
-    private static final String ICF_FQCN;
-    
-    
-    static
-    {
-        // -------------------------------------------------------------------
-        // for lack of a better approach we're just checking the JVM here and 
-        // setting the ICF_FQCN based on that using a bunch of conditional tests
-        // -------------------------------------------------------------------
-        
-        String jvmVendor = System.getProperty( "java.vm.vendor" );
-        
-        if ( jvmVendor.equalsIgnoreCase( "SUN Microsystems, Inc." ) )
-        {
-            ICF_FQCN = SUN_ICF_FQCN;
-        }
-        else if ( jvmVendor.equalsIgnoreCase( "BEA Systems, Inc." ) )
-        {
-            ICF_FQCN = BEA_ICF_FQCN;
-        }
-        else if ( jvmVendor.equalsIgnoreCase( "IBM, Inc." ) )
-        {
-            ICF_FQCN = IBM_ICF_FQCN;
-        }
-        else
-        {
-            ICF_FQCN = "Unknown";
-        }
-    }
-    
-    
-    private final InitialContextFactory factory;
-    
-    
-    public UniversalContextFactory() throws InstantiationException, IllegalAccessException, ClassNotFoundException
-    {
-        factory = ( InitialContextFactory ) Class.forName( ICF_FQCN ).newInstance();
-    }
-    
-    
-    public Context getInitialContext( Hashtable<?, ?> env ) throws NamingException
-    {
-        return factory.getInitialContext( env );
-    }
-}
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.jndi;
+
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+
+/**
+ * A context factory that delegates calls to the underlying JNDI 
+ * implementation of the JVM.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class UniversalContextFactory implements InitialContextFactory
+{
+    private static final String SUN_ICF_FQCN = "com.sun.jndi.ldap.LdapCtxFactory";
+    private static final String IBM_ICF_FQCN = "com.ibm.jndi.LDAPCtxFactory";
+    private static final String BEA_ICF_FQCN = SUN_ICF_FQCN;  // JRocket might use SUN classes
+    private static final String ICF_FQCN;
+    
+    
+    static
+    {
+        // -------------------------------------------------------------------
+        // for lack of a better approach we're just checking the JVM here and 
+        // setting the ICF_FQCN based on that using a bunch of conditional tests
+        // -------------------------------------------------------------------
+        
+        String jvmVendor = System.getProperty( "java.vm.vendor" );
+        
+        if ( jvmVendor.equalsIgnoreCase( "SUN Microsystems, Inc." ) )
+        {
+            ICF_FQCN = SUN_ICF_FQCN;
+        }
+        else if ( jvmVendor.equalsIgnoreCase( "BEA Systems, Inc." ) )
+        {
+            ICF_FQCN = BEA_ICF_FQCN;
+        }
+        else if ( jvmVendor.equalsIgnoreCase( "IBM, Inc." ) )
+        {
+            ICF_FQCN = IBM_ICF_FQCN;
+        }
+        else
+        {
+            ICF_FQCN = "Unknown";
+        }
+    }
+    
+    
+    private final InitialContextFactory factory;
+    
+    
+    public UniversalContextFactory() throws InstantiationException, IllegalAccessException, ClassNotFoundException
+    {
+        factory = ( InitialContextFactory ) Class.forName( ICF_FQCN ).newInstance();
+    }
+    
+    
+    public Context getInitialContext( Hashtable<?, ?> env ) throws NamingException
+    {
+        return factory.getInitialContext( env );
+    }
+}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=801332&r1=801331&r2=801332&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java Wed Aug  5 17:40:50 2009
@@ -1,402 +1,402 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.shared.ldap.entry;
-
-
-import java.io.Externalizable;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.naming.NamingException;
-
-import org.apache.directory.shared.ldap.name.LdapDN;
-
-
-/**
- * <p>
- * This interface represent a LDAP entry. An LDAP entry contains :
- * <li> A distinguished name (DN)</li>
- * <li> A list of attributes</li>
- * </p>
- * <p>
- * The available methods on this object are described in this interface.
- * </p>
- * <p>
- * This interface is used by the serverEntry and clientEntry interfaces.
- *</p>
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public interface Entry extends Cloneable, Iterable<EntryAttribute>, Externalizable
-{
-    /**
-     * Remove all the attributes for this entry. The DN is not reset
-     */
-    void clear();
-
-
-    /**
-     * Clone the current entry
-     */
-    Entry clone();
-
-
-    /**
-     * Get this entry's DN.
-     *
-     * @return The entry's DN
-     */
-    LdapDN getDn();
-
-
-    /**
-     * Tells if an entry as a specific ObjectClass value
-     * 
-     * @param objectClass The ObjectClassw we want to check
-     * @return <code>true</code> if the ObjectClass value is present 
-     * in the ObjectClass attribute
-     */
-    boolean hasObjectClass( String objectClass );
-
-
-    /**
-     * <p>
-     * Returns the attribute with the specified alias. The return value
-     * is <code>null</code> if no match is found.  
-     * </p>
-     * <p>An Attribute with an id different from the supplied alias may 
-     * be returned: for example a call with 'cn' may in some implementations 
-     * return an Attribute whose getId() field returns 'commonName'.
-     * </p>
-     *
-     * @param alias an aliased name of the attribute identifier
-     * @return the attribute associated with the alias
-     */
-    EntryAttribute get( String alias );
-
-
-    /**
-     * <p>
-     * Put some new ClientAttribute using the User Provided ID. 
-     * No value is inserted. 
-     * </p>
-     * <p>
-     * If an existing Attribute is found, it will be replaced by an
-     * empty attribute, and returned to the caller.
-     * </p>
-     * 
-     * @param upIds The user provided IDs of the AttributeTypes to add.
-     * @return A list of replaced Attributes.
-     */
-    List<EntryAttribute> set( String... upIds );
-
-
-    /**
-     * Set this entry's DN.
-     *
-     * @param dn The DN associated with this entry
-     */
-    void setDn( LdapDN dn );
-
-
-    /**
-     * Returns an enumeration containing the zero or more attributes in the
-     * collection. The behavior of the enumeration is not specified if the
-     * attribute collection is changed.
-     *
-     * @return an enumeration of all contained attributes
-     */
-    Iterator<EntryAttribute> iterator();
-
-
-    /**
-     * Add some Attributes to the current Entry.
-     *
-     * @param attributes The attributes to add
-     * @throws NamingException If we can't add any of the attributes
-     */
-    void add( EntryAttribute... attributes ) throws NamingException;
-
-
-    /**
-     * Add some String values to the current Entry.
-     *
-     * @param upId The user provided ID of the attribute we want to add 
-     * some values to
-     * @param values The list of String values to add
-     * @throws NamingException If we can't add any of the values
-     */
-    void add( String upId, String... values ) throws NamingException;
-
-
-    /**
-     * Add some binary values to the current Entry.
-     *
-     * @param upId The user provided ID of the attribute we want to add 
-     * some values to
-     * @param values The list of binary values to add
-     * @throws NamingException If we can't add any of the values
-     */
-    void add( String upId, byte[]... values ) throws NamingException;
-
-
-    /**
-     * Add some Values to the current Entry.
-     *
-     * @param upId The user provided ID of the attribute we want to add 
-     * some values to
-     * @param values The list of Values to add
-     * @throws NamingException If we can't add any of the values
-     */
-    void add( String upId, Value<?>... values ) throws NamingException;
-
-
-    /**
-     * <p>
-     * Places attributes in the attribute collection. 
-     * </p>
-     * <p>If there is already an attribute with the same ID as any of the 
-     * new attributes, the old ones are removed from the collection and 
-     * are returned by this method. If there was no attribute with the 
-     * same ID the return value is <code>null</code>.
-     *</p>
-     *
-     * @param attributes the attributes to be put
-     * @return the old attributes with the same OID, if exist; otherwise
-     *         <code>null</code>
-     * @exception NamingException if the operation fails
-     */
-    List<EntryAttribute> put( EntryAttribute... attributes ) throws NamingException;
-
-
-    /**
-     * <p>
-     * Put an attribute (represented by its ID and some binary values) into an entry. 
-     * </p>
-     * <p> 
-     * If the attribute already exists, the previous attribute will be 
-     * replaced and returned.
-     * </p>
-     *
-     * @param upId The attribute ID
-     * @param values The list of binary values to put. It can be empty.
-     * @return The replaced attribute
-     */
-    EntryAttribute put( String upId, byte[]... values );
-
-
-    /**
-     * <p>
-     * Put an attribute (represented by its ID and some String values) into an entry. 
-     * </p>
-     * <p> 
-     * If the attribute already exists, the previous attribute will be 
-     * replaced and returned.
-     * </p>
-     *
-     * @param upId The attribute ID
-     * @param values The list of String values to put. It can be empty.
-     * @return The replaced attribute
-     */
-    EntryAttribute put( String upId, String... values );
-
-
-    /**
-     * <p>
-     * Put an attribute (represented by its ID and some values) into an entry. 
-     * </p>
-     * <p> 
-     * If the attribute already exists, the previous attribute will be 
-     * replaced and returned.
-     * </p>
-     *
-     * @param upId The attribute ID
-     * @param values The list of values to put. It can be empty.
-     * @return The replaced attribute
-     */
-    EntryAttribute put( String upId, Value<?>... values );
-
-
-    /**
-      * Removes the specified attributes. The removed attributes are
-      * returned by this method. If there were no attribute the return value
-      * is <code>null</code>.
-      *
-      * @param attributes the attributes to be removed
-      * @return the removed attribute, if exists; otherwise <code>null</code>
-      */
-    List<EntryAttribute> remove( EntryAttribute... attributes ) throws NamingException;
-
-
-    /**
-     * <p>
-     * Removes the specified binary values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param upId The attribute ID  
-     * @param attributes the attributes to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( String upId, byte[]... values ) throws NamingException;
-
-
-    /**
-     * <p>
-     * Removes the specified String values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after havong removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param upId The attribute ID  
-     * @param attributes the attributes to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if no values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( String upId, String... values ) throws NamingException;
-
-
-    /**
-     * <p>
-     * Removes the specified values from an attribute.
-     * </p>
-     * <p>
-     * If at least one value is removed, this method returns <code>true</code>.
-     * </p>
-     * <p>
-     * If there is no more value after having removed the values, the attribute
-     * will be removed too.
-     * </p>
-     * <p>
-     * If the attribute does not exist, nothing is done and the method returns 
-     * <code>false</code>
-     * </p> 
-     *
-     * @param upId The attribute ID  
-     * @param attributes the attributes to be removed
-     * @return <code>true</code> if at least a value is removed, <code>false</code>
-     * if not all the values have been removed or if the attribute does not exist. 
-     */
-    boolean remove( String upId, Value<?>... values ) throws NamingException;
-
-
-    /**
-      * <p>
-      * Removes the attribute with the specified alias. 
-      * </p>
-      * <p>
-      * The removed attribute are returned by this method. 
-      * </p>
-      * <p>
-      * If there is no attribute with the specified alias,
-      * the return value is <code>null</code>.
-      * </p>
-      *
-      * @param attributes an aliased name of the attribute to be removed
-      * @return the removed attributes, if any, as a list; otherwise <code>null</code>
-      */
-    List<EntryAttribute> removeAttributes( String... attributes );
-
-
-    /**
-     * <p>
-     * Checks if an entry contains a list of attributes.
-     * </p>
-     * <p>
-     * If the list is null or empty, this method will return <code>true</code>
-     * if the entry has no attribute, <code>false</code> otherwise.
-     * </p>
-     *
-     * @param attributes The Attributes to look for
-     * @return <code>true</code> if all the attributes are found within 
-     * the entry, <code>false</code> if at least one of them is not present.
-     * @throws NamingException If the attribute does not exist
-     */
-    boolean contains( EntryAttribute... attributes ) throws NamingException;
-
-
-    /**
-     * Checks if an entry contains an attribute with some binary values.
-     *
-     * @param id The Attribute we are looking for.
-     * @param values The searched values.
-     * @return <code>true</code> if all the values are found within the attribute,
-     * false if at least one value is not present or if the ID is not valid. 
-     */
-    boolean contains( String upId, byte[]... values );
-
-
-    /**
-     * Checks if an entry contains an attribute with some String values.
-     *
-     * @param id The Attribute we are looking for.
-     * @param values The searched values.
-     * @return <code>true</code> if all the values are found within the attribute,
-     * false if at least one value is not present or if the ID is not valid. 
-     */
-    boolean contains( String upId, String... values );
-
-
-    /**
-     * Checks if an entry contains an attribute with some values.
-     *
-     * @param id The Attribute we are looking for.
-     * @param values The searched values.
-     * @return <code>true</code> if all the values are found within the attribute,
-     * false if at least one value is not present or if the ID is not valid. 
-     */
-    boolean contains( String upId, Value<?>... values );
-
-
-    /**
-     * Checks if an entry contains some specific attributes.
-     *
-     * @param attributes The Attributes to look for.
-     * @return <code>true</code> if the attributes are all found within the entry.
-     */
-    boolean containsAttribute( String... attributes );
-
-    
-    /**
-     * Returns the number of attributes.
-     *
-     * @return the number of attributes
-     */
-    int size();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.shared.ldap.entry;
+
+
+import java.io.Externalizable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+
+/**
+ * <p>
+ * This interface represent a LDAP entry. An LDAP entry contains :
+ * <li> A distinguished name (DN)</li>
+ * <li> A list of attributes</li>
+ * </p>
+ * <p>
+ * The available methods on this object are described in this interface.
+ * </p>
+ * <p>
+ * This interface is used by the serverEntry and clientEntry interfaces.
+ *</p>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface Entry extends Cloneable, Iterable<EntryAttribute>, Externalizable
+{
+    /**
+     * Remove all the attributes for this entry. The DN is not reset
+     */
+    void clear();
+
+
+    /**
+     * Clone the current entry
+     */
+    Entry clone();
+
+
+    /**
+     * Get this entry's DN.
+     *
+     * @return The entry's DN
+     */
+    LdapDN getDn();
+
+
+    /**
+     * Tells if an entry as a specific ObjectClass value
+     * 
+     * @param objectClass The ObjectClassw we want to check
+     * @return <code>true</code> if the ObjectClass value is present 
+     * in the ObjectClass attribute
+     */
+    boolean hasObjectClass( String objectClass );
+
+
+    /**
+     * <p>
+     * Returns the attribute with the specified alias. The return value
+     * is <code>null</code> if no match is found.  
+     * </p>
+     * <p>An Attribute with an id different from the supplied alias may 
+     * be returned: for example a call with 'cn' may in some implementations 
+     * return an Attribute whose getId() field returns 'commonName'.
+     * </p>
+     *
+     * @param alias an aliased name of the attribute identifier
+     * @return the attribute associated with the alias
+     */
+    EntryAttribute get( String alias );
+
+
+    /**
+     * <p>
+     * Put some new ClientAttribute using the User Provided ID. 
+     * No value is inserted. 
+     * </p>
+     * <p>
+     * If an existing Attribute is found, it will be replaced by an
+     * empty attribute, and returned to the caller.
+     * </p>
+     * 
+     * @param upIds The user provided IDs of the AttributeTypes to add.
+     * @return A list of replaced Attributes.
+     */
+    List<EntryAttribute> set( String... upIds );
+
+
+    /**
+     * Set this entry's DN.
+     *
+     * @param dn The DN associated with this entry
+     */
+    void setDn( LdapDN dn );
+
+
+    /**
+     * Returns an enumeration containing the zero or more attributes in the
+     * collection. The behavior of the enumeration is not specified if the
+     * attribute collection is changed.
+     *
+     * @return an enumeration of all contained attributes
+     */
+    Iterator<EntryAttribute> iterator();
+
+
+    /**
+     * Add some Attributes to the current Entry.
+     *
+     * @param attributes The attributes to add
+     * @throws NamingException If we can't add any of the attributes
+     */
+    void add( EntryAttribute... attributes ) throws NamingException;
+
+
+    /**
+     * Add some String values to the current Entry.
+     *
+     * @param upId The user provided ID of the attribute we want to add 
+     * some values to
+     * @param values The list of String values to add
+     * @throws NamingException If we can't add any of the values
+     */
+    void add( String upId, String... values ) throws NamingException;
+
+
+    /**
+     * Add some binary values to the current Entry.
+     *
+     * @param upId The user provided ID of the attribute we want to add 
+     * some values to
+     * @param values The list of binary values to add
+     * @throws NamingException If we can't add any of the values
+     */
+    void add( String upId, byte[]... values ) throws NamingException;
+
+
+    /**
+     * Add some Values to the current Entry.
+     *
+     * @param upId The user provided ID of the attribute we want to add 
+     * some values to
+     * @param values The list of Values to add
+     * @throws NamingException If we can't add any of the values
+     */
+    void add( String upId, Value<?>... values ) throws NamingException;
+
+
+    /**
+     * <p>
+     * Places attributes in the attribute collection. 
+     * </p>
+     * <p>If there is already an attribute with the same ID as any of the 
+     * new attributes, the old ones are removed from the collection and 
+     * are returned by this method. If there was no attribute with the 
+     * same ID the return value is <code>null</code>.
+     *</p>
+     *
+     * @param attributes the attributes to be put
+     * @return the old attributes with the same OID, if exist; otherwise
+     *         <code>null</code>
+     * @exception NamingException if the operation fails
+     */
+    List<EntryAttribute> put( EntryAttribute... attributes ) throws NamingException;
+
+
+    /**
+     * <p>
+     * Put an attribute (represented by its ID and some binary values) into an entry. 
+     * </p>
+     * <p> 
+     * If the attribute already exists, the previous attribute will be 
+     * replaced and returned.
+     * </p>
+     *
+     * @param upId The attribute ID
+     * @param values The list of binary values to put. It can be empty.
+     * @return The replaced attribute
+     */
+    EntryAttribute put( String upId, byte[]... values );
+
+
+    /**
+     * <p>
+     * Put an attribute (represented by its ID and some String values) into an entry. 
+     * </p>
+     * <p> 
+     * If the attribute already exists, the previous attribute will be 
+     * replaced and returned.
+     * </p>
+     *
+     * @param upId The attribute ID
+     * @param values The list of String values to put. It can be empty.
+     * @return The replaced attribute
+     */
+    EntryAttribute put( String upId, String... values );
+
+
+    /**
+     * <p>
+     * Put an attribute (represented by its ID and some values) into an entry. 
+     * </p>
+     * <p> 
+     * If the attribute already exists, the previous attribute will be 
+     * replaced and returned.
+     * </p>
+     *
+     * @param upId The attribute ID
+     * @param values The list of values to put. It can be empty.
+     * @return The replaced attribute
+     */
+    EntryAttribute put( String upId, Value<?>... values );
+
+
+    /**
+      * Removes the specified attributes. The removed attributes are
+      * returned by this method. If there were no attribute the return value
+      * is <code>null</code>.
+      *
+      * @param attributes the attributes to be removed
+      * @return the removed attribute, if exists; otherwise <code>null</code>
+      */
+    List<EntryAttribute> remove( EntryAttribute... attributes ) throws NamingException;
+
+
+    /**
+     * <p>
+     * Removes the specified binary values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after having removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param upId The attribute ID  
+     * @param attributes the attributes to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if not all the values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( String upId, byte[]... values ) throws NamingException;
+
+
+    /**
+     * <p>
+     * Removes the specified String values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after havong removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param upId The attribute ID  
+     * @param attributes the attributes to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if no values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( String upId, String... values ) throws NamingException;
+
+
+    /**
+     * <p>
+     * Removes the specified values from an attribute.
+     * </p>
+     * <p>
+     * If at least one value is removed, this method returns <code>true</code>.
+     * </p>
+     * <p>
+     * If there is no more value after having removed the values, the attribute
+     * will be removed too.
+     * </p>
+     * <p>
+     * If the attribute does not exist, nothing is done and the method returns 
+     * <code>false</code>
+     * </p> 
+     *
+     * @param upId The attribute ID  
+     * @param attributes the attributes to be removed
+     * @return <code>true</code> if at least a value is removed, <code>false</code>
+     * if not all the values have been removed or if the attribute does not exist. 
+     */
+    boolean remove( String upId, Value<?>... values ) throws NamingException;
+
+
+    /**
+      * <p>
+      * Removes the attribute with the specified alias. 
+      * </p>
+      * <p>
+      * The removed attribute are returned by this method. 
+      * </p>
+      * <p>
+      * If there is no attribute with the specified alias,
+      * the return value is <code>null</code>.
+      * </p>
+      *
+      * @param attributes an aliased name of the attribute to be removed
+      * @return the removed attributes, if any, as a list; otherwise <code>null</code>
+      */
+    List<EntryAttribute> removeAttributes( String... attributes );
+
+
+    /**
+     * <p>
+     * Checks if an entry contains a list of attributes.
+     * </p>
+     * <p>
+     * If the list is null or empty, this method will return <code>true</code>
+     * if the entry has no attribute, <code>false</code> otherwise.
+     * </p>
+     *
+     * @param attributes The Attributes to look for
+     * @return <code>true</code> if all the attributes are found within 
+     * the entry, <code>false</code> if at least one of them is not present.
+     * @throws NamingException If the attribute does not exist
+     */
+    boolean contains( EntryAttribute... attributes ) throws NamingException;
+
+
+    /**
+     * Checks if an entry contains an attribute with some binary values.
+     *
+     * @param id The Attribute we are looking for.
+     * @param values The searched values.
+     * @return <code>true</code> if all the values are found within the attribute,
+     * false if at least one value is not present or if the ID is not valid. 
+     */
+    boolean contains( String upId, byte[]... values );
+
+
+    /**
+     * Checks if an entry contains an attribute with some String values.
+     *
+     * @param id The Attribute we are looking for.
+     * @param values The searched values.
+     * @return <code>true</code> if all the values are found within the attribute,
+     * false if at least one value is not present or if the ID is not valid. 
+     */
+    boolean contains( String upId, String... values );
+
+
+    /**
+     * Checks if an entry contains an attribute with some values.
+     *
+     * @param id The Attribute we are looking for.
+     * @param values The searched values.
+     * @return <code>true</code> if all the values are found within the attribute,
+     * false if at least one value is not present or if the ID is not valid. 
+     */
+    boolean contains( String upId, Value<?>... values );
+
+
+    /**
+     * Checks if an entry contains some specific attributes.
+     *
+     * @param attributes The Attributes to look for.
+     * @return <code>true</code> if the attributes are all found within the entry.
+     */
+    boolean containsAttribute( String... attributes );
+
+    
+    /**
+     * Returns the number of attributes.
+     *
+     * @return the number of attributes
+     */
+    int size();
+}