View Javadoc

1   /*
2    * Copyright 2002-2005 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.ldaptemplate.support.filter;
18  
19  /***
20   * A filter for a logical AND. E.g.:
21   * 
22   * <pre>
23   *     AndFilter filter = new AndFilter();
24   *     filter.and(new EqualsFilter(&quot;objectclass&quot;, &quot;person&quot;);
25   *     filter.and(new EqualsFilter(&quot;cn&quot;, &quot;Some CN&quot;);
26   *     System.out.println(filter.ecode());    
27   * </pre>
28   * 
29   * would result in: <code>(&amp;(objectclass=person)(cn=Some CN))</code>
30   * 
31   * @see net.sf.ldaptemplate.support.filter.EqualsFilter
32   * @author Adam Skogman
33   * @author Mattias Arthursson
34   */
35  public class AndFilter extends BinaryLogicalFilter {
36  
37      private static final String AMPERSAND = "&";
38  
39      /*
40       * (non-Javadoc)
41       * 
42       * @see net.sf.ldaptemplate.support.filter.BinaryLogicalFilter#getLogicalOperator()
43       */
44      protected String getLogicalOperator() {
45          return AMPERSAND;
46      }
47  
48      /***
49       * Add a query to the and expression
50       * 
51       * @param query
52       *            The query to and with the rest of the and:ed queries.
53       * @return This LdapAndQuery
54       */
55      public AndFilter and(Filter query) {
56          queryList.add(query);
57          return this;
58      }
59  }