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 2007/09/19 18:51:42 UTC

svn commit: r577362 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci: ACIItem.java ItemFirstACIItem.java ProtectedItem.java UserFirstACIItem.java UserPermission.java

Author: elecharny
Date: Wed Sep 19 09:51:41 2007
New Revision: 577362

URL: http://svn.apache.org/viewvc?rev=577362&view=rev
Log:
 o Removed the printToBuffer() method and replaced it by toString()
 o Using generics and replaced iterators by for() 

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACIItem.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ItemFirstACIItem.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ProtectedItem.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserFirstACIItem.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserPermission.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACIItem.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACIItem.java?rev=577362&r1=577361&r2=577362&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACIItem.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACIItem.java Wed Sep 19 09:51:41 2007
@@ -110,15 +110,6 @@
 
 
     /**
-     * Converts this item into its string representation as stored
-     * in directory.
-     *
-     * @param buffer the string buffer
-     */
-    public abstract void printToBuffer( StringBuilder buffer );
-
-    
-    /**
      * Converts a set of {@link GrantAndDenial}s into a set of
      * {@link MicroOperation}s and returns it.
      */

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ItemFirstACIItem.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ItemFirstACIItem.java?rev=577362&r1=577361&r2=577362&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ItemFirstACIItem.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ItemFirstACIItem.java Wed Sep 19 09:51:41 2007
@@ -87,63 +87,25 @@
 
     public String toString()
     {
-        return "itemFirstACIItem: " + "identificationTag=" + getIdentificationTag() + ", " + "precedence="
-            + getPrecedence() + ", " + "authenticationLevel=" + getAuthenticationLevel() + ", " + "protectedItems="
-            + protectedItems + ", " + "itemPermissions=" + itemPermissions;
-    }
-
-
-    public Collection<ACITuple> toTuples()
-    {
-        Collection<ACITuple> tuples = new ArrayList<ACITuple>();
-        
-        for ( ItemPermission itemPermission:itemPermissions )
-        {
-            Set<GrantAndDenial> grants = itemPermission.getGrants();
-            Set<GrantAndDenial> denials = itemPermission.getDenials();
-            int precedence = itemPermission.getPrecedence() >= 0 ? itemPermission.getPrecedence() : this
-                .getPrecedence();
-
-            if ( grants.size() > 0 )
-            {
-                tuples.add( new ACITuple( itemPermission.getUserClasses(), getAuthenticationLevel(), protectedItems,
-                    toMicroOperations( grants ), true, precedence ) );
-            }
-            if ( denials.size() > 0 )
-            {
-                tuples.add( new ACITuple( itemPermission.getUserClasses(), getAuthenticationLevel(), protectedItems,
-                    toMicroOperations( denials ), false, precedence ) );
-            }
-        }
-        return tuples;
-    }
-
-
-    /**
-     * Converts this item into its string representation as stored
-     * in directory.
-     *
-     * @param buffer the string buffer
-     */
-    public void printToBuffer( StringBuilder buffer )
-    {
+    	StringBuilder buf = new StringBuilder();
+    	
         // identificationTag
-        buffer.append( "{ identificationTag \"" );
-        buffer.append( getIdentificationTag() );
+        buf.append( "{ identificationTag \"" );
+        buf.append( getIdentificationTag() );
 
         // precedence
-        buffer.append( "\", precedence " );
-        buffer.append( getPrecedence() );
+        buf.append( "\", precedence " );
+        buf.append( getPrecedence() );
         
         // authenticationLevel
-        buffer.append( ", authenticationLevel " );
-        buffer.append( getAuthenticationLevel().getName() );
+        buf.append( ", authenticationLevel " );
+        buf.append( getAuthenticationLevel().getName() );
         
         // itemOrUserFirst
-        buffer.append( ", itemOrUserFirst itemFirst: { " );
+        buf.append( ", itemOrUserFirst itemFirst: { " );
         
         // protectedItems
-        buffer.append( "protectedItems { " );
+        buf.append( "protectedItems { " );
         
         boolean isFirst = true;
 
@@ -155,14 +117,14 @@
             }
             else
             {
-                buffer.append( ", " );
+                buf.append( ", " );
             }
 
