Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 63985 invoked from network); 27 May 2010 08:09:23 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 May 2010 08:09:23 -0000 Received: (qmail 90661 invoked by uid 500); 27 May 2010 08:09:23 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 90602 invoked by uid 500); 27 May 2010 08:09:23 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 90595 invoked by uid 99); 27 May 2010 08:09:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 May 2010 08:09:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 May 2010 08:09:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 199652388A66; Thu, 27 May 2010 08:08:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r948711 [3/7] - in /directory: apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/ apacheds/trunk/core-integ/src/test/java/org/apache/... Date: Thu, 27 May 2010 08:08:45 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100527080849.199652388A66@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java?rev=948711&r1=948710&r2=948711&view=diff ============================================================================== --- directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java (original) +++ directory/apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/entry/SchemaAwareModificationTest.java Thu May 27 08:08:44 2010 @@ -34,8 +34,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.List; -import org.apache.directory.shared.ldap.entry.DefaultModification; import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute; +import org.apache.directory.shared.ldap.entry.DefaultModification; import org.apache.directory.shared.ldap.entry.EntryAttribute; import org.apache.directory.shared.ldap.entry.Modification; import org.apache.directory.shared.ldap.entry.ModificationOperation; @@ -62,11 +62,11 @@ public class SchemaAwareModificationTest private static LdifSchemaLoader loader; private static SchemaManager schemaManager; private static AttributeType atCN; - + // A SINGLE-VALUE attribute - private static AttributeType atC; - - + private static AttributeType atC; + + /** * Serialize a DefaultModification */ @@ -100,15 +100,16 @@ public class SchemaAwareModificationTest throw ioe; } } - + return out; } - - + + /** * Deserialize a DefaultModification */ - private DefaultModification deserializeValue( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException, LdapException + private DefaultModification deserializeValue( ByteArrayOutputStream out ) throws IOException, + ClassNotFoundException, LdapException { ObjectInputStream oIn = null; ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() ); @@ -141,33 +142,33 @@ public class SchemaAwareModificationTest } } } - - + + /** * Initialize the registries once for the whole test suite */ @BeforeClass public static void setup() throws Exception { - String workingDirectory = System.getProperty( "workingDirectory" ); - + String workingDirectory = System.getProperty( "workingDirectory" ); + if ( workingDirectory == null ) { String path = SchemaAwareModificationTest.class.getResource( "" ).getPath(); int targetPos = path.indexOf( "target" ); workingDirectory = path.substring( 0, targetPos + 6 ); } - - File schemaRepository = new File( workingDirectory, "schema" ); + + File schemaRepository = new File( workingDirectory, "schema" ); SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) ); extractor.extractOrCopy( true ); loader = new LdifSchemaLoader( schemaRepository ); - + schemaManager = new DefaultSchemaManager( loader ); schemaManager.loadAllEnabled(); - + List errors = schemaManager.getErrors(); - + if ( errors.size() != 0 ) { fail( "Schema load failed : " + LdapExceptionUtils.printErrors( errors ) ); @@ -178,18 +179,19 @@ public class SchemaAwareModificationTest } - @Test public void testCreateClientModification() + @Test + public void testCreateClientModification() { EntryAttribute attribute = new DefaultEntryAttribute( atCN ); attribute.add( "test1", "test2" ); - + Modification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute ); Modification clone = mod.clone(); - + attribute.remove( "test2" ); - + EntryAttribute clonedAttribute = clone.getAttribute(); - + assertEquals( 1, mod.getAttribute().size() ); assertTrue( mod.getAttribute().contains( "test1" ) ); @@ -197,8 +199,8 @@ public class SchemaAwareModificationTest assertTrue( clone.getAttribute().contains( "test1" ) ); assertTrue( clone.getAttribute().contains( "test2" ) ); } - - + + /** * Test the copy constructor with a DefaultModification * @@ -209,21 +211,21 @@ public class SchemaAwareModificationTest EntryAttribute attribute = new DefaultEntryAttribute( atC ); attribute.add( "test1", "test2" ); Modification serverModification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute ); - + Modification copy = new DefaultModification( schemaManager, serverModification ); - + assertTrue( copy instanceof DefaultModification ); assertEquals( copy, serverModification ); - + serverModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE ); assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() ); - + EntryAttribute attribute2 = new DefaultEntryAttribute( atCN, "t" ); serverModification.setAttribute( attribute2 ); assertNotSame( attribute2, copy.getAttribute() ); } - - + + /** * Test the copy constructor with a DefaultModification * @@ -234,78 +236,78 @@ public class SchemaAwareModificationTest EntryAttribute attribute = new DefaultEntryAttribute( atC.getName() ); attribute.add( "test1", "test2" ); Modification clientModification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute ); - + Modification copy = new DefaultModification( schemaManager, clientModification ); - + assertTrue( copy instanceof DefaultModification ); assertTrue( copy instanceof DefaultModification ); - assertFalse( copy.equals( clientModification ) ); + assertFalse( copy.equals( clientModification ) ); assertTrue( copy.getAttribute() instanceof EntryAttribute ); assertEquals( atC, copy.getAttribute().getAttributeType() ); assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() ); assertTrue( copy.getAttribute().contains( "test1", "test2" ) ); - + clientModification.setOperation( ModificationOperation.REMOVE_ATTRIBUTE ); assertEquals( ModificationOperation.ADD_ATTRIBUTE, copy.getOperation() ); - + EntryAttribute attribute2 = new DefaultEntryAttribute( "cn", "t" ); clientModification.setAttribute( attribute2 ); assertNotSame( attribute2, copy.getAttribute() ); } - - + + @Test public void testSerializationModificationADD() throws ClassNotFoundException, IOException, LdapException { EntryAttribute attribute = new DefaultEntryAttribute( atCN ); attribute.add( "test1", "test2" ); - + DefaultModification mod = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attribute ); - + Modification modSer = deserializeValue( serializeValue( mod ) ); - + assertEquals( mod, modSer ); } - - + + @Test public void testSerializationModificationREPLACE() throws ClassNotFoundException, IOException, LdapException { EntryAttribute attribute = new DefaultEntryAttribute( atCN ); attribute.add( "test1", "test2" ); - + DefaultModification mod = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attribute ); - + Modification modSer = deserializeValue( serializeValue( mod ) ); - + assertEquals( mod, modSer ); } - - + + @Test public void testSerializationModificationREMOVE() throws ClassNotFoundException, IOException, LdapException { EntryAttribute attribute = new DefaultEntryAttribute( atCN ); attribute.add( "test1", "test2" ); - + DefaultModification mod = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attribute ); - + Modification modSer = deserializeValue( serializeValue( mod ) ); - + assertEquals( mod, modSer ); } - - + + @Test public void testSerializationModificationNoAttribute() throws ClassNotFoundException, IOException, LdapException { Modification mod = new DefaultModification(); - + mod.setOperation( ModificationOperation.ADD_ATTRIBUTE ); - + try { - deserializeValue( serializeValue( (DefaultModification)mod ) ); + deserializeValue( serializeValue( ( DefaultModification ) mod ) ); fail(); } catch ( IOException ioe ) Modified: directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java?rev=948711&r1=948710&r2=948711&view=diff ============================================================================== --- directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java (original) +++ directory/apacheds/trunk/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapImpl.java Thu May 27 08:08:44 2010 @@ -33,29 +33,30 @@ import java.util.List; * @author Apache Directory Project * @version $Rev$, $Date$ */ -public class AvlTreeMapImpl implements AvlTreeMap +public class AvlTreeMapImpl implements AvlTreeMap { /** the root of the tree */ - private LinkedAvlMapNode root; + private LinkedAvlMapNode root; /** The Comparator used for comparing the keys */ private Comparator keyComparator; /** The Comparator used for comparing the values */ private Comparator valueComparator; - + /** node representing the start of the doubly linked list formed with the tree nodes */ - private LinkedAvlMapNode first; - + private LinkedAvlMapNode first; + /** node representing the end of the doubly linked list formed with the tree nodes */ - private LinkedAvlMapNode last; - + private LinkedAvlMapNode last; + /** flag to allow storing duplicate keys */ private boolean allowDuplicates; /** size of the map */ private int size; + /** * Creates a new instance of AVLTreeMap without support for duplicate keys. * @@ -65,7 +66,7 @@ public class AvlTreeMapImpl impleme { this( keyComparator, valueComparator, false ); } - + public AvlTreeMapImpl( Comparator keyComparator, Comparator valueComparator, boolean allowDuplicates ) { @@ -74,7 +75,7 @@ public class AvlTreeMapImpl impleme this.allowDuplicates = allowDuplicates; } - + /** * {@inheritDoc} */ @@ -82,7 +83,7 @@ public class AvlTreeMapImpl impleme { return keyComparator; } - + /** * {@inheritDoc} @@ -91,42 +92,42 @@ public class AvlTreeMapImpl impleme { return valueComparator; } - - + + /** * {@inheritDoc} */ public V insert( K key, V value ) { - LinkedAvlMapNode node, temp; - LinkedAvlMapNode parent = null; + LinkedAvlMapNode node, temp; + LinkedAvlMapNode parent = null; int c; - + if ( root == null ) { - root = new LinkedAvlMapNode( key, value ); - first = root; - last = root; - size++; - return null; - } - - node = new LinkedAvlMapNode( key, value ); - + root = new LinkedAvlMapNode( key, value ); + first = root; + last = root; + size++; + return null; + } + + node = new LinkedAvlMapNode( key, value ); + temp = root; - - List> treePath = new ArrayList>(); - while( temp != null ) + List> treePath = new ArrayList>(); + + while ( temp != null ) { - treePath.add(0, temp ); // last node first, for the sake of balance factor computation + treePath.add( 0, temp ); // last node first, for the sake of balance factor computation parent = temp; - + c = keyComparator.compare( key, temp.getKey() ); - - if( c == 0 ) + + if ( c == 0 ) { - if( allowDuplicates ) + if ( allowDuplicates ) { return insertDupKey( value, temp ); // key already exists add another value } @@ -136,8 +137,8 @@ public class AvlTreeMapImpl impleme return temp.value.setSingleton( value ); } } - - if( c < 0 ) + + if ( c < 0 ) { temp.isLeft = true; temp = temp.getLeft(); @@ -148,8 +149,8 @@ public class AvlTreeMapImpl impleme temp = temp.getRight(); } } - - if( ( c = keyComparator.compare( key, parent.getKey() ) ) < 0 ) + + if ( ( c = keyComparator.compare( key, parent.getKey() ) ) < 0 ) { parent.setLeft( node ); } @@ -157,22 +158,22 @@ public class AvlTreeMapImpl impleme { parent.setRight( node ); } - + insertInList( node, parent, c ); - + treePath.add( 0, node ); - balance(treePath); - + balance( treePath ); + size++; return null; } - - - private V insertDupKey( V value, LinkedAvlMapNode existingNode ) + + + private V insertDupKey( V value, LinkedAvlMapNode existingNode ) { AvlTree dupsTree = null; - - if( existingNode.value.isOrderedSet() ) + + if ( existingNode.value.isOrderedSet() ) { dupsTree = existingNode.value.getOrderedSet(); } @@ -183,71 +184,72 @@ public class AvlTreeMapImpl impleme dupsTree.insert( existingNode.value.getSingleton() ); existingNode.value.switchToOrderedSet( dupsTree ); } - + // check if value already exists - if( dupsTree.find( value ) != null ) + if ( dupsTree.find( value ) != null ) { - return value; + return value; } - + // insert value into duplicate key holder dupsTree.insert( value ); - + return null; } - - - private void removeFromList(LinkedAvlMapNode node) + + + private void removeFromList( LinkedAvlMapNode node ) { - if( node.next == null && node.previous == null ) // should happen in case of tree having single node + if ( node.next == null && node.previous == null ) // should happen in case of tree having single node { first = last = null; } - else if( node.next == null ) // last node + else if ( node.next == null ) // last node { node.previous.next = null; last = node.previous; } - else if( node.previous == null ) // first node + else if ( node.previous == null ) // first node { node.next.previous = null; first = node.next; } - else // somewhere in middle + else + // somewhere in middle { node.previous.next = node.next; node.next.previous = node.previous; } - + } - - - private void insertInList(LinkedAvlMapNode node, LinkedAvlMapNode parentNode, int pos) + + + private void insertInList( LinkedAvlMapNode node, LinkedAvlMapNode parentNode, int pos ) { - if( pos < 0 ) + if ( pos < 0 ) { - if( last == null ) + if ( last == null ) { - last = parentNode; + last = parentNode; } - - if( parentNode.previous == null ) + + if ( parentNode.previous == null ) { first = node; } else { - parentNode.previous.next = node ; + parentNode.previous.next = node; node.previous = parentNode.previous; } - + node.next = parentNode; parentNode.previous = node; } - else if( pos > 0 ) + else if ( pos > 0 ) { - if( parentNode.next == null ) + if ( parentNode.next == null ) { last = node; } @@ -258,35 +260,35 @@ public class AvlTreeMapImpl impleme } node.previous = parentNode; parentNode.next = node; - } - + } + } - - + + /** * {@inheritDoc} */ public SingletonOrOrderedSet remove( K key ) { - if( key == null ) + if ( key == null ) { throw new IllegalArgumentException( "key cannot be null" ); } - - LinkedAvlMapNode temp = null; - - List> treePath = new ArrayList>(); - - treePath = find( key, root, treePath); - - if( treePath == null ) + + LinkedAvlMapNode temp = null; + + List> treePath = new ArrayList>(); + + treePath = find( key, root, treePath ); + + if ( treePath == null ) { return null; } - + temp = treePath.remove( 0 ); - - if( temp.isLeaf() && ( temp == root ) ) + + if ( temp.isLeaf() && ( temp == root ) ) { root = null; } @@ -294,95 +296,96 @@ public class AvlTreeMapImpl impleme { balanceNodesAfterRemove( treePath, temp ); } - + size--; - return temp.value; + return temp.value; } - - + + /** * {@inheritDoc} */ public V remove( K key, V value ) { - if( key == null || value == null ) + if ( key == null || value == null ) { throw new IllegalArgumentException( "key or value cannot be null" ); } - - LinkedAvlMapNode temp = null; - - List> treePath = new ArrayList>(); - - treePath = find( key, root, treePath); - - if( treePath == null ) + + LinkedAvlMapNode temp = null; + + List> treePath = new ArrayList>(); + + treePath = find( key, root, treePath ); + + if ( treePath == null ) { return null; } - + temp = treePath.remove( 0 ); // check if the value matches - if( allowDuplicates ) + if ( allowDuplicates ) { - if( temp.value.isOrderedSet() ) + if ( temp.value.isOrderedSet() ) { AvlTree dupsTree = temp.value.getOrderedSet(); V removedVal = dupsTree.remove( value ); - + // if the removal is successful and the tree is not empty // we don't need to balance the tree, cause just one value // of the same key was removed // if the tree is empty because of the removal, the entire // node will be removed which might require balancing, so we continue // further down in this function - if( ( removedVal != null ) && ! dupsTree.isEmpty() ) + if ( ( removedVal != null ) && !dupsTree.isEmpty() ) { return removedVal;//no need to balance } - /* - * if the value is not found then we should return - */ - else if ( removedVal == null ) + /* + * if the value is not found then we should return + */ + else if ( removedVal == null ) { return removedVal;//no need to balance } } else { - if( valueComparator.compare( temp.value.getSingleton(), value ) != 0 ) + if ( valueComparator.compare( temp.value.getSingleton(), value ) != 0 ) { return null;// no need to balance } } } - if( temp.isLeaf() && ( temp == root ) ) + if ( temp.isLeaf() && ( temp == root ) ) { - if( allowDuplicates ) + if ( allowDuplicates ) { - if( temp.value.isSingleton() || temp.value.getOrderedSet().isEmpty() ) + if ( temp.value.isSingleton() || temp.value.getOrderedSet().isEmpty() ) { root = null; } } - else // if dups are not allowed set root to null + else + // if dups are not allowed set root to null { root = null; } - + size--; return value; } - balanceNodesAfterRemove( treePath, temp ); + balanceNodesAfterRemove( treePath, temp ); - size--; - return value; + size--; + return value; } - + /** * changes the order of nodes after a delete operation and then * balances the tree @@ -390,28 +393,28 @@ public class AvlTreeMapImpl impleme * @param treePath the path traversed to find the node temp * @param delNode the node to be deleted */ - private void balanceNodesAfterRemove( List> treePath, LinkedAvlMapNode delNode ) + private void balanceNodesAfterRemove( List> treePath, LinkedAvlMapNode delNode ) { - LinkedAvlMapNode y = null; - + LinkedAvlMapNode y = null; + // remove from the doubly linked - removeFromList( delNode ); + removeFromList( delNode ); - if( delNode.isLeaf() ) + if ( delNode.isLeaf() ) { - if( !treePath.isEmpty() ) + if ( !treePath.isEmpty() ) { detachNodes( delNode, treePath.get( 0 ) ); } } else { - if( delNode.left != null ) + if ( delNode.left != null ) { - List> leftTreePath = findMax( delNode.left ); + List> leftTreePath = findMax( delNode.left ); y = leftTreePath.remove( 0 ); - - if( leftTreePath.isEmpty() ) // y is the left child of root and y is a leaf + + if ( leftTreePath.isEmpty() ) // y is the left child of root and y is a leaf { detachNodes( y, delNode ); } @@ -419,13 +422,13 @@ public class AvlTreeMapImpl impleme { detachNodes( y, leftTreePath.remove( 0 ) ); } - + leftTreePath.addAll( treePath ); treePath = leftTreePath; - + y.right = delNode.right; // assign the right here left will be assigned in replaceNode() - if( delNode == root ) + if ( delNode == root ) { y.left = delNode.left; root = y; @@ -435,12 +438,12 @@ public class AvlTreeMapImpl impleme replaceNode( delNode, y, treePath.get( 0 ) ); } } - else if( delNode.right != null ) + else if ( delNode.right != null ) { - List> rightTreePath = findMin( delNode.right ); + List> rightTreePath = findMin( delNode.right ); y = rightTreePath.remove( 0 ); - - if( rightTreePath.isEmpty() ) + + if ( rightTreePath.isEmpty() ) { detachNodes( y, delNode ); // y is the right child of root and y is a leaf } @@ -448,13 +451,13 @@ public class AvlTreeMapImpl impleme { detachNodes( y, rightTreePath.remove( 0 ) ); } - + rightTreePath.addAll( treePath ); treePath = rightTreePath; - + y.right = delNode.right; // assign the right here left will be assigned in replaceNode() - - if( delNode == root ) + + if ( delNode == root ) { y.right = delNode.right; root = y; @@ -465,12 +468,12 @@ public class AvlTreeMapImpl impleme } } } - - treePath.add( 0, y ); // y can be null but getBalance returns 0 so np - balance( treePath ); + + treePath.add( 0, y ); // y can be null but getBalance returns 0 so np + balance( treePath ); } - - + + /** * Balances the tree by visiting the nodes present in the List of nodes present in the * treePath parameter.

