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.api.ldap.model.filter;
21  
22  
23  import java.util.List;
24  
25  
26  /**
27   * Filter expression tree node visitor interface. Note that this is a variation
28   * of the extrinsic visitor variation. It has the following advantages over the
29   * standard visitor pattern:
30   * <ul>
31   *   <li>Visitor takes responsibility that a visitor can visit a node</li>
32   *   <li>Each visitor knows which types of concrete classes it can visit</li>
33   *   <li>New visitors can be created without changing the node class</li>
34   *   <li>New node classes can be added without having to change old visitors</li>
35   *   <li>Visitation order can be controled in every respect:</li>
36   *   <li>
37   *     <ul>
38   *       <li>Visitation rejection with canVisit() and/or getOrder()</li>
39   *       <li>Recursive visitation ordering with isPrefix()</li>
40   *       <li>Child visitation ordering with getOrder()</li>
41   *     </ul>
42   *   </li>
43   * </ul>
44   * 
45   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
46   */
47  public interface FilterVisitor
48  {
49      /**
50       * Visits a filter expression AST using a specific visitation order.
51       * 
52       * @param node the node to visit
53       * @return node the resulting modified node
54       */
55      Object visit( ExprNode node );
56  
57  
58      /**
59       * Checks to see if a node can be visited.
60       * 
61       * @param node the node to be visited
62       * @return whether or node the node should be visited
63       */
64      boolean canVisit( ExprNode node );
65  
66  
67      /**
68       * Determines whether the visitation order is prefix or postfix.
69       * 
70       * @return true if the visitation is in prefix order, false otherwise.
71       */
72      boolean isPrefix();
73  
74  
75      /**
76       * Get the array of children to visit sequentially to determine the order of
77       * child visitations. Some children may not be returned at all if canVisit()
78       * returns false on them.
79       * 
80       * @param node the parent branch node
81       * @param children the child node array
82       * @return the new reordered array of children
83       */
84      List<ExprNode> getOrder( BranchNode node, List<ExprNode> children );
85  }