-            item.printToBuffer( buffer );
+            buf.append( item.toString() );
         }
 
         // itemPermissions
-        buffer.append( " }, itemPermissions { " );
+        buf.append( " }, itemPermissions { " );
 
         isFirst = true;
         
@@ -174,12 +136,41 @@
             }
             else
             {
-                buffer.append( ", " );
+                buf.append( ", " );
             }
 
-            permission.printToBuffer( buffer );
+            buf.append( permission.toString() );
         }
 
-        buffer.append( " } } }" );
+        buf.append( " } } }" );
+        
+        return buf.toString();
+    }
+
+
+    public Collection<ACITuple> toTuples()
+    {
+        Collection<ACITuple> tuples = new ArrayList<ACITuple>();
+        
+        for ( ItemPermission itemPermission:itemPermissions )
+        {
+            Set<GrantAndDenial> grants = itemPermission.getGrants();
+            Set<GrantAndDenial> denials = itemPermission.getDenials();
+            int precedence = itemPermission.getPrecedence() >= 0 ? itemPermission.getPrecedence() : this
+                .getPrecedence();
+
+            if ( grants.size() > 0 )
+            {
+                tuples.add( new ACITuple( itemPermission.getUserClasses(), getAuthenticationLevel(), protectedItems,
+                    toMicroOperations( grants ), true, precedence ) );
+            }
+            if ( denials.size() > 0 )
+            {
+                tuples.add( new ACITuple( itemPermission.getUserClasses(), getAuthenticationLevel(), protectedItems,
+                    toMicroOperations( denials ), false, precedence ) );
+            }
+        }
+        
+        return tuples;
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ProtectedItem.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ProtectedItem.java?rev=577362&r1=577361&r2=577362&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ProtectedItem.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ProtectedItem.java Wed Sep 19 09:51:41 2007
@@ -72,15 +72,6 @@
 
     
     /**
-     * Converts this item into its string representation as stored
-     * in directory.
-     *
-     * @param buffer the string buffer
-     */
-    public abstract void printToBuffer( StringBuilder buffer );
-
-    
-    /**
      * The contents of entries (possibly a family member) which are restricted
      * to those that have object class values that satisfy the predicate defined
      * by Refinement (see 12.3.5), together (in the case of an ancestor or other
@@ -130,10 +121,17 @@
         }
 
 
-        public void printToBuffer( StringBuilder buffer )
+        /**
+         * @see Object#toString()
+         */
+        public String toString()
         {
-            buffer.append( "classes " );
-            classes.printRefinementToBuffer( buffer );
+        	StringBuilder buf = new StringBuilder();
+        	
+        	buf.append( "classes " );
+        	classes.printRefinementToBuffer( buf );
+        	
+        	return buf.toString();
         }
     }
 
