directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r328266 - /directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java
Date Tue, 25 Oct 2005 06:02:13 GMT
Author: akarasulu
Date: Mon Oct 24 23:02:10 2005
New Revision: 328266

URL: http://svn.apache.org/viewcvs?rev=328266&view=rev
Log:
changes ...

 o added ability to invoke naming manager to populate the object in a 
   SearchResult using the object factories in the env of the context
 o each prefetched entry has its object generated for it if a valid 
   object factory exists 
 o this fixes DIREVE-279 here: http://issues.apache.org/jira/browse/DIREVE-279


Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java?rev=328266&r1=328265&r2=328266&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/enumeration/SearchResultFilteringEnumeration.java
Mon Oct 24 23:02:10 2005
@@ -20,16 +20,24 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Hashtable;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.DirectoryManager;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
 
 //import org.slf4j.Logger;
 //import org.slf4j.LoggerFactory;
 import org.apache.ldap.server.invocation.Invocation;
+import org.apache.ldap.common.name.LdapName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -42,8 +50,9 @@
  */
 public class SearchResultFilteringEnumeration implements NamingEnumeration
 {
-//    private static final Logger log = LoggerFactory.getLogger( SearchResultFilteringEnumeration.class
);
-//
+    /** the logger used by this class */
+    private static final Logger log = LoggerFactory.getLogger( SearchResultFilteringEnumeration.class
);
+
     /** the list of filters to be applied */
     private final List filters;
     /** the underlying decorated enumeration */
@@ -57,6 +66,8 @@
     private final SearchControls searchControls;
     /** the Invocation that representing the search creating this enumeration */
     private final Invocation invocation;
+    /** whether or not the caller context has object factories which need to be applied to
the results */
+    private final boolean applyObjectFactories;
 
 
     // ------------------------------------------------------------------------
@@ -84,6 +95,7 @@
         this.filters = new ArrayList();
         this.filters.add( filter );
         this.decorated = decorated;
+        this.applyObjectFactories = invocation.getCaller().getEnvironment().containsKey(
Context.OBJECT_FACTORIES );
 
         if ( ! decorated.hasMore() )
         {
@@ -115,6 +127,7 @@
         this.filters = new ArrayList();
         this.filters.addAll( filters );
         this.decorated = decorated;
+        this.applyObjectFactories = invocation.getCaller().getEnvironment().containsKey(
Context.OBJECT_FACTORIES );
 
         if ( ! decorated.hasMore() )
         {
@@ -228,6 +241,34 @@
     // ------------------------------------------------------------------------
 
 
+    private void applyObjectFactories( SearchResult result ) throws NamingException
+    {
+        // if already populated or no factories are available just return
+        if ( result.getObject() != null || ! applyObjectFactories )
+        {
+            return;
+        }
+
+        DirContext ctx = ( DirContext ) invocation.getCaller();
+        Hashtable env = ctx.getEnvironment();
+        Attributes attrs = result.getAttributes();
+        Name name = new LdapName( result.getName() );
+        try
+        {
+            Object obj = DirectoryManager.getObjectInstance( null, name, ctx, env, attrs
);
+            result.setObject( obj );
+        }
+        catch ( Exception e )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "ObjectFactories threw exception while attempting to generate an
object for " );
+            buf.append( result.getName() );
+            buf.append( ". Call on SearchResult.getObject() will return null." );
+            log.warn( buf.toString(), e );
+        }
+    }
+
+
     /**
      * Keeps getting results from the underlying decorated filter and applying
      * the filters until a result is accepted by all and set as the prefetced
@@ -252,6 +293,7 @@
             if ( filters.isEmpty() )
             {
                 this.prefetched = tmp;
+                applyObjectFactories( this.prefetched );
                 return;
             }
             else if ( filters.size() == 1 )
@@ -261,6 +303,7 @@
                 if ( accepted )
                 {
                     this.prefetched = tmp;
+                    applyObjectFactories( this.prefetched );
                     return;
                 }
 
@@ -285,6 +328,7 @@
              * on the following call to the next() or nextElement() methods
              */
             this.prefetched = tmp;
+            applyObjectFactories( this.prefetched );
             return;
         }
 



Mime
View raw message