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.core.interceptor.context;
21  
22  
23  import java.util.Set;
24  
25  import javax.naming.directory.SearchControls;
26  
27  import org.apache.directory.server.core.CoreSession;
28  import org.apache.directory.shared.ldap.filter.ExprNode;
29  import org.apache.directory.shared.ldap.filter.SearchScope;
30  import org.apache.directory.shared.ldap.message.AliasDerefMode;
31  import org.apache.directory.shared.ldap.message.ManageDsaITControl;
32  import org.apache.directory.shared.ldap.message.MessageTypeEnum;
33  import org.apache.directory.shared.ldap.message.SearchRequest;
34  import org.apache.directory.shared.ldap.name.LdapDN;
35  import org.apache.directory.shared.ldap.schema.AttributeTypeOptions;
36  
37  
38  /**
39   * A Search context used for Interceptors. It contains all the informations
40   * needed for the search operation, and used by all the interceptors
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   * @version $Rev$, $Date$
44   */
45  public class SearchOperationContext extends SearchingOperationContext
46  {
47      /** The filter */
48      private ExprNode filter;
49  
50  
51      /**
52       * Creates a new instance of SearchOperationContext.
53       */
54      public SearchOperationContext( CoreSession session )
55      {
56          super( session );
57      }
58  
59  
60      /**
61       * Creates a new instance of SearchOperationContext.
62       * @throws Exception 
63       */
64      public SearchOperationContext( CoreSession session, SearchRequest searchRequest ) throws Exception
65      {
66          super( session );
67          
68          this.dn = searchRequest.getBase();
69          this.filter = searchRequest.getFilter();
70          this.abandoned = searchRequest.isAbandoned();
71          this.aliasDerefMode = searchRequest.getDerefAliases();
72          
73          this.requestControls = searchRequest.getControls();
74          this.scope = searchRequest.getScope();
75          this.sizeLimit = searchRequest.getSizeLimit();
76          this.timeLimit = searchRequest.getTimeLimit();
77          this.noAttributes = searchRequest.getTypesOnly();
78          setReturningAttributes( searchRequest.getAttributes() );
79      }
80  
81  
82      /**
83       * Creates a new instance of SearchOperationContext.
84       * 
85       * @param aliasDerefMode the alias dereferencing mode
86       * @param dn the dn of the search base
87       * @param filter the filter AST to use for the search
88       * @param searchControls the search controls
89       */
90      public SearchOperationContext( CoreSession session, LdapDN dn, AliasDerefMode aliasDerefMode, ExprNode filter,
91                                     SearchControls searchControls ) throws Exception
92      {
93          super( session, dn, aliasDerefMode, searchControls );
94          this.filter = filter;
95      }
96  
97  
98      /**
99       * Creates a new instance of SearchOperationContext.
100      * 
101      * @param session the session this operation is associated with
102      * @param dn the search base
103      * @param scope the search scope
104      * @param filter the filter AST to use for the search
105      * @param aliasDerefMode the alias dereferencing mode
106      * @param returningAttributes the attributes to return
107      */
108     public SearchOperationContext( CoreSession session, LdapDN dn, SearchScope scope,
109         ExprNode filter, AliasDerefMode aliasDerefMode, Set<AttributeTypeOptions> returningAttributes )
110     {
111         super( session, dn, aliasDerefMode, returningAttributes );
112         super.setScope( scope );
113         this.filter = filter;
114     }
115 
116 
117     /**
118      * Checks whether or not the ManageDsaITControl is present.  If not 
119      * present then the filter is modified to force the return of all referral
120      * entries regardless of whether or not the filter matches the referral
121      * entry.
122      */
123     public boolean hasManageDsaItControl()
124     {
125         return super.hasRequestControl( ManageDsaITControl.CONTROL_OID );
126     }
127     
128     
129     /**
130      * @return The filter
131      */
132     public ExprNode getFilter()
133     {
134         return filter;
135     }
136 
137 
138     /**
139      * Set the filter into the context.
140      *
141      * @param filter The filter to set
142      */
143     public void setFilter( ExprNode filter )
144     {
145         this.filter = filter;
146     }
147 
148 
149     /**
150      * @see Object#toString()
151      */
152     public String toString()
153     {
154         return "SearchContext for DN '" + getDn().getUpName() + "', filter :'"
155         + filter + "'"; 
156     }
157 
158 
159     /**
160      * @return the operation name
161      */
162     public String getName()
163     {
164         return MessageTypeEnum.SEARCH_REQUEST.name();
165     }
166 }