@@ -159,12 +157,6 @@
         {
             return "entry";
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "entry" );
-        }
     }
 
     /**
@@ -185,12 +177,6 @@
         {
             return "allUserAttributeTypes";
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "allUserAttributeTypes" );
-        }
     }
 
     /**
@@ -211,12 +197,6 @@
         {
             return "allUserAttributeTypesAndValues";
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "allUserAttributeTypesAndValues" );
-        }
     }
 
     /**
@@ -285,6 +265,36 @@
             
             buffer.append( " }" );
         }
+
+        
+        /**
+         * @see Object#toString()
+         */
+        public String toString()
+        {
+        	StringBuilder buf = new StringBuilder();
+        	
+            buf.append( "{ " );
+            boolean isFirst = true;
+            
+            for ( String attributeType:attributeTypes )
+            {
+                if ( isFirst ) 
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    buf.append( ", " );
+                }
+
+                buf.append( attributeType );
+            }
+            
+            buf.append( " }" );
+        	
+        	return buf.toString();
+        }
     }
 
     /**
@@ -312,13 +322,6 @@
         {
             return "attributeType: " + attributeTypes;
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "attributeType " );
-            super.printToBuffer( buffer );
-        }
     }
 
     /**
@@ -345,13 +348,6 @@
         {
             return "allAttributeValues: " + attributeTypes;
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "allAttributeValues " );
-            super.printToBuffer( buffer );
-        }
     }
 
     /**
@@ -382,13 +378,6 @@
         {
             return "selfValue: " + attributeTypes;
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "selfValue " );
-            super.printToBuffer( buffer );
-        }
     }
 
     /**
@@ -440,23 +429,19 @@
 
         public String toString()
         {
-            return "attributeValue: " + attributes;
-        }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "attributeValue {" );
+        	StringBuilder buf = new StringBuilder();
+        	
+            buf.append( "attributeValue {" );
             
             for ( Iterator<Attribute> it = attributes.iterator(); it.hasNext(); )
             {
                 Attribute attribute = it.next();
-                buffer.append( attribute.getID() );
-                buffer.append( '=' );
+                buf.append( attribute.getID() );
+                buf.append( '=' );
                 
                 try
                 {
-                    buffer.append( attribute.get( 0 ) );
+                    buf.append( attribute.get( 0 ) );
                 }
                 catch ( NamingException e )
                 {
@@ -465,11 +450,13 @@
                 
                 if ( it.hasNext() ) 
                 {
-                    buffer.append( ", " );
+                    buf.append( ", " );
                 }
             }
             
-            buffer.append( " }" );
+            buf.append( " }" );
+
+            return "attributeValue: " + attributes;
         }
     }
 
@@ -529,26 +516,29 @@
 
         public String toString()
         {
-            return "maxValueCount: " + items;
-        }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "maxValueCount {" );
-            
-            for ( Iterator<MaxValueCountItem> it = items.iterator(); it.hasNext(); )
-            {
-                MaxValueCountItem item = it.next();
-                item.printToBuffer( buffer );
-                
-                if ( it.hasNext() ) 
-                {
-                    buffer.append( ", " );
-                }
+        	StringBuilder buf = new StringBuilder();
+        	
+        	buf.append( "maxValueCount {" );
+
+        	boolean isFirst = true;
+        	
+            for ( MaxValueCountItem item:items )
+            {
+            	if ( isFirst )
+            	{
+            		isFirst = false;
+            	}
+            	else
+            	{
+            		buf.append( ", " );
+            	}
+            	
+                buf.append( item.toString() );
             }
             
-            buffer.append( " }" );
+            buf.append( "}" );
+
+            return buf.toString();
         }
     }
 
@@ -610,16 +600,10 @@
         {
         	StringBuilder buf = new StringBuilder();
             buf.append( "rangeOfValues: " );
-            filter.printToBuffer( buf );
+            buf.append( filter.toString() );
+            
             return buf.toString();
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "rangeOfValues " );
-            filter.printToBuffer( buffer );
-        }
     }
 
     /**
@@ -681,13 +665,6 @@
         {
             return "maxImmSub: " + value;
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "maxImmSub " );
-            buffer.append( value );
-        }
     }
 
     /**
@@ -745,26 +722,29 @@
 
         public String toString()
         {
-            return "restrictedBy: " + items;
-        }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "restrictedBy {" );
+        	StringBuilder buf = new StringBuilder();
+        	
+            buf.append( "restrictedBy {" );
+
+            boolean isFirst = true;
             
-            for ( Iterator<RestrictedByItem> it = items.iterator(); it.hasNext(); )
+            for ( RestrictedByItem item:items )
             {
-                RestrictedByItem item = it.next();
-                item.printToBuffer( buffer );
-                
-                if ( it.hasNext() ) 
-                {
-                    buffer.append( ", " );
-                }
+            	if ( isFirst )
+            	{
+            		isFirst = false;
+            	}
+            	else
+            	{
+            		buf.append( ", " );
+            	}
+            	
+                buf.append( item.toString() );
             }
             
-            buffer.append( " }" );
+            buf.append( '}' );
+            
+            return buf.toString();
         }
     }
 
@@ -818,16 +798,6 @@
         {
             return "attributeType=" + attributeType + ", maxCount=" + maxCount;
         }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "{ type " ).append( attributeType );
-
-            buffer.append( ", maxcount " ).append( maxCount );
-            
-            buffer.append( " }" );
-        }
     }
 
     /**
@@ -879,17 +849,7 @@
 
         public String toString()
         {
-            return "attributeType=" + attributeType + ", valuesIn=" + valuesIn;
-        }
-        
-        
-        public void printToBuffer( StringBuilder buffer )
-        {
-            buffer.append( "' type " ).append( attributeType );
-
-            buffer.append( ", valuesIn " ).append( valuesIn );
-            
-            buffer.append( " }" );
+            return "{attributeType=" + attributeType + ", valuesIn=" + valuesIn + "}";
         }
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserFirstACIItem.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserFirstACIItem.java?rev=577362&r1=577361&r2=577362&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserFirstACIItem.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserFirstACIItem.java Wed Sep 19 09:51:41 2007
@@ -23,7 +23,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.Set;
 
 
@@ -88,9 +87,69 @@
 
     public String toString()
     {
-        return "userFirstACIItem: " + "identificationTag=" + getIdentificationTag() + ", " + "precedence="
-            + getPrecedence() + ", " + "authenticationLevel=" + getAuthenticationLevel() + ", " + "userClasses="
-            + userClasses + ", " + "userPermissions=" + userPermissions;
+    	StringBuilder buf = new StringBuilder();
+    	
+        // identificationTag
+        buf.append( "{ identificationTag \"" );
+        buf.append( getIdentificationTag() );
+        buf.append( "\", " );
+        
+        // precedence
+        buf.append( "precedence " );
+        buf.append( getPrecedence() );
+        buf.append( ", " );
+        
+        // authenticationLevel
+        buf.append( "authenticationLevel " );
+        buf.append( getAuthenticationLevel().getName() );
+        buf.append( ", " );
+        
+        // itemOrUserFirst
+        buf.append( "itemOrUserFirst userFirst: { " );
+        
+        // protectedItems
+        buf.append( "userClasses { " );
+
+        boolean isFirst = true;
+        
+        for ( UserClass userClass:userClasses )
+        {
+        	if ( isFirst )
+        	{
+        		isFirst = false;
+        	}
+        	else
+        	{
+        		buf.append( ", " );
+        	}
+        	
+            buf.append( userClass.toString() );
+        }
+
+        buf.append( " }, " );
+        
+        // itemPermissions
+        buf.append( "userPermissions { " );
+
+        isFirst = true;
+        
+        for ( UserPermission permission:userPermissions )
+        {
+        	if ( isFirst )
+        	{
+        		isFirst = false;
+        	}
+        	else
+        	{
+        		buf.append( ", " );
+        	}
+        	
+            buf.append( permission.toString() );
+        }
+        
+        buf.append( " } } }" );
+
+        return buf.toString();
     }
 
 
@@ -117,65 +176,5 @@
             }
         }
         return tuples;
-    }
-    
-    
-    /**
-     * Converts this item into its string representation as stored
-     * in directory.
-     *
-     * @param buffer the string buffer
-     */
-    public void printToBuffer( StringBuilder buffer )
-    {
-        // identificationTag
-        buffer.append( "{ identificationTag \"" );
-        buffer.append( getIdentificationTag() );
-        buffer.append( "\", " );
-        
-        // precedence
-        buffer.append( "precedence " );
-        buffer.append( getPrecedence() );
-        buffer.append( ", " );
-        
-        // authenticationLevel
-        buffer.append( "authenticationLevel " );
-        buffer.append( getAuthenticationLevel().getName() );
-        buffer.append( ", " );
-        
-        // itemOrUserFirst
-        buffer.append( "itemOrUserFirst userFirst: { " );
-        
-        // protectedItems
-        buffer.append( "userClasses { " );
-
-        for ( Iterator it = userClasses.iterator(); it.hasNext(); )
-        {
-            UserClass userClass =  ( UserClass ) it.next();
-            userClass.printToBuffer( buffer );
-            
-            if ( it.hasNext() ) 
-            {
-                buffer.append( ", " );
-            }
-        }
-
-        buffer.append( " }, " );
-        
-        // itemPermissions
-        buffer.append( "userPermissions { " );
-
-        for ( Iterator it = userPermissions.iterator(); it.hasNext(); )
-        {
-            UserPermission permission = ( UserPermission ) it.next();
-            permission.printToBuffer( buffer );
-            
-            if ( it.hasNext() ) 
-            {
-                buffer.append( ", " );
-            }
-        }
-        
-        buffer.append( " } } }" );
     }
 }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserPermission.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserPermission.java?rev=577362&r1=577361&r2=577362&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserPermission.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserPermission.java Wed Sep 19 09:51:41 2007