@@ -482,41 +485,42 @@ public class AvlTreeMapImpl impleme * * @param treePath the traversed list of LinkedAvlMapNodes after performing an insert/delete operation. */ - private void balance( List> treePath ) + private void balance( List> treePath ) { - LinkedAvlMapNode parentNode = null; - + LinkedAvlMapNode parentNode = null; + int size = treePath.size(); - - for( LinkedAvlMapNode node: treePath ) + + for ( LinkedAvlMapNode node : treePath ) { int balFactor = getBalance( node ); - if( node != root && treePath.indexOf( node ) < ( size - 1 ) ) + if ( node != root && treePath.indexOf( node ) < ( size - 1 ) ) { parentNode = treePath.get( treePath.indexOf( node ) + 1 ); } - if( balFactor > 1 ) + if ( balFactor > 1 ) { - if( getBalance( node.right ) <= -1) + if ( getBalance( node.right ) <= -1 ) { //------rotate double-left-------- rotateSingleRight( node.right, node ); rotateSingleLeft( node, parentNode ); } - else // rotate single-left + else + // rotate single-left { - rotateSingleLeft( node, parentNode ); + rotateSingleLeft( node, parentNode ); } } - else if( balFactor < -1 ) + else if ( balFactor < -1 ) { - if( getBalance( node.left ) >= 1) + if ( getBalance( node.left ) >= 1 ) { - //------rotate double-right-------- - rotateSingleLeft( node.left, node ); - rotateSingleRight( node, parentNode ); + //------rotate double-right-------- + rotateSingleLeft( node.left, node ); + rotateSingleRight( node, parentNode ); } else { @@ -525,17 +529,17 @@ public class AvlTreeMapImpl impleme } } } - + /** * {@inheritDoc} */ public boolean isEmpty() { - return root == null; + return root == null; } - + /** * {@inheritDoc} */ @@ -544,8 +548,8 @@ public class AvlTreeMapImpl impleme { return size; } - - + + /** * Set the root of the tree. * @@ -553,12 +557,12 @@ public class AvlTreeMapImpl impleme * * @param root the root of the tree */ - /* no protection */ void setRoot( LinkedAvlMapNode root ) + /* no protection */void setRoot( LinkedAvlMapNode root ) { this.root = root; } - + /** * Set the first element of the tree * @@ -566,12 +570,12 @@ public class AvlTreeMapImpl impleme * * @param first the first element to be added */ - /* no protection */ void setFirst( LinkedAvlMapNode first ) + /* no protection */void setFirst( LinkedAvlMapNode first ) { this.first = first; } - + /** * Set the last element of the tree * @@ -579,7 +583,7 @@ public class AvlTreeMapImpl impleme * * @param last the last element to be added */ - /* no protection */ void setLast( LinkedAvlMapNode last ) + /* no protection */void setLast( LinkedAvlMapNode last ) { this.last = last; } @@ -588,127 +592,128 @@ public class AvlTreeMapImpl impleme /** * {@inheritDoc} */ - public LinkedAvlMapNode getRoot() + public LinkedAvlMapNode getRoot() { return root; } - - + + /** * {@inheritDoc} */ public List getKeys() { List keys = new ArrayList(); - LinkedAvlMapNode node = first; - - while( node != null ) + LinkedAvlMapNode node = first; + + while ( node != null ) { keys.add( node.key ); node = node.next; } - + return keys; } + /** * {@inheritDoc} */ - public void printTree() + public void printTree() { - if( isEmpty() ) + if ( isEmpty() ) { System.out.println( "Tree is empty" ); return; } - + getRoot().setDepth( 0 ); System.out.println( getRoot() ); - + visit( getRoot().getRight(), getRoot() ); - + visit( getRoot().getLeft(), getRoot() ); } - + /** * {@inheritDoc} */ - public LinkedAvlMapNode getFirst() + public LinkedAvlMapNode getFirst() { return first; } - + /** * {@inheritDoc} */ - public LinkedAvlMapNode getLast() + public LinkedAvlMapNode getLast() { return last; } - + /** * Rotate the node left side once. * * @param node the LinkedAvlMapNode to be rotated * @param parentNode parent LinkedAvlMapNode of node */ - private void rotateSingleLeft(LinkedAvlMapNode node, LinkedAvlMapNode parentNode) + private void rotateSingleLeft( LinkedAvlMapNode node, LinkedAvlMapNode parentNode ) { - LinkedAvlMapNode temp; + LinkedAvlMapNode temp; //------rotate single-left-------- - + temp = node.right; node.right = temp.left; temp.left = node; - - if( node == root ) + + if ( node == root ) { - root = temp; + root = temp; } - else if( parentNode != null ) + else if ( parentNode != null ) { - if( parentNode.left == node ) + if ( parentNode.left == node ) { parentNode.left = temp; } - else if( parentNode.right == node ) + else if ( parentNode.right == node ) { parentNode.right = temp; } } } - - + + /** * Rotate the node right side once. * * @param node the LinkedAvlMapNode to be rotated * @param parentNode parent LinkedAvlMapNode of node */ - private void rotateSingleRight(LinkedAvlMapNode node, LinkedAvlMapNode parentNode) + private void rotateSingleRight( LinkedAvlMapNode node, LinkedAvlMapNode parentNode ) { - LinkedAvlMapNode temp; + LinkedAvlMapNode temp; //------rotate single-right-------- - + temp = node.left; node.left = temp.right; temp.right = node; - - if( node == root ) + + if ( node == root ) { - root = temp; + root = temp; } - else if( parentNode != null ) + else if ( parentNode != null ) { - if( parentNode.left == node ) + if ( parentNode.left == node ) { parentNode.left = temp; } - else if( parentNode.right == node ) + else if ( parentNode.right == node ) { parentNode.right = temp; } @@ -717,13 +722,13 @@ public class AvlTreeMapImpl impleme when the 'parentNode' param is null then the node under rotation is a child of ROOT. Most likely this condition executes when the root node is deleted and balancing is required. */ - else if( root != null && root.left == node ) + else if ( root != null && root.left == node ) { root.left = temp; // no need to check for right node } } - + /** * Detach a LinkedAvlMapNode from its parent @@ -731,15 +736,15 @@ public class AvlTreeMapImpl impleme * @param node the LinkedAvlMapNode to be detached * @param parentNode the parent LinkedAvlMapNode of the node */ - private void detachNodes(LinkedAvlMapNode node, LinkedAvlMapNode parentNode) + private void detachNodes( LinkedAvlMapNode node, LinkedAvlMapNode parentNode ) { - if( parentNode != null ) + if ( parentNode != null ) { - if( node == parentNode.left ) + if ( node == parentNode.left ) { parentNode.left = node.left; } - else if( node == parentNode.right ) + else if ( node == parentNode.right ) { parentNode.right = node.left; } @@ -755,24 +760,25 @@ public class AvlTreeMapImpl impleme * @param replaceNode the LinkedAvlMapNode to replace the deleteNode * @param parentNode the parent LinkedAvlMapNode of deleteNode */ - private void replaceNode(LinkedAvlMapNode deleteNode, LinkedAvlMapNode replaceNode, LinkedAvlMapNode parentNode) + private void replaceNode( LinkedAvlMapNode deleteNode, LinkedAvlMapNode replaceNode, + LinkedAvlMapNode parentNode ) { - if( parentNode != null ) + if ( parentNode != null ) { replaceNode.left = deleteNode.left; - - if( deleteNode == parentNode.left ) + + if ( deleteNode == parentNode.left ) { parentNode.left = replaceNode; } - else if( deleteNode == parentNode.right ) + else if ( deleteNode == parentNode.right ) { parentNode.right = replaceNode; } } } - - + + /** * * Find a LinkedAvlMapNode with the given key value in the tree starting from the startNode. @@ -782,31 +788,32 @@ public class AvlTreeMapImpl impleme * @param path the list to be filled with traversed nodes * @return the list of traversed LinkedAvlMapNodes. */ - private List> find( K key, LinkedAvlMapNode startNode, List> path ) + private List> find( K key, LinkedAvlMapNode startNode, + List> path ) { int c; - - if( startNode == null ) + + if ( startNode == null ) { return null; } - + path.add( 0, startNode ); c = keyComparator.compare( key, startNode.key ); - - if( c == 0 ) + + if ( c == 0 ) { return path; } - else if( c > 0 ) + else if ( c > 0 ) { return find( key, startNode.right, path ); } - else if( c < 0 ) + else if ( c < 0 ) { return find( key, startNode.left, path ); } - + return null; } @@ -814,15 +821,15 @@ public class AvlTreeMapImpl impleme /** * {@inheritDoc} */ - public LinkedAvlMapNode findGreater( K key ) + public LinkedAvlMapNode findGreater( K key ) { - LinkedAvlMapNode result = fetchNonNullNode( key, root, root); + LinkedAvlMapNode result = fetchNonNullNode( key, root, root ); - if( result == null ) + if ( result == null ) { return null; } - else if( keyComparator.compare( key, result.key ) < 0 ) + else if ( keyComparator.compare( key, result.key ) < 0 ) { return result; } @@ -834,15 +841,15 @@ public class AvlTreeMapImpl impleme /** * {@inheritDoc} */ - public LinkedAvlMapNode findGreaterOrEqual( K key ) + public LinkedAvlMapNode findGreaterOrEqual( K key ) { - LinkedAvlMapNode result = fetchNonNullNode( key, root, root); + LinkedAvlMapNode result = fetchNonNullNode( key, root, root ); - if( result == null ) + if ( result == null ) { return null; } - else if( keyComparator.compare( key, result.key ) <= 0 ) + else if ( keyComparator.compare( key, result.key ) <= 0 ) { return result; } @@ -854,15 +861,15 @@ public class AvlTreeMapImpl impleme /** * {@inheritDoc} */ - public LinkedAvlMapNode findLess( K key ) + public LinkedAvlMapNode findLess( K key ) { - LinkedAvlMapNode result = fetchNonNullNode( key, root, root); + LinkedAvlMapNode result = fetchNonNullNode( key, root, root ); - if( result == null ) + if ( result == null ) { return null; } - else if( keyComparator.compare( key, result.key ) > 0 ) + else if ( keyComparator.compare( key, result.key ) > 0 ) { return result; } @@ -874,15 +881,15 @@ public class AvlTreeMapImpl impleme /** * {@inheritDoc} */ - public LinkedAvlMapNode findLessOrEqual( K key ) + public LinkedAvlMapNode findLessOrEqual( K key ) { - LinkedAvlMapNode result = fetchNonNullNode( key, root, root); + LinkedAvlMapNode result = fetchNonNullNode( key, root, root ); - if( result == null ) + if ( result == null ) { return null; } - else if( keyComparator.compare( key, result.key ) >= 0 ) + else if ( keyComparator.compare( key, result.key ) >= 0 ) { return result; } @@ -896,68 +903,70 @@ public class AvlTreeMapImpl impleme * is not present. This method should not be used as general purpose lookup method. * This is written to assist the findGreater, findLess methods. */ - private LinkedAvlMapNode fetchNonNullNode( K key, LinkedAvlMapNode startNode, LinkedAvlMapNode parent ) + private LinkedAvlMapNode fetchNonNullNode( K key, LinkedAvlMapNode startNode, + LinkedAvlMapNode parent ) { - - if( startNode == null ) + + if ( startNode == null ) { return parent; } - + int c = keyComparator.compare( key, startNode.key ); - + parent = startNode; - if( c > 0 ) + if ( c > 0 ) { return fetchNonNullNode( key, startNode.right, parent ); } - else if( c < 0 ) + else if ( c < 0 ) { return fetchNonNullNode( key, startNode.left, parent ); } - + return startNode; } - + + /** * {@inheritDoc} */ - public LinkedAvlMapNode find( K key ) + public LinkedAvlMapNode find( K key ) { - return find( key, root); + return find( key, root ); } - + /** * {@inheritDoc} */ - public LinkedAvlMapNode find( K key, V value ) + public LinkedAvlMapNode find( K key, V value ) { - if( key == null || value == null ) + if ( key == null || value == null ) { return null; } - - LinkedAvlMapNode node = find( key, root ); - - if( node == null ) + + LinkedAvlMapNode node = find( key, root ); + + if ( node == null ) { return null; } - - if( node.value.isOrderedSet() ) + + if ( node.value.isOrderedSet() ) { AvlTree dupsTree = node.value.getOrderedSet(); - - if( dupsTree.find( value ) == null ) + + if ( dupsTree.find( value ) == null ) { return null; } } else { - if( valueComparator.compare( node.value.getSingleton(), value ) != 0 ) + if ( valueComparator.compare( node.value.getSingleton(), value ) != 0 ) { return null; } @@ -966,157 +975,157 @@ public class AvlTreeMapImpl impleme return node; } - - private LinkedAvlMapNode find( K key, LinkedAvlMapNode startNode) + + private LinkedAvlMapNode find( K key, LinkedAvlMapNode startNode ) { int c; - - if( startNode == null ) + + if ( startNode == null ) { return null; } - + c = keyComparator.compare( key, startNode.key ); - - if( c > 0 ) + + if ( c > 0 ) { startNode.isLeft = false; return find( key, startNode.right ); } - else if( c < 0 ) + else if ( c < 0 ) { startNode.isLeft = true; return find( key, startNode.left ); } - + return startNode; } - - + + /** * Find the LinkedAvlMapNode having the max key value in the tree starting from the startNode. * * @param startNode starting node of a subtree/tree * @return the list of traversed LinkedAvlMapNodes. */ - private List> findMax( LinkedAvlMapNode startNode ) + private List> findMax( LinkedAvlMapNode startNode ) { - LinkedAvlMapNode x = startNode; - LinkedAvlMapNode y = null; - List> path; - - if( x == null ) + LinkedAvlMapNode x = startNode; + LinkedAvlMapNode y = null; + List> path; + + if ( x == null ) { return null; } - - while( x.right != null ) + + while ( x.right != null ) { x.isLeft = false; y = x; x = x.right; } - - path = new ArrayList>(2); + + path = new ArrayList>( 2 ); path.add( x ); - + if ( y != null ) { - path.add( y ); + path.add( y ); } - + return path; } - + /** * Find the LinkedAvlMapNode having the min key value in the tree starting from the startNode. * * @param startNode starting node of a subtree/tree * @return the list of traversed LinkedAvlMapNodes. */ - private List> findMin( LinkedAvlMapNode startNode ) + private List> findMin( LinkedAvlMapNode startNode ) { - LinkedAvlMapNode x = startNode; - LinkedAvlMapNode y = null; - List> path; - - if( x == null ) + LinkedAvlMapNode x = startNode; + LinkedAvlMapNode y = null; + List> path; + + if ( x == null ) { return null; } - - while( x.left != null ) + + while ( x.left != null ) { x.isLeft = true; y = x; x = x.left; } - - path = new ArrayList>(2); + + path = new ArrayList>( 2 ); path.add( x ); - + if ( y != null ) { - path.add( y ); + path.add( y ); } - + return path; } - - + + /** * Get balance-factor of the given LinkedAvlMapNode. * * @param node a LinkedAvlMapNode * @return balance-factor of the node */ - private int getBalance( LinkedAvlMapNode node ) + private int getBalance( LinkedAvlMapNode node ) { - if( node == null) + if ( node == null ) { return 0; } - + return node.getBalance(); } - - - private void visit( LinkedAvlMapNode node, LinkedAvlMapNode parentNode ) + + + private void visit( LinkedAvlMapNode node, LinkedAvlMapNode parentNode ) { - if( node == null ) + if ( node == null ) { return; } - - if( !node.isLeaf() ) + + if ( !node.isLeaf() ) { node.setDepth( parentNode.getDepth() + 1 ); } - - for( int i=0; i < parentNode.getDepth(); i++ ) + + for ( int i = 0; i < parentNode.getDepth(); i++ ) { System.out.print( "| " ); } String type = ""; - if( node == parentNode.left ) + if ( node == parentNode.left ) { type = "L"; } - else if( node == parentNode.right ) + else if ( node == parentNode.right ) { type = "R"; } - + System.out.println( "|--" + node + type ); - + if ( node.getRight() != null ) { visit( node.getRight(), node ); } - - if( node.getLeft() != null ) + + if ( node.getLeft() != null ) { visit( node.getLeft(), node ); } Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java?rev=948711&r1=948710&r2=948711&view=diff ============================================================================== --- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java (original) +++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java Thu May 27 08:08:44 2010 @@ -82,59 +82,47 @@ public class MetaSyntaxCheckerHandlerIT @Test public void testAddSyntaxCheckerToEnabledSchema() throws Exception { - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntaxChecker", - "m-fqcn", OctetStringSyntaxChecker.class.getName(), - "m-oid", OID, + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID, "m-description: A test syntaxChecker" ); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); getSchemaContext( service ).createSubcontext( DN.toName( dn ), attrs ); - + assertTrue( schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); assertEquals( schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( OID ).getClass(); assertEquals( clazz, OctetStringSyntaxChecker.class ); assertTrue( isOnDisk( dn ) ); } - - + + @Test public void testAddSyntaxCheckerToDisabledSchema() throws Exception { - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntaxChecker", - "m-fqcn", OctetStringSyntaxChecker.class.getName(), - "m-oid", OID, + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID, "m-description: A test syntaxChecker" ); - + // nis is by default inactive DN dn = getSyntaxCheckerContainer( "nis" ); dn.add( "m-oid" + "=" + OID ); getSchemaContext( service ).createSubcontext( DN.toName( dn ), attrs ); - - assertFalse( "adding new syntaxChecker to disabled schema should not register it into the registries", + + assertFalse( "adding new syntaxChecker to disabled schema should not register it into the registries", schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); assertTrue( isOnDisk( dn ) ); } - - + + @Test public void testAddSyntaxCheckerToUnloadedSchema() throws Exception { - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntaxChecker", - "m-fqcn", OctetStringSyntaxChecker.class.getName(), - "m-oid", OID, + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID, "m-description: A test syntaxChecker" ); - + // nis is by default inactive DN dn = getSyntaxCheckerContainer( "notloaded" ); dn.add( "m-oid" + "=" + OID ); @@ -144,12 +132,12 @@ public class MetaSyntaxCheckerHandlerIT getSchemaContext( service ).createSubcontext( DN.toName( dn ), attrs ); fail( "Should not be there" ); } - catch( NameNotFoundException nnfe ) + catch ( NameNotFoundException nnfe ) { // Expected result. } - - assertFalse( "adding new syntaxChecker to disabled schema should not register it into the registries", + + assertFalse( "adding new syntaxChecker to disabled schema should not register it into the registries", schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); assertFalse( isOnDisk( dn ) ); } @@ -160,25 +148,21 @@ public class MetaSyntaxCheckerHandlerIT { InputStream in = getClass().getResourceAsStream( "DummySyntaxChecker.bytecode" ); ByteArrayOutputStream out = new ByteArrayOutputStream(); - + while ( in.available() > 0 ) { out.write( in.read() ); } - - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntaxChecker", - "m-fqcn", "org.apache.directory.shared.ldap.schema.syntaxCheckers.DummySyntaxChecker", - "m-bytecode", out.toByteArray(), - "m-oid", OID, - "m-description: A test syntaxChecker" ); - + + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntaxChecker", "m-fqcn", + "org.apache.directory.shared.ldap.schema.syntaxCheckers.DummySyntaxChecker", "m-bytecode", out + .toByteArray(), "m-oid", OID, "m-description: A test syntaxChecker" ); + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); getSchemaContext( service ).createSubcontext( DN.toName( dn ), attrs ); - + assertTrue( schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); assertEquals( schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( OID ).getClass(); @@ -192,84 +176,80 @@ public class MetaSyntaxCheckerHandlerIT { InputStream in = getClass().getResourceAsStream( "DummySyntaxChecker.bytecode" ); ByteArrayOutputStream out = new ByteArrayOutputStream(); - + while ( in.available() > 0 ) { out.write( in.read() ); } - - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntaxChecker", - "m-fqcn", "org.apache.directory.shared.ldap.schema.syntaxCheckers.DummySyntaxChecker", - "m-bytecode", out.toByteArray(), - "m-oid", OID, - "m-description: A test syntaxChecker" ); - + + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntaxChecker", "m-fqcn", + "org.apache.directory.shared.ldap.schema.syntaxCheckers.DummySyntaxChecker", "m-bytecode", out + .toByteArray(), "m-oid", OID, "m-description: A test syntaxChecker" ); + DN dn = getSyntaxCheckerContainer( "nis" ); dn.add( "m-oid" + "=" + OID ); getSchemaContext( service ).createSubcontext( DN.toName( dn ), attrs ); - + assertFalse( schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); assertTrue( isOnDisk( dn ) ); } - - + + @Test public void testDeleteSyntaxCheckerFromEnabledSchema() throws Exception { DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); testAddSyntaxCheckerToEnabledSchema(); - - assertTrue( "syntaxChecker should be removed from the registry after being deleted", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + + assertTrue( "syntaxChecker should be removed from the registry after being deleted", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); assertTrue( isOnDisk( dn ) ); - + getSchemaContext( service ).destroySubcontext( DN.toName( dn ) ); - assertFalse( "syntaxChecker should be removed from the registry after being deleted", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertFalse( "syntaxChecker should be removed from the registry after being deleted", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); try { schemaManager.getSyntaxCheckerRegistry().lookup( OID ); fail( "syntaxChecker lookup should fail after deleting the syntaxChecker" ); } - catch( LdapException e ) + catch ( LdapException e ) { } - + assertFalse( isOnDisk( dn ) ); } - - + + @Test public void testDeleteSyntaxCheckerFromDisabledSchema() throws Exception { DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); testAddSyntaxCheckerToEnabledSchema(); - - assertTrue( "syntaxChecker should be removed from the registry after being deleted", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + + assertTrue( "syntaxChecker should be removed from the registry after being deleted", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); assertTrue( isOnDisk( dn ) ); getSchemaContext( service ).destroySubcontext( DN.toName( dn ) ); - assertFalse( "syntaxChecker should be removed from the registry after being deleted", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertFalse( "syntaxChecker should be removed from the registry after being deleted", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); try { schemaManager.getSyntaxCheckerRegistry().lookup( OID ); fail( "syntaxChecker lookup should fail after deleting the syntaxChecker" ); } - catch( LdapException e ) + catch ( LdapException e ) { } - + assertFalse( isOnDisk( dn ) ); } @@ -281,13 +261,13 @@ public class MetaSyntaxCheckerHandlerIT DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); testAddSyntaxCheckerToEnabledSchema(); - + DN newdn = getSyntaxCheckerContainer( "apachemeta" ); newdn.add( "m-oid" + "=" + NEW_OID ); getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); - assertFalse( "old syntaxChecker OID should be removed from the registry after being renamed", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertFalse( "old syntaxChecker OID should be removed from the registry after being renamed", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); //noinspection EmptyCatchBlock try @@ -295,7 +275,7 @@ public class MetaSyntaxCheckerHandlerIT schemaManager.getSyntaxCheckerRegistry().lookup( OID ); fail( "syntaxChecker lookup should fail after deleting the syntaxChecker" ); } - catch( LdapException e ) + catch ( LdapException e ) { } @@ -310,20 +290,20 @@ public class MetaSyntaxCheckerHandlerIT public void testMoveSyntaxChecker() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN newdn = getSyntaxCheckerContainer( "apache" ); newdn.add( "m-oid" + "=" + OID ); - + getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); - assertTrue( "syntaxChecker OID should still be present", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); - - assertEquals( "syntaxChecker schema should be set to apache not apachemeta", - schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apache" ); + assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry() + .contains( OID ) ); + + assertEquals( "syntaxChecker schema should be set to apache not apachemeta", schemaManager + .getSyntaxCheckerRegistry().getSchemaName( OID ), "apache" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( OID ).getClass(); assertEquals( clazz, OctetStringSyntaxChecker.class ); @@ -335,77 +315,77 @@ public class MetaSyntaxCheckerHandlerIT public void testMoveSyntaxCheckerAndChangeRdn() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN newdn = getSyntaxCheckerContainer( "apache" ); newdn.add( "m-oid" + "=" + NEW_OID ); - + getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); - assertFalse( "old syntaxChecker OID should NOT be present", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); - - assertTrue( "new syntaxChecker OID should be present", - schemaManager.getSyntaxCheckerRegistry().contains( NEW_OID ) ); - - assertEquals( "syntaxChecker with new oid should have schema set to apache NOT apachemeta", - schemaManager.getSyntaxCheckerRegistry().getSchemaName( NEW_OID ), "apache" ); + assertFalse( "old syntaxChecker OID should NOT be present", schemaManager.getSyntaxCheckerRegistry().contains( + OID ) ); + + assertTrue( "new syntaxChecker OID should be present", schemaManager.getSyntaxCheckerRegistry().contains( + NEW_OID ) ); + + assertEquals( "syntaxChecker with new oid should have schema set to apache NOT apachemeta", schemaManager + .getSyntaxCheckerRegistry().getSchemaName( NEW_OID ), "apache" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( NEW_OID ).getClass(); assertEquals( clazz, OctetStringSyntaxChecker.class ); } - + @Test @Ignore public void testModifySyntaxCheckerWithModificationItems() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); - + ModificationItem[] mods = new ModificationItem[1]; Attribute attr = new BasicAttribute( "m-fqcn", BogusSyntaxChecker.class.getName() ); mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr ); getSchemaContext( service ).modifyAttributes( DN.toName( dn ), mods ); - assertTrue( "syntaxChecker OID should still be present", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); - - assertEquals( "syntaxChecker schema should be set to apachemeta", - schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); + assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry() + .contains( OID ) ); + + assertEquals( "syntaxChecker schema should be set to apachemeta", schemaManager.getSyntaxCheckerRegistry() + .getSchemaName( OID ), "apachemeta" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( OID ).getClass(); assertEquals( clazz, BogusSyntaxChecker.class ); } - + @Test @Ignore public void testModifySyntaxCheckerWithAttributes() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); - + Attributes mods = new BasicAttributes( true ); mods.put( "m-fqcn", BogusSyntaxChecker.class.getName() ); getSchemaContext( service ).modifyAttributes( DN.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods ); - assertTrue( "syntaxChecker OID should still be present", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); - - assertEquals( "syntaxChecker schema should be set to apachemeta", - schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); + assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry() + .contains( OID ) ); + + assertEquals( "syntaxChecker schema should be set to apachemeta", schemaManager.getSyntaxCheckerRegistry() + .getSchemaName( OID ), "apachemeta" ); Class clazz = schemaManager.getSyntaxCheckerRegistry().lookup( OID ).getClass(); assertEquals( clazz, BogusSyntaxChecker.class ); } - + // ---------------------------------------------------------------------- // Test move, rename, and delete when a MR exists and uses the Normalizer @@ -415,19 +395,15 @@ public class MetaSyntaxCheckerHandlerIT { DN scDn = getSyntaxCheckerContainer( "apachemeta" ); scDn.add( "m-oid" + "=" + OID ); - + // Create a new SyntaxChecker testAddSyntaxCheckerToEnabledSchema(); assertTrue( isOnDisk( scDn ) ); assertTrue( service.getSchemaManager().getSyntaxCheckerRegistry().contains( OID ) ); - + // Create a Syntax using this comparator - Attributes attrs = LdifUtils.createAttributes( - "objectClass: top", - "objectClass: metaTop", - "objectClass: metaSyntax", - "m-oid", OID, - "m-description: test" ); + Attributes attrs = LdifUtils.createAttributes( "objectClass: top", "objectClass: metaTop", + "objectClass: metaSyntax", "m-oid", OID, "m-description: test" ); DN sDn = getSyntaxContainer( "apachemeta" ); sDn.add( "m-oid" + "=" + OID ); @@ -442,45 +418,45 @@ public class MetaSyntaxCheckerHandlerIT // Post-checks assertTrue( isOnDisk( sDn ) ); assertTrue( service.getSchemaManager().getLdapSyntaxRegistry().contains( OID ) ); - + try { getSchemaContext( service ).destroySubcontext( DN.toName( scDn ) ); fail( "should not be able to delete a syntaxChecker in use" ); } - catch( OperationNotSupportedException e ) + catch ( OperationNotSupportedException e ) { } - assertTrue( "syntaxChecker should still be in the registry after delete failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after delete failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); } - - + + @Test @Ignore public void testMoveSyntaxCheckerWhenInUse() throws Exception { testAddSyntaxCheckerToEnabledSchema(); schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() ); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN newdn = getSyntaxCheckerContainer( "apache" ); newdn.add( "m-oid" + "=" + OID ); - + try { getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); fail( "should not be able to move a syntaxChecker in use" ); } - catch( OperationNotSupportedException e ) + catch ( OperationNotSupportedException e ) { } - assertTrue( "syntaxChecker should still be in the registry after move failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after move failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); schemaManager.getLdapSyntaxRegistry().unregister( OID ); schemaManager.getGlobalOidRegistry().unregister( OID ); } @@ -492,29 +468,29 @@ public class MetaSyntaxCheckerHandlerIT { testAddSyntaxCheckerToEnabledSchema(); schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() ); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN newdn = getSyntaxCheckerContainer( "apache" ); newdn.add( "m-oid" + "=" + NEW_OID ); - + try { getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); fail( "should not be able to move a syntaxChecker in use" ); } - catch( OperationNotSupportedException e ) + catch ( OperationNotSupportedException e ) { } - assertTrue( "syntaxChecker should still be in the registry after move failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after move failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); schemaManager.getLdapSyntaxRegistry().unregister( OID ); schemaManager.getGlobalOidRegistry().unregister( OID ); } - + @Test @Ignore public void testRenameSyntaxCheckerWhenInUse() throws Exception @@ -523,21 +499,21 @@ public class MetaSyntaxCheckerHandlerIT dn.add( "m-oid" + "=" + OID ); testAddSyntaxCheckerToEnabledSchema(); schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() ); - + DN newdn = getSyntaxCheckerContainer( "apachemeta" ); newdn.add( "m-oid" + "=" + NEW_OID ); - + try { getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); fail( "should not be able to rename a syntaxChecker in use" ); } - catch( OperationNotSupportedException e ) + catch ( OperationNotSupportedException e ) { } - assertTrue( "syntaxChecker should still be in the registry after rename failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after rename failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); schemaManager.getLdapSyntaxRegistry().unregister( OID ); schemaManager.getGlobalOidRegistry().unregister( OID ); } @@ -547,30 +523,29 @@ public class MetaSyntaxCheckerHandlerIT // Let's try some freaky stuff // ---------------------------------------------------------------------- - @Test @Ignore public void testMoveSyntaxCheckerToTop() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN top = new DN(); top.add( "m-oid" + "=" + OID ); - + try { getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( top ) ); fail( "should not be able to move a syntaxChecker up to ou=schema" ); } - catch( InvalidNameException e ) + catch ( InvalidNameException e ) { } - assertTrue( "syntaxChecker should still be in the registry after move failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after move failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); } @@ -579,44 +554,44 @@ public class MetaSyntaxCheckerHandlerIT public void testMoveSyntaxCheckerToComparatorContainer() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); DN newdn = new DN( "ou=comparators,cn=apachemeta" ); newdn.add( "m-oid" + "=" + OID ); - + try { getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); fail( "should not be able to move a syntaxChecker into comparators container" ); } - catch( InvalidNameException e ) + catch ( InvalidNameException e ) { } - assertTrue( "syntaxChecker should still be in the registry after move failure", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertTrue( "syntaxChecker should still be in the registry after move failure", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); } - - + + @Test @Ignore public void testMoveSyntaxCheckerToDisabledSchema() throws Exception { testAddSyntaxCheckerToEnabledSchema(); - + DN dn = getSyntaxCheckerContainer( "apachemeta" ); dn.add( "m-oid" + "=" + OID ); // nis is inactive by default DN newdn = getSyntaxCheckerContainer( "nis" ); newdn.add( "m-oid" + "=" + OID ); - + getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); - assertFalse( "syntaxChecker OID should no longer be present", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertFalse( "syntaxChecker OID should no longer be present", schemaManager.getSyntaxCheckerRegistry() + .contains( OID ) ); } @@ -625,52 +600,53 @@ public class MetaSyntaxCheckerHandlerIT public void testMoveSyntaxCheckerToEnabledSchema() throws Exception { testAddSyntaxCheckerToDisabledSchema(); - + // nis is inactive by default DN dn = getSyntaxCheckerContainer( "nis" ); dn.add( "m-oid" + "=" + OID ); - assertFalse( "syntaxChecker OID should NOT be present when added to disabled nis schema", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); + assertFalse( "syntaxChecker OID should NOT be present when added to disabled nis schema", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); DN newdn = getSyntaxCheckerContainer( "apachemeta" ); newdn.add( "m-oid" + "=" + OID ); - + getSchemaContext( service ).rename( DN.toName( dn ), DN.toName( newdn ) ); - assertTrue( "syntaxChecker OID should be present when moved to enabled schema", - schemaManager.getSyntaxCheckerRegistry().contains( OID ) ); - - assertEquals( "syntaxChecker should be in apachemeta schema after move", - schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); + assertTrue( "syntaxChecker OID should be present when moved to enabled schema", schemaManager + .getSyntaxCheckerRegistry().contains( OID ) ); + + assertEquals( "syntaxChecker should be in apachemeta schema after move", schemaManager + .getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" ); } - public static class BogusSyntaxChecker extends SyntaxChecker { private static final long serialVersionUID = 1L; + public BogusSyntaxChecker() { - super(OID); + super( OID ); } - + + public boolean isValidSyntax( Object value ) { return false; } } - class DummySyntax extends LdapSyntax { private static final long serialVersionUID = 1L; + public DummySyntax() { super( OID ); addName( "dummy" ); - isObsolete = false; + isObsolete = false; isHumanReadable = false; syntaxChecker = null; } Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/FilterNormalizingVisitor.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/FilterNormalizingVisitor.java?rev=948711&r1=948710&r2=948711&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/FilterNormalizingVisitor.java (original) +++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/normalization/FilterNormalizingVisitor.java Thu May 27 08:08:44 2010 @@ -70,32 +70,31 @@ public class FilterNormalizingVisitor im /** the global registries used to resolve OIDs for attributeType ids */ private final SchemaManager schemaManager; - /** * Chars which need to be escaped in a filter * '\0' | '(' | ')' | '*' | '\' */ private static final boolean[] FILTER_CHAR = - { - true, false, false, false, false, false, false, false, // 00 -> 07 NULL + { true, false, false, false, false, false, false, false, // 00 -> 07 NULL false, false, false, false, false, false, false, false, // 08 -> 0F false, false, false, false, false, false, false, false, // 10 -> 17 false, false, false, false, false, false, false, false, // 18 -> 1F false, false, false, false, false, false, false, false, // 20 -> 27 - true, true, true, false, false, false, false, false, // 28 -> 2F '(', ')', '*' + true, true, true, false, false, false, false, false, // 28 -> 2F '(', ')', '*' false, false, false, false, false, false, false, false, // 30 -> 37 false, false, false, false, false, false, false, false, // 38 -> 3F false, false, false, false, false, false, false, false, // 40 -> 47 false, false, false, false, false, false, false, false, // 48 -> 4F false, false, false, false, false, false, false, false, // 50 -> 57 - false, false, false, false, true, false, false, false, // 58 -> 5F '\' + false, false, false, false, true, false, false, false, // 58 -> 5F '\' false, false, false, false, false, false, false, false, // 60 -> 67 false, false, false, false, false, false, false, false, // 68 -> 6F false, false, false, false, false, false, false, false, // 70 -> 77 - false, false, false, false, false, false, false, false // 78 -> 7F + false, false, false, false, false, false, false, false // 78 -> 7F }; - + + /** * Check if the given char is a filter escaped char * <filterEscapedChars> ::= '\0' | '(' | ')' | '*' | '\' @@ -143,12 +142,11 @@ public class FilterNormalizingVisitor im if ( attributeType.getSyntax().isHumanReadable() ) { - normalized = new StringValue( - (String) ncn.normalizeByName( attribute, value.getString() ) ); + normalized = new StringValue( ( String ) ncn.normalizeByName( attribute, value.getString() ) ); } else { - normalized = (Value)ncn.normalizeByName( attribute, value.getBytes() ); + normalized = ( Value ) ncn.normalizeByName( attribute, value.getBytes() ); } return normalized; @@ -204,7 +202,7 @@ public class FilterNormalizingVisitor im node.setAttribute( schemaManager.getAttributeTypeRegistry().getOidByName( node.getAttribute() ) ); node.setValue( normalized ); - + return node; } @@ -427,54 +425,54 @@ public class FilterNormalizingVisitor im * @param node the node to visit * @return the visited node */ - public Object visit( ExprNode node ) + public Object visit( ExprNode node ) { - try - { - // ------------------------------------------------------------------- - // Handle PresenceNodes - // ------------------------------------------------------------------- - - if ( node instanceof PresenceNode ) - { - return visitPresenceNode( ( PresenceNode ) node ); - } - - // ------------------------------------------------------------------- - // Handle BranchNodes (AndNode, NotNode and OrNode) - // ------------------------------------------------------------------- - - else if ( node instanceof BranchNode ) - { - return visitBranchNode( ( BranchNode ) node ); - } - - // ------------------------------------------------------------------- - // Handle SimpleNodes (ApproximateNode, EqualityNode, GreaterEqNode, - // and LesserEqNode) - // ------------------------------------------------------------------- - - else if ( node instanceof SimpleNode ) - { - return visitSimpleNode( ( SimpleNode ) node ); - } - else if ( node instanceof ExtensibleNode ) - { - return visitExtensibleNode( ( ExtensibleNode ) node ); - } - else if ( node instanceof SubstringNode ) - { - return visitSubstringNode( ( SubstringNode ) node ); - } - else - { - return null; - } - } - catch( LdapException e ) - { - throw new RuntimeException( e ); - } + try + { + // ------------------------------------------------------------------- + // Handle PresenceNodes + // ------------------------------------------------------------------- + + if ( node instanceof PresenceNode ) + { + return visitPresenceNode( ( PresenceNode ) node ); + } + + // ------------------------------------------------------------------- + // Handle BranchNodes (AndNode, NotNode and OrNode) + // ------------------------------------------------------------------- + + else if ( node instanceof BranchNode ) + { + return visitBranchNode( ( BranchNode ) node ); + } + + // ------------------------------------------------------------------- + // Handle SimpleNodes (ApproximateNode, EqualityNode, GreaterEqNode, + // and LesserEqNode) + // ------------------------------------------------------------------- + + else if ( node instanceof SimpleNode ) + { + return visitSimpleNode( ( SimpleNode ) node ); + } + else if ( node instanceof ExtensibleNode ) + { + return visitExtensibleNode( ( ExtensibleNode ) node ); + } + else if ( node instanceof SubstringNode ) + { + return visitSubstringNode( ( SubstringNode ) node ); + } + else + { + return null; + } + } + catch ( LdapException e ) + { + throw new RuntimeException( e ); + } } Modified: directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java?rev=948711&r1=948710&r2=948711&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java (original) +++ directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/DummyAttributeTypeRegistry.java Thu May 27 08:08:44 2010 @@ -46,12 +46,12 @@ import org.apache.directory.shared.ldap. * @version $Rev$, $Date$ * */ -public class DummyAttributeTypeRegistry extends DefaultSchemaObjectRegistry +public class DummyAttributeTypeRegistry extends DefaultSchemaObjectRegistry { private final boolean returnOperational; - public DummyAttributeTypeRegistry(boolean returnOperational) + public DummyAttributeTypeRegistry( boolean returnOperational ) { super( SchemaObjectType.ATTRIBUTE_TYPE, new OidRegistry() ); this.returnOperational = returnOperational; @@ -64,7 +64,7 @@ public class DummyAttributeTypeRegistry MatchingRule equality = new MatchingRule( "1.1.1" ); equality.setNormalizer( normalizer ); - + AttributeType attributeType = new AttributeType( id ); attributeType.setEquality( equality ); attributeType.setSingleValued( false ); @@ -83,7 +83,7 @@ public class DummyAttributeTypeRegistry attributeType.setSyntax( syntax ); attributeType.setUserModifiable( true ); } - + return attributeType; } @@ -106,7 +106,7 @@ public class DummyAttributeTypeRegistry } - public Map getNormalizerMapping() + public Map getNormalizerMapping() { return null; } @@ -132,7 +132,7 @@ public class DummyAttributeTypeRegistry public AttributeType unregister( String numericOid ) throws LdapException { - return null; + return null; } @@ -146,19 +146,17 @@ public class DummyAttributeTypeRegistry return null; } - - public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) - throws LdapException + + public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException { } - - public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) - throws LdapException + + public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException { } - - + + public void addMappingFor( AttributeType attributeType ) throws LdapException { }