directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1419458 - in /directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context: FilteringOperationContext.java LookupOperationContext.java SearchingOperationContext.java
Date Mon, 10 Dec 2012 13:48:10 GMT
Author: elecharny
Date: Mon Dec 10 13:48:09 2012
New Revision: 1419458

URL: http://svn.apache.org/viewvc?rev=1419458&view=rev
Log:
Added a common root class for the lookup and search context, as we are sharing many of the
filtering elements

Added:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java
  (with props)
Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/LookupOperationContext.java
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java

Added: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java?rev=1419458&view=auto
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java
(added)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java
Mon Dec 10 13:48:09 2012
@@ -0,0 +1,573 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ * 
+ */
+package org.apache.directory.server.core.api.interceptor.context;
+
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapNoSuchAttributeException;
+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.SchemaUtils;
+import org.apache.directory.shared.ldap.model.schema.UsageEnum;
+import org.apache.directory.shared.util.StringConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A context used to store the filter used to manage the Attributes the user
+ * ha srequested. It's used by the Lookup, List and Search operations
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class FilteringOperationContext extends AbstractOperationContext
+{
+    /** The LoggerFactory used by this Interceptor */
+    protected static Logger LOG = LoggerFactory.getLogger( FilteringOperationContext.class
);
+
+    private static final String[] EMPTY = new String[]
+        {};
+
+    /** A set containing the returning attributeTypesOptions */
+    protected Set<AttributeTypeOptions> returningAttributes;
+
+    /** The set of attributes to return as String */
+    protected String[] returningAttributesString;
+
+    /** A flag set to true if the user has requested all the operational attributes ( "+"
)*/
+    private Boolean allOperationalAttributes;
+
+    /** A flag set to true if the user has requested all the user attributes ( "*" ) */
+    private Boolean allUserAttributes;
+
+    /** A flag set to true if the user has requested no attribute to be returned (1.1) */
+    private Boolean noAttributes;
+
+    /** A flag to tell if only the attribute names to be returned. */
+    protected Boolean typesOnly = false;
+
+
+    /**
+     * 
+     * Creates a new instance of LookupOperationContext.
+     *
+     */
+    public FilteringOperationContext( CoreSession session )
+    {
+        super( session );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of LookupOperationContext.
+     *
+     */
+    public FilteringOperationContext( CoreSession session, Dn dn )
+    {
+        super( session, dn );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of LookupOperationContext.
+     *
+     */
+    public FilteringOperationContext( CoreSession session, Set<AttributeTypeOptions>
returningAttributes )
+    {
+        super( session );
+        setReturningAttributes( returningAttributes );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of LookupOperationContext.
+     *
+     */
+    public FilteringOperationContext( CoreSession session, Dn dn, Set<AttributeTypeOptions>
returningAttributes )
+    {
+        super( session, dn );
+        setReturningAttributes( returningAttributes );
+    }
+
+
+    /**
+     * Add an attribute ID to the current list, creating the list if necessary
+     *
+     * @param attrId the Id to add
+     *
+    public void addAttrsId( String attrId )
+    {
+        if ( noAttributes == null )
+        {
+            if ( attrId.equals( SchemaConstants.NO_ATTRIBUTE ) )
+            {
+                noAttributes = true;
+
+                if ( attrsId != null )
+                {
+                    attrsId.clear();
+                }
+
+                return;
+            }
+
+            if ( attrId.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
+            {
+                allUserAttributes = true;
+
+                return;
+            }
+
+            if ( attrId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
+            {
+                allOperationalAttributes = true;
+
+                return;
+            }
+
+            if ( attrsId == null )
+            {
+                attrsId = new ArrayList<String>();
+            }
+
+            attrsId.add( attrId );
+        }
+    }
+
+
+    /**
+     * @return the returningAttributes as a Set of AttributeTypeOptions
+     */
+    public Set<AttributeTypeOptions> getReturningAttributes()
+    {
+        return returningAttributes;
+    }
+
+
+    /**
+     * @return the returning Attributes, as a array of Strings
+     */
+    public String[] getReturningAttributesString()
+    {
+        return returningAttributesString;
+    }
+    
+    
+    /**
+     * Tells if an attribute is present in the list of attribute to return
+     * 
+     * @param attribute The attribute we are looking for
+     * @return true if the attribute is present
+     */
+    public boolean contains( String attribute )
+    {
+        if ( isNoAttributes() )
+        {
+            return false;
+        }
+        
+        try
+        {
+            AttributeType attributeType = getSession().getDirectoryService().
+                getSchemaManager().lookupAttributeTypeRegistry( attribute );
+            
+            if ( ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && isAllUserAttributes()
)
+            {
+                return true;
+            }
+
+            if ( ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) && isAllOperationalAttributes()
)
+            {
+                return true;
+            }
+
+            AttributeTypeOptions attributeTypeOption = new AttributeTypeOptions( attributeType
);
+            
+            boolean present = returningAttributes.contains( attributeTypeOption );
+            
+            return present;
+        }
+        catch ( LdapException le )
+        {
+            return false;
+        }
+    }
+
+
+    /**
+     * @param returningAttributes the returningAttributes to set
+     */
+    public void setReturningAttributes( Set<AttributeTypeOptions> returningAttributes
)
+    {
+        this.returningAttributes = returningAttributes;
+    }
+    
+    
+    public void setReturningAttributes( String... attributesIds ) throws LdapException
+    {
+        if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
+        {
+            returningAttributes = new HashSet<AttributeTypeOptions>();
+            Set<String> attributesString = new HashSet<String>();
+            int nbInvalid = 0;
+            
+            for ( String returnAttribute : attributesIds )
+            {
+                if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
+                {
+                    noAttributes = true;
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES )
)
+                {
+                    allOperationalAttributes = true;
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
+                {
+                    allUserAttributes = true;
+                    continue;
+                }
+
+                try
+                {
+                    String id = SchemaUtils.stripOptions( returnAttribute );
+                    Set<String> options = SchemaUtils.getOptions( returnAttribute );
+
+                    AttributeType attributeType = session.getDirectoryService()
+                        .getSchemaManager().lookupAttributeTypeRegistry( id );
+                    AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType,
options );
+
+                    returningAttributes.add( attrOptions );
+                    attributesString.add( attributeType.getOid() );
+                }
+                catch ( LdapNoSuchAttributeException nsae )
+                {
+                    LOG.warn( "Requested attribute {} does not exist in the schema, it will
be ignored",
+                        returnAttribute );
+                    // Unknown attributes should be silently ignored, as RFC 2251 states
+                    nbInvalid++;
+                }
+            }
+
+            // reset the noAttribute flag if it is already set cause that will be ignored
if any other AT is requested
+            if ( isNoAttributes() && 
+                ( isAllUserAttributes() || 
+                  isAllOperationalAttributes() || 
+                  ( ( returningAttributes != null ) && ( returningAttributes.size()
> 0 ) ) ) )
+            {
+                noAttributes = false;
+            }
+            
+            if ( attributesString.size() > 0 )
+            {
+                returningAttributesString = attributesString.toArray( ArrayUtils.EMPTY_STRING_ARRAY
);
+            }
+            else if ( nbInvalid > 0 )
+            {
+                returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
+            }
+            else
+            {
+                String[] ret = new String[3];
+                
+                int nbElem = 0;
+                
+                if ( isNoAttributes() )
+                {
+                    ret[nbElem++] = SchemaConstants.NO_ATTRIBUTE;
+                }
+                
+                if ( isAllOperationalAttributes() )
+                {
+                    ret[nbElem++] = SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES;
+                }
+                
+                if ( isAllUserAttributes() )
+                {
+                    ret[nbElem++] = SchemaConstants.ALL_USER_ATTRIBUTES;
+                }
+                
+                if ( nbElem == 0 )
+                {
+                    returningAttributesString = new String[]{ SchemaConstants.ALL_USER_ATTRIBUTES
};
+                    allUserAttributes = true;
+                }
+                else
+                {
+                    returningAttributesString = new String[nbElem];
+                    System.arraycopy( ret, 0, returningAttributesString, 0, nbElem );
+                }
+            }
+        }
+    }
+
+
+    
+    
+    public void addReturningAttributes( String... attributesIds ) throws LdapException
+    {
+        if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
+        {
+            Set<String> attributesString = new HashSet<String>();
+            int nbInvalid = 0;
+            
+            for ( String returnAttribute : attributesIds )
+            {
+                if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
+                {
+                    noAttributes = true;
+                    attributesString.add( SchemaConstants.NO_ATTRIBUTE );
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES )
)
+                {
+                    allOperationalAttributes = true;
+                    attributesString.add( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
+                    continue;
+                }
+
+                if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
+                {
+                    allUserAttributes = true;
+                    attributesString.add( SchemaConstants.ALL_USER_ATTRIBUTES );
+                    continue;
+                }
+
+                try
+                {
+                    String id = SchemaUtils.stripOptions( returnAttribute );
+                    Set<String> options = SchemaUtils.getOptions( returnAttribute );
+
+                    AttributeType attributeType = session.getDirectoryService()
+                        .getSchemaManager().lookupAttributeTypeRegistry( id );
+                    AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType,
options );
+
+                    returningAttributes.add( attrOptions );
+                    
+                    attributesString.add( attributeType.getOid() );
+                }
+                catch ( LdapNoSuchAttributeException nsae )
+                {
+                    LOG.warn( "Requested attribute {} does not exist in the schema, it will
be ignored",
+                        returnAttribute );
+                    // Unknown attributes should be silently ignored, as RFC 2251 states
+                    nbInvalid++;
+                }
+            }
+
+            // reset the noAttribute flag if it is already set cause that will be ignored
if any other AT is requested
+            if ( noAttributes && ( allUserAttributes || allOperationalAttributes
|| ( !returningAttributes.isEmpty() ) ) )
+            {
+                noAttributes = false;
+            }
+            
+            if ( attributesString.size() > 0 )
+            {
+                returningAttributesString = attributesString.toArray( ArrayUtils.EMPTY_STRING_ARRAY
);
+            }
+            else if ( nbInvalid > 0 )
+            {
+                returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
+            }
+            else
+            {
+                returningAttributesString = new String[]{ SchemaConstants.ALL_USER_ATTRIBUTES
};
+                allUserAttributes = true;
+            }
+        }
+    }
+
+
+    protected void setReturningAttributes( Collection<String> attributesIds )
+        throws LdapException
+    {
+        setReturningAttributes( attributesIds.toArray( StringConstants.EMPTY_STRINGS ) );
+    }
+
+
+    /**
+     * @param allOperationalAttributes the allOperationalAttributes to set
+     */
+    public void setAllOperationalAttributes( boolean allOperationalAttribute )
+    {
+        this.allOperationalAttributes = allOperationalAttribute;
+    }
+
+
+    /**
+     * @return The flag telling if the "*" attribute has been used
+     */
+    public boolean hasAllUserAttributes()
+    {
+        return ( allUserAttributes != null );
+    }
+
+
+    /**
+     * @return The flag telling if the "*" attribute has been used
+     */
+    public boolean isAllUserAttributes()
+    {
+        return ( allUserAttributes != null ) && allUserAttributes;
+    }
+
+
+    /**
+     * @param allUserAttributes the allUserAttributes to set
+     */
+    public void setAllUserAttributes( boolean allUserAttributes )
+    {
+        this.allUserAttributes = allUserAttributes;
+    }
+
+
+    /**
+     * @return The flag telling if the "+" attribute has been used
+     */
+    public boolean hasAllOperationalAttributes()
+    {
+        return ( allOperationalAttributes != null );
+    }
+
+
+    /**
+     * @return The flag telling if the "+" attribute has been used
+     */
+    public boolean isAllOperationalAttributes()
+    {
+        return ( allOperationalAttributes != null ) && allOperationalAttributes;
+    }
+
+
+    /**
+     * @return The flag telling if the "1.1" attribute has been used
+     */
+    public boolean hasNoAttributes()
+    {
+        return ( noAttributes != null );
+    }
+
+
+    /**
+     * @return The flag telling if the "1.1" attribute has been used
+     */
+    public boolean isNoAttributes()
+    {
+        return ( noAttributes != null ) && ( noAttributes );
+    }
+
+    
+    /**
+     * @param noAttributes the noAttributes to set
+     */
+    public void setNoAttributes( boolean noAttributes )
+    {
+        this.noAttributes = noAttributes;
+    }
+
+
+    /**
+     * @return true, if attribute descriptions alone need to be returned
+     */
+    public boolean isTypesOnly()
+    {
+        return typesOnly;
+    }
+
+
+    /**
+     * @param typesOnly true If we want to get back the attributeType only
+     */
+    public void setTypesOnly( boolean typesOnly )
+    {
+        this.typesOnly = typesOnly;
+    }
+
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "FilteringOperationContext for Dn '" );
+        sb.append( getDn().getName() ).append( "'" );
+
+        if ( isTypesOnly() )
+        {
+            sb.append( ", type only" );
+        }
+        
+        if ( hasAllOperationalAttributes() )
+        {
+            sb.append( ", +" );
+        }
+
+        if ( hasAllUserAttributes() )
+        {
+            sb.append( ", *" );
+        }
+
+        if ( isNoAttributes() )
+        {
+            sb.append( ", 1.1" );
+        }
+
+        if ( ( returningAttributesString != null ) && ( returningAttributesString.length
> 0 ) )
+        {
+            sb.append( ", attributes : <" );
+            boolean isFirst = true;
+            
+            for ( String returningAttribute : returningAttributesString )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ", " );
+                }
+                
+                sb.append( returningAttribute );
+            }
+            
+            sb.append(  ">" );
+        }
+
+        return sb.toString();
+    }
+}