@@ -22,7 +22,6 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 
 
 /**
@@ -69,54 +68,55 @@
 
     public String toString()
     {
-        return "itemPermission: precedence=" + getPrecedence() + ", " + "protectedItems=" + protectedItems + ", "
-            + "grantsAndDenials=" + getGrantsAndDenials();
-    }
-    
-    
-    /**
-     * Converts this item into its string representation as stored
-     * in directory.
-     *
-     * @param buffer the string buffer
-     */
-    public void printToBuffer( StringBuilder buffer )
-    {
-        buffer.append( "{ " );
+    	StringBuilder buf = new StringBuilder();
+    	
+        buf.append( "{ " );
 
         if ( getPrecedence() >= 0 && getPrecedence() <= 255 )
         {
-            buffer.append( "precedence " );
-            buffer.append( getPrecedence() );
-            buffer.append( ", " );
+            buf.append( "precedence " );
+            buf.append( getPrecedence() );
+            buf.append( ", " );
         }
         
-        buffer.append( "protectedItems { " );
+        buf.append( "protectedItems { " );
         
-        for ( Iterator it = protectedItems.iterator(); it.hasNext(); )
+        boolean isFirst = true;
+        
+        for ( ProtectedItem item:protectedItems )
         {
-            ProtectedItem item = ( ProtectedItem ) it.next();
-            item.printToBuffer( buffer );
-            
-            if ( it.hasNext() ) 
-            {
-                buffer.append( ", " );
-            }
+        	if ( isFirst )
+        	{
+        		isFirst = false;
+        	}
+        	else
+        	{
+        		buf.append( ", " );
+        	}
+        	
+            buf.append( item.toString() );
         }
         
-        buffer.append( " }, grantsAndDenials { " );
+        buf.append( " }, grantsAndDenials { " );
 
-        for ( Iterator it = getGrantsAndDenials().iterator(); it.hasNext(); )
+        isFirst = true;
+        
+        for ( GrantAndDenial grantAndDenial:getGrantsAndDenials() )
         {
-            GrantAndDenial grantAndDenial = ( GrantAndDenial ) it.next();
-            grantAndDenial.printToBuffer( buffer );
-            
-            if ( it.hasNext() ) 
-            {
-                buffer.append( ", " );
-            }
+        	if ( isFirst )
+        	{
+        		isFirst = false;
+        	}
+        	else
+        	{
+        		buf.append( ", " );
+        	}
+
+        	buf.append( grantAndDenial.toString() );
         }
         
-        buffer.append( " } }" );
+        buf.append( " } }" );
+        
+        return buf.toString();
     }
 }