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 * <ul> 37 * <li>Visitation rejection with canVisit() and/or getOrder()</li> 38 * <li>Recursive visitation ordering with isPrefix()</li> 39 * <li>Child visitation ordering with getOrder()</li> 40 * </ul> 41 * </ul> 42 * 43 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 44 */ 45 public interface FilterVisitor 46 { 47 /** 48 * Visits a filter expression AST using a specific visitation order. 49 * 50 * @param node the node to visit 51 * @return node the resulting modified node 52 */ 53 Object visit( ExprNode node ); 54 55 56 /** 57 * Checks to see if a node can be visited. 58 * 59 * @param node the node to be visited 60 * @return whether or node the node should be visited 61 */ 62 boolean canVisit( ExprNode node ); 63 64 65 /** 66 * Determines whether the visitation order is prefix or postfix. 67 * 68 * @return true if the visitation is in prefix order, false otherwise. 69 */ 70 boolean isPrefix(); 71 72 73 /** 74 * Get the array of children to visit sequentially to determine the order of 75 * child visitations. Some children may not be returned at all if canVisit() 76 * returns false on them. 77 * 78 * @param node the parent branch node 79 * @param children the child node array 80 * @return the new reordered array of children 81 */ 82 List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); 83 }