View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.server.xdbm.search;
21  
22  
23  import java.util.Set;
24  
25  import org.apache.directory.api.ldap.model.cursor.SetCursor;
26  import org.apache.directory.api.ldap.model.filter.ExprNode;
27  import org.apache.directory.api.ldap.model.message.AliasDerefMode;
28  import org.apache.directory.api.ldap.model.schema.SchemaManager;
29  import org.apache.directory.server.xdbm.IndexEntry;
30  
31  
32  /**
33   * A class containing the result of a search :
34   * <ul>
35   * <li>A set of candidate UUIDs</li>
36   * <li>A set of aliased entry if we have any</li>
37   * <li>A flag telling if we are dereferencing aliases or not</li>
38   * <li>A hierarchy of evaluators to use to validate the candidates</li>
39   * </ul>
40   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
41   */
42  public class PartitionSearchResult
43  {
44      /** The set of candidate UUIDs selected by the search */
45      private SetCursor<IndexEntry<String, String>> resultSet;
46  
47      /** The set of candidate UUIDs */
48      private Set<String> candidateSet;
49  
50      /** The flag indicating if we are dereferencing the aliases. Default to Never. */
51      private AliasDerefMode aliasDerefMode = AliasDerefMode.NEVER_DEREF_ALIASES;
52  
53      /** The evaluator to validate the candidates */
54      private Evaluator<? extends ExprNode> evaluator;
55  
56      /** The SchemaManager */
57      private SchemaManager schemaManager;
58  
59  
60      /**
61       * Create a PartitionSearchResult instance
62       * 
63       * @param schemaManager The SchemaManager instance
64       */
65      public PartitionSearchResult( SchemaManager schemaManager )
66      {
67          this.schemaManager = schemaManager;
68      }
69  
70  
71      /**
72       * @return the resultSet
73       */
74      public SetCursor<IndexEntry<String, String>> getResultSet()
75      {
76          return resultSet;
77      }
78  
79  
80      /**
81       * @param set the resultSet to set
82       */
83      public void setResultSet( Set<IndexEntry<String, String>> set )
84      {
85          resultSet = new SetCursor<>( set );
86      }
87  
88  
89      /**
90       * @return the candidateSet
91       */
92      public Set<String> getCandidateSet()
93      {
94          return candidateSet;
95      }
96  
97  
98      /**
99       * @param set the candidateSet to set
100      */
101     public void setCandidateSet( Set<String> set )
102     {
103         candidateSet = set;
104     }
105 
106 
107     /**
108      * @return the evaluator
109      */
110     public Evaluator<? extends ExprNode> getEvaluator()
111     {
112         return evaluator;
113     }
114 
115 
116     /**
117      * @param evaluator the evaluator to set
118      */
119     public void setEvaluator( Evaluator<? extends ExprNode> evaluator )
120     {
121         this.evaluator = evaluator;
122     }
123 
124 
125     /**
126      * @param aliasDerefMode the aliasDerefMode to set
127      */
128     public void setAliasDerefMode( AliasDerefMode aliasDerefMode )
129     {
130         this.aliasDerefMode = aliasDerefMode;
131     }
132 
133 
134     /**
135      * @return True if the alias is never dereferenced
136      */
137     public boolean isNeverDeref()
138     {
139         return aliasDerefMode == AliasDerefMode.NEVER_DEREF_ALIASES;
140     }
141 
142 
143     /**
144      * @return True if the alias is always dereferenced
145      */
146     public boolean isDerefAlways()
147     {
148         return aliasDerefMode == AliasDerefMode.DEREF_ALWAYS;
149     }
150 
151 
152     /**
153      * @return True if the alias is dereferenced while searching
154      */
155     public boolean isDerefInSearching()
156     {
157         return aliasDerefMode == AliasDerefMode.DEREF_IN_SEARCHING;
158     }
159 
160 
161     /**
162      * @return True if the alias is dereferenced while finding
163      */
164     public boolean isDerefFinding()
165     {
166         return aliasDerefMode == AliasDerefMode.DEREF_FINDING_BASE_OBJ;
167     }
168 
169 
170     /**
171      * @return the schemaManager
172      */
173     public SchemaManager getSchemaManager()
174     {
175         return schemaManager;
176     }
177 
178 
179     /**
180      * @param schemaManager the schemaManager to set
181      */
182     public void setSchemaManager( SchemaManager schemaManager )
183     {
184         this.schemaManager = schemaManager;
185     }
186 
187 
188     /**
189      * @see Object#toString()
190      */
191     public String toString()
192     {
193         StringBuilder sb = new StringBuilder();
194 
195         sb.append( "Search result : \n" );
196         sb.append( "Alias : " ).append( aliasDerefMode ).append( "\n" );
197         sb.append( "Evaluator : " ).append( evaluator ).append( "\n" );
198 
199         if ( resultSet == null )
200         {
201             sb.append( "No UUID found" );
202         }
203         else
204         {
205             sb.append( '{' );
206             boolean isFirst = true;
207 
208             try
209             {
210                 while ( resultSet.next() )
211                 {
212                     if ( isFirst )
213                     {
214                         isFirst = false;
215                     }
216                     else
217                     {
218                         sb.append( ", " );
219                     }
220 
221                     sb.append( resultSet.get().getId() );
222                 }
223 
224                 resultSet.beforeFirst();
225             }
226             catch ( Exception e )
227             {
228                 // Nothing we can do...
229             }
230 
231             sb.append( '}' );
232         }
233 
234         return sb.toString();
235     }
236 }