Propchange: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/FilteringOperationContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/LookupOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/LookupOperationContext.java?rev=1419458&r1=1419457&r2=1419458&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/LookupOperationContext.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/LookupOperationContext.java
Mon Dec 10 13:48:09 2012
@@ -20,15 +20,13 @@
 package org.apache.directory.server.core.api.interceptor.context;
 
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Set;
 
 import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.core.api.OperationEnum;
-import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.name.Dn;
-import org.apache.directory.shared.util.Strings;
+import org.apache.directory.shared.ldap.model.schema.AttributeTypeOptions;
 
 
 /**
@@ -37,23 +35,8 @@ import org.apache.directory.shared.util.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LookupOperationContext extends AbstractOperationContext
+public class LookupOperationContext extends FilteringOperationContext
 {
-    private static final String[] EMPTY = new String[]
-        {};
-
-    /** The list of attributes id to return */
-    private List<String> attrsId = new ArrayList<String>();
-
-    /** A flag set to true if the user has requested all the operational attributes ( "+"
)*/
-    private Boolean allOperational;
-
-    /** A flag set to true if the user has requested all the user attributes ( "*" ) */
-    private Boolean allUser;
-
-    /** A flag set to true if the user has requested no attribute to be returned */
-    private Boolean noAttribute;
-
     /** flag to indicate if this search is done for replication */
     private boolean syncreplLookup;
 
@@ -94,10 +77,18 @@ public class LookupOperationContext exte
      * Creates a new instance of LookupOperationContext.
      *
      */
-    public LookupOperationContext( CoreSession session, String attrsId[] )
+    public LookupOperationContext( CoreSession session, String... returningAttributes )
     {
         super( session );
-        setAttrsId( attrsId );
+        
+        try
+        {
+            setReturningAttributes( returningAttributes );
+        }
+        catch ( LdapException le )
+        {
+            LOG.error( le.getMessage() );
+        }
 
         if ( session != null )
         {
@@ -105,16 +96,17 @@ public class LookupOperationContext exte
         }
     }
 
+    
+
 
     /**
      * 
      * Creates a new instance of LookupOperationContext.
      *
      */
-    public LookupOperationContext( CoreSession session, Dn dn, String attrsId[] )
+    public LookupOperationContext( CoreSession session, Set<AttributeTypeOptions> returningAttributes
)
     {
-        super( session, dn );
-        setAttrsId( attrsId );
+        super( session, returningAttributes );
 
         if ( session != null )
         {
@@ -124,161 +116,47 @@ public class LookupOperationContext exte
 
 
     /**
-     * @return Get the attribute ids as a String array
+     * 
+     * Creates a new instance of LookupOperationContext.
+     *
      */
-    public String[] getAttrsIdArray()
+    public LookupOperationContext( CoreSession session, Dn dn, String... returningAttributes
)
     {
-        if ( ( attrsId == null ) || ( attrsId.size() == 0 ) )
+        super( session, dn );
+        
+        try
         {
-            return EMPTY;
+            setReturningAttributes( returningAttributes );
         }
-        else
+        catch ( LdapException le )
         {
-            String[] attrs = new String[attrsId.size()];
-            return attrsId.toArray( attrs );
+            LOG.error( le.getMessage() );
         }
-    }
-
 
-    /**
-     * Set the attribute Ids
-     *
-     * @param attrsId The String array containing all the attribute IDs
-     */
-    public void setAttrsId( String[] attrsId )
-    {
-        if ( ( attrsId != null ) && ( attrsId.length > 0 ) )
+        if ( session != null )
         {
-            this.attrsId = new ArrayList<String>( Arrays.asList( attrsId ) );
-            int nbNoAttribute = 0;
-
-            // filter out the '+' and '*' and set boolean parameters
-            for ( String id : this.attrsId )
-            {
-                if ( id.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
-                {
-                    allOperational = true;
-                }
-                else if ( id.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
-                {
-                    allUser = true;
-                }
-                else if ( id.equals( SchemaConstants.NO_ATTRIBUTE ) )
-                {
-                    noAttribute = true;
-                    nbNoAttribute++;
-                }
-            }
-
-            if ( ( allOperational != null ) && allOperational )
-            {
-                this.attrsId.remove( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
-            }
-
-            if ( ( allUser != null ) && allUser )
-            {
-                this.attrsId.remove( SchemaConstants.ALL_USER_ATTRIBUTES );
-            }
-
-            if ( noAttribute != null )
-            {
-                if ( attrsId.length == nbNoAttribute )
-                {
-                    this.attrsId.clear();
-                }
-                else
-                {
-                    // We have to ignore the 1.1
-                    this.attrsId.remove( SchemaConstants.NO_ATTRIBUTE );
-                    noAttribute = false;
-                }
-            }
+            setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.LOOKUP
) );
         }
     }
 
 
     /**
-     * Add an attribute ID to the current list, creating the list if necessary
+     * 
+     * Creates a new instance of LookupOperationContext.
      *
-     * @param attrId the Id to add
      */
-    public void addAttrsId( String attrId )
+    public LookupOperationContext( CoreSession session, Dn dn, Set<AttributeTypeOptions>
returningAttributes )
     {
-        if ( noAttribute == null )
-        {
-            if ( attrId.equals( SchemaConstants.NO_ATTRIBUTE ) )
-            {
-                noAttribute = true;
-
-                if ( attrsId != null )
-                {
-                    attrsId.clear();
-                }
-
-                return;
-            }
-
-            if ( attrId.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
-            {
-                allUser = true;
-
-                return;
-            }
-
-            if ( attrId.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
-            {
-                allOperational = true;
-
-                return;
-            }
-
-            if ( attrsId == null )
-            {
-                attrsId = new ArrayList<String>();
-            }
+        super( session, dn, returningAttributes );
 
-            attrsId.add( attrId );
+        if ( session != null )
+        {
+            setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.LOOKUP
) );
         }
     }
 
 
     /**
-     * @return The attribute IDs list
-     */
-    public List<String> getAttrsId()
-    {
-        return attrsId;
-    }
-
-
-    /**
-     * @return The flag telling if the "*" attribute has been used
-     */
-    public boolean hasAllUser()
-    {
-        return ( allUser != null ) && allUser;
-    }
-
-
-    /**
-     * @return The flag telling if the "+" attribute has been used
-     */
-    public boolean hasAllOperational()
-    {
-        return ( allOperational != null ) && allOperational;
-    }
-
-
-    /**
-     * @return The flag telling if the "1.1" attribute has been used
-     */
-    public boolean hasNoAttribute()
-    {
-        return ( noAttribute != null );
-    }
-
-
-    /**
      * @return the operation name
      */
     public String getName()
@@ -305,14 +183,4 @@ public class LookupOperationContext exte
     {
         this.syncreplLookup = syncreplLookup;
     }
-    
-    
-    /**
-     * @see Object#toString()
-     */
-    public String toString()
-    {
-        return "LookupContext for Dn '" + getDn().getName() + "'"
-            + ( ( attrsId != null ) ? ", attributes : <" + Strings.listToString( attrsId
) + ">" : "" );
-    }
 }

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java?rev=1419458&r1=1419457&r2=1419458&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/interceptor/context/SearchingOperationContext.java
Mon Dec 10 13:48:09 2012
@@ -22,24 +22,14 @@ package org.apache.directory.server.core
 
 import static org.apache.directory.shared.ldap.model.message.SearchScope.ONELEVEL;
 
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.directory.server.core.api.CoreSession;
-import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.ldap.model.exception.LdapNoSuchAttributeException;
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 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.SchemaUtils;
-import org.apache.directory.shared.util.StringConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -48,11 +38,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class SearchingOperationContext extends AbstractOperationContext
+public abstract class SearchingOperationContext extends FilteringOperationContext
 {
-    /** The LoggerFactory used by this Interceptor */
-    private static Logger LOG = LoggerFactory.getLogger( SearchingOperationContext.class
);
-
     /** A flag describing the way alias should be handled */
     protected AliasDerefMode aliasDerefMode = AliasDerefMode.DEREF_ALWAYS;
 
@@ -65,27 +52,9 @@ public abstract class SearchingOperation
     /** The scope for this search : default to One Level */
     protected SearchScope scope = ONELEVEL;
 
-    /** A flag set if the returned attributes set contains '+' */
-    protected boolean allOperationalAttributes = false;
-
-    /** A flag set if the returned attributes set contains '*' */
-    protected boolean allUserAttributes = false;
-
-    /** A flag set if the returned attributes set contains '1.1' */
-    protected boolean noAttributes = false;
-
-    /** A set containing the returning attributeTypesOptions */
-    protected Set<AttributeTypeOptions> returningAttributes;
-
-    /** The set of attributes to return as String */
-    protected String[] returningAttributesString;
-
     /** A flag if the search operation is abandoned */
     protected boolean abandoned = false;
 
-    /** A flag to tell if only the attribute names to be returned */
-    protected boolean typesOnly = false;
-
 
     /**
      * Creates a new instance of SearchingOperationContext.
@@ -99,6 +68,7 @@ public abstract class SearchingOperation
     /**
      * Creates a new instance of SearchingOperationContext.
      *
+     * @param session The LDAP session we are in
      * @param dn The Dn to get the suffix from
      */
     public SearchingOperationContext( CoreSession session, Dn dn )
@@ -111,114 +81,30 @@ public abstract class SearchingOperation
      * Creates a new instance of a SearchingOperationContext using one level
      * scope, with attributes to return.
      *
+     * @param session The LDAP session we are in
      * @param dn The Dn to get the suffix from
-     * @param aliasDerefMode the alias dereferencing mode to use
+     * @param returningAttributes The list of attributes to return
      * @throws LdapException
      */
     public SearchingOperationContext( CoreSession session, Dn dn, Set<AttributeTypeOptions>
returningAttributes )
     {
-        super( session, dn );
-        this.returningAttributes = returningAttributes;
-    }
-
-
-    protected void setReturningAttributes( Collection<String> attributesIds )
-        throws LdapException
-    {
-        setReturningAttributes( attributesIds.toArray( StringConstants.EMPTY_STRINGS ) );
-    }
-
-
-    public void setReturningAttributes( String... attributesIds ) throws LdapException
-    {
-        if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
-        {
-            returningAttributes = new HashSet<AttributeTypeOptions>();
-            Set<String> attributesString = new HashSet<String>();
-            int nbInvalid = 0;
-            
-            for ( String returnAttribute : attributesIds )
-            {
-                if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
-                {
-                    noAttributes = true;
-                    attributesString.add( SchemaConstants.NO_ATTRIBUTE );
-                    continue;
-                }
-
-                if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES )
)
-                {
-                    allOperationalAttributes = true;
-                    attributesString.add( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES );
-                    continue;
-                }
-
-                if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
-                {
-                    allUserAttributes = true;
-                    attributesString.add( SchemaConstants.ALL_USER_ATTRIBUTES );
-                    continue;
-                }
-
-                try
-                {
-                    String id = SchemaUtils.stripOptions( returnAttribute );
-                    Set<String> options = SchemaUtils.getOptions( returnAttribute );
-
-                    AttributeType attributeType = session.getDirectoryService()
-                        .getSchemaManager().lookupAttributeTypeRegistry( id );
-                    AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType,
options );
-
-                    returningAttributes.add( attrOptions );
-                    attributesString.add( attributeType.getOid() );
-                }
-                catch ( LdapNoSuchAttributeException nsae )
-                {
-                    LOG.warn( "Requested attribute {} does not exist in the schema, it will
be ignored",
-                        returnAttribute );
-                    // Unknown attributes should be silently ignored, as RFC 2251 states
-                    nbInvalid++;
-                }
-            }
-
-            // reset the noAttribute flag if it is already set cause that will be ignored
if any other AT is requested
-            if ( noAttributes && ( allUserAttributes || allOperationalAttributes
|| ( !returningAttributes.isEmpty() ) ) )
-            {
-                noAttributes = false;
-            }
-            
-            if ( attributesString.size() > 0 )
-            {
-                returningAttributesString = attributesString.toArray( ArrayUtils.EMPTY_STRING_ARRAY
);
-            }
-            else if ( nbInvalid > 0 )
-            {
-                returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
-            }
-            else
-            {
-                returningAttributesString = new String[]{ SchemaConstants.ALL_USER_ATTRIBUTES
};
-                allUserAttributes = true;
-            }
-        }
+        super( session, dn, returningAttributes );
     }
 
 
     /**
-     * @see Object#toString()
+     * @return The alias dereferencing mode
      */
-    public String toString()
-    {
-        return "ListOperationContext with Dn '" + getDn().getName() + "'";
-    }
-
-
     public AliasDerefMode getAliasDerefMode()
     {
         return aliasDerefMode;
     }
 
 
+    /**
+     * Set the Alias dereferencing mode
+     * @param aliasDerefMode Th erequested mode
+     */
     public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
     {
         this.aliasDerefMode = aliasDerefMode;
@@ -280,102 +166,6 @@ public abstract class SearchingOperation
 
 
     /**
-     * @param allOperationalAttributes the allOperationalAttributes to set
-     */
-    public void setAllOperationalAttributes( boolean allOperationalAttribute )
-    {
-        this.allOperationalAttributes = allOperationalAttribute;
-    }
-
-
-    /**
-     * @return the allOperationalAttributes
-     */
-    public boolean isAllOperationalAttributes()
-    {
-        return allOperationalAttributes;
-    }
-
-
-    /**
-     * @param allUserAttributes the allUserAttributes to set
-     */
-    public void setAllUserAttributes( boolean allUserAttributes )
-    {
-        this.allUserAttributes = allUserAttributes;
-    }
-
-
-    /**
-     * @return the allUserAttributes
-     */
-    public boolean isAllUserAttributes()
-    {
-        return allUserAttributes;
-    }
-
-
-    /**
-     * @param noAttributes the noAttributes to set
-     */
-    public void setNoAttributes( boolean noAttributes )
-    {
-        this.noAttributes = noAttributes;
-    }
-
-
-    /**
-     * @return the noAttributes
-     */
-    public boolean isNoAttributes()
-    {
-        return noAttributes;
-    }
-
-
-    /**
-     * @return true, if attribute descriptions alone need to be returned
-     */
-    public boolean isTypesOnly()
-    {
-        return typesOnly;
-    }
-
-
-    public void setTypesOnly( boolean typesOnly )
-    {
-        this.typesOnly = typesOnly;
-    }
-
-
-    /**
-     * @param returningAttributes the returningAttributes to set
-     */
-    public void setReturningAttributes( Set<AttributeTypeOptions> returningAttributes
)
-    {
-        this.returningAttributes = returningAttributes;
-    }
-
-
-    /**
-     * @return the returningAttributes
-     */
-    public Set<AttributeTypeOptions> getReturningAttributes()
-    {
-        return returningAttributes;
-    }
-
-
-    /**
-     * @return the returningAttributesString
-     */
-    public String[] getReturningAttributesString()
-    {
-        return returningAttributesString;
-    }
-
-
-    /**
      * @param abandoned the abandoned to set
      */
     public void setAbandoned( boolean abandoned )
@@ -391,4 +181,13 @@ public abstract class SearchingOperation
     {
         return abandoned;
     }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return "SearchingOperationContext with Dn '" + getDn().getName() + "'";
+    }
 }



Mime
View raw message