directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1418346 - in /directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api: entry/ServerEntryUtils.java filtering/BaseEntryFilteringCursor.java
Date Fri, 07 Dec 2012 15:01:11 GMT
Author: elecharny
Date: Fri Dec  7 15:01:10 2012
New Revision: 1418346

URL: http://svn.apache.org/viewvc?rev=1418346&view=rev
Log:
Moved the filterContents(Entry) method to ServerEntryUtils, so that we can use it elswhere

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/entry/ServerEntryUtils.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/entry/ServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/entry/ServerEntryUtils.java?rev=1418346&r1=1418345&r2=1418346&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/entry/ServerEntryUtils.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/entry/ServerEntryUtils.java
Fri Dec  7 15:01:10 2012
@@ -35,6 +35,8 @@ import javax.naming.directory.InvalidAtt
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchResult;
 
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
@@ -49,8 +51,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeTypeException;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.AttributeTypeOptions;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.SchemaUtils;
+import org.apache.directory.shared.ldap.model.schema.UsageEnum;
 import org.apache.directory.shared.util.EmptyEnumeration;
 import org.apache.directory.shared.util.Strings;
 
@@ -726,4 +730,131 @@ public class ServerEntryUtils
             return null;
         }
     }
+    
+    
+    /**
+     * Filters an entry accordingly to the requested Attribute list.
+     * 
+     * @param entry The entry to filter
+     * @param operationContext The SearchingOperationContext
+     * @throws Exception If the filtering fails
+     */
+    public static void filterContents( Entry entry, SearchingOperationContext operationContext
) throws Exception
+    {
+        boolean typesOnly = operationContext.isTypesOnly();
+
+        boolean returnAll = ( operationContext.getReturningAttributes() == null ||
+            ( operationContext.isAllOperationalAttributes() && operationContext.isAllUserAttributes()
) )
+            && ( !typesOnly );
+
+        if ( returnAll )
+        {
+            return;
+        }
+
+        Entry originalEntry = ( ( ClonedServerEntry ) entry ).getOriginalEntry();
+
+        if ( operationContext.isNoAttributes() )
+        {
+            for ( Attribute attribute : originalEntry.getAttributes() )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                entry.remove( entry.get( attributeType ) );
+            }
+
+            return;
+        }
+
+        if ( operationContext.isAllUserAttributes() )
+        {
+            for ( Attribute attribute : originalEntry.getAttributes() )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                boolean isNotRequested = true;
+
+                for ( AttributeTypeOptions attrOptions : operationContext.getReturningAttributes()
)
+                {
+                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
+                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
+                    {
+                        isNotRequested = false;
+                        break;
+                    }
+                }
+
+                boolean isNotUserAttribute = attributeType.getUsage() != UsageEnum.USER_APPLICATIONS;
+
+                if ( isNotRequested && isNotUserAttribute )
+                {
+                    entry.removeAttributes( attributeType );
+                }
+                else if ( typesOnly )
+                {
+                    entry.get( attributeType ).clear();
+                }
+            }
+
+            return;
+        }
+
+        if ( operationContext.isAllOperationalAttributes() )
+        {
+            for ( Attribute attribute : originalEntry.getAttributes() )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                boolean isNotRequested = true;
+
+                for ( AttributeTypeOptions attrOptions : operationContext.getReturningAttributes()
)
+                {
+                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
+                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
+                    {
+                        isNotRequested = false;
+                        break;
+                    }
+                }
+
+                boolean isUserAttribute = attributeType.getUsage() == UsageEnum.USER_APPLICATIONS;
+
+                if ( isNotRequested && isUserAttribute )
+                {
+                    entry.removeAttributes( attributeType );
+                }
+                else if ( typesOnly )
+                {
+                    entry.get( attributeType ).clear();
+                }
+            }
+
+            return;
+        }
+
+        if ( operationContext.getReturningAttributes() != null )
+        {
+            for ( Attribute attribute : originalEntry.getAttributes() )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                boolean isNotRequested = true;
+
+                for ( AttributeTypeOptions attrOptions : operationContext.getReturningAttributes()
)
+                {
+                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
+                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
+                    {
+                        isNotRequested = false;
+                        break;
+                    }
+                }
+
+                if ( isNotRequested )
+                {
+                    entry.removeAttributes( attributeType );
+                }
+                else if ( typesOnly )
+                {
+                    entry.get( attributeType ).clear();
+                }
+            }
+        }
+    }
 }

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java?rev=1418346&r1=1418345&r2=1418346&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
Fri Dec  7 15:01:10 2012
@@ -26,6 +26,7 @@ import java.util.List;
 
 import org.apache.directory.server.core.api.entry.ClonedServerEntry;
 import org.apache.directory.server.core.api.entry.ClonedServerEntrySearch;
+import org.apache.directory.server.core.api.entry.ServerEntryUtils;
 import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.shared.ldap.model.cursor.AbstractCursor;
 import org.apache.directory.shared.ldap.model.cursor.ClosureMonitor;
@@ -353,126 +354,6 @@ public class BaseEntryFilteringCursor ex
     }
 
 
-    private void filterContents( Entry entry ) throws Exception
-    {
-        boolean typesOnly = getOperationContext().isTypesOnly();
-
-        boolean returnAll = ( getOperationContext().getReturningAttributes() == null ||
-            ( getOperationContext().isAllOperationalAttributes() && getOperationContext().isAllUserAttributes()
) )
-            && ( !typesOnly );
-
-        if ( returnAll )
-        {
-            return;
-        }
-
-        Entry originalEntry = ( ( ClonedServerEntry ) entry ).getOriginalEntry();
-
-        if ( getOperationContext().isNoAttributes() )
-        {
-            for ( Attribute attribute : originalEntry.getAttributes() )
-            {
-                AttributeType attributeType = attribute.getAttributeType();
-                entry.remove( entry.get( attributeType ) );
-            }
-
-            return;
-        }
-
-        if ( getOperationContext().isAllUserAttributes() )
-        {
-            for ( Attribute attribute : originalEntry.getAttributes() )
-            {
-                AttributeType attributeType = attribute.getAttributeType();
-                boolean isNotRequested = true;
-
-                for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes()
)
-                {
-                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
-                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
-                    {
-                        isNotRequested = false;
-                        break;
-                    }
-                }
-
-                boolean isNotUserAttribute = attributeType.getUsage() != UsageEnum.USER_APPLICATIONS;
-
-                if ( isNotRequested && isNotUserAttribute )
-                {
-                    entry.removeAttributes( attributeType );
-                }
-                else if ( typesOnly )
-                {
-                    entry.get( attributeType ).clear();
-                }
-            }
-
-            return;
-        }
-
-        if ( getOperationContext().isAllOperationalAttributes() )
-        {
-            for ( Attribute attribute : originalEntry.getAttributes() )
-            {
-                AttributeType attributeType = attribute.getAttributeType();
-                boolean isNotRequested = true;
-
-                for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes()
)
-                {
-                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
-                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
-                    {
-                        isNotRequested = false;
-                        break;
-                    }
-                }
-
-                boolean isUserAttribute = attributeType.getUsage() == UsageEnum.USER_APPLICATIONS;
-
-                if ( isNotRequested && isUserAttribute )
-                {
-                    entry.removeAttributes( attributeType );
-                }
-                else if ( typesOnly )
-                {
-                    entry.get( attributeType ).clear();
-                }
-            }
-
-            return;
-        }
-
-        if ( getOperationContext().getReturningAttributes() != null )
-        {
-            for ( Attribute attribute : originalEntry.getAttributes() )
-            {
-                AttributeType attributeType = attribute.getAttributeType();
-                boolean isNotRequested = true;
-
-                for ( AttributeTypeOptions attrOptions : getOperationContext().getReturningAttributes()
)
-                {
-                    if ( attrOptions.getAttributeType().equals( attributeType ) ||
-                        attrOptions.getAttributeType().isAncestorOf( attributeType ) )
-                    {
-                        isNotRequested = false;
-                        break;
-                    }
-                }
-
-                if ( isNotRequested )
-                {
-                    entry.removeAttributes( attributeType );
-                }
-                else if ( typesOnly )
-                {
-                    entry.get( attributeType ).clear();
-                }
-            }
-        }
-    }
-
-
     /**
      * {@inheritDoc}
      */
@@ -519,14 +400,16 @@ public class BaseEntryFilteringCursor ex
             if ( filters.isEmpty() )
             {
                 prefetched = tempResult;
-                filterContents( prefetched );
+                ServerEntryUtils.filterContents( prefetched, getOperationContext() );
+                
                 return true;
             }
 
             if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(),
tempResult ) )
             {
                 prefetched = tempResult;
-                filterContents( prefetched );
+                ServerEntryUtils.filterContents( prefetched, getOperationContext() );
+
                 return true;
             }
 
@@ -544,12 +427,13 @@ public class BaseEntryFilteringCursor ex
              * Here the entry has been accepted by all filters.
              */
             prefetched = tempResult;
-            filterContents( prefetched );
+            ServerEntryUtils.filterContents( prefetched, getOperationContext() );
 
             return true;
         }
 
         prefetched = null;
+        
         return false;
     }
 
@@ -591,14 +475,16 @@ public class BaseEntryFilteringCursor ex
             if ( filters.isEmpty() )
             {
                 prefetched = tempResult;
-                filterContents( prefetched );
+                ServerEntryUtils.filterContents( prefetched, getOperationContext() );
+
                 return true;
             }
 
             if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(),
tempResult ) )
             {
                 prefetched = tempResult;
-                filterContents( prefetched );
+                ServerEntryUtils.filterContents( prefetched, getOperationContext() );
+
                 return true;
             }
 
@@ -617,7 +503,7 @@ public class BaseEntryFilteringCursor ex
              * Here the entry has been accepted by all filters.
              */
             prefetched = tempResult;
-            filterContents( prefetched );
+            ServerEntryUtils.filterContents( prefetched, getOperationContext() );
 
             return true;
         }
@@ -638,7 +524,7 @@ public class BaseEntryFilteringCursor ex
         if ( wrapped != null )
         {
             sb.append( tabs ).append( "BaseEntryFilteringCursor, wrapped : \n" );
-            sb.append( wrapped.toString( tabs + "    " ) ).append( "\n" );
+            sb.append( wrapped.toString( tabs + "    " ) );
         }
         else
         {



Mime
View raw message