001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.model.filter; 021 022 023import java.util.List; 024 025 026/** 027 * Filter expression tree node visitor interface. Note that this is a variation 028 * of the extrinsic visitor variation. It has the following advantages over the 029 * standard visitor pattern: 030 * <ul> 031 * <li>Visitor takes responsibility that a visitor can visit a node</li> 032 * <li>Each visitor knows which types of concrete classes it can visit</li> 033 * <li>New visitors can be created without changing the node class</li> 034 * <li>New node classes can be added without having to change old visitors</li> 035 * <li>Visitation order can be controled in every respect:</li> 036 * <ul> 037 * <li>Visitation rejection with canVisit() and/or getOrder()</li> 038 * <li>Recursive visitation ordering with isPrefix()</li> 039 * <li>Child visitation ordering with getOrder()</li> 040 * </ul> 041 * </ul> 042 * 043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 044 */ 045public interface FilterVisitor 046{ 047 /** 048 * Visits a filter expression AST using a specific visitation order. 049 * 050 * @param node the node to visit 051 * @return node the resulting modified node 052 */ 053 Object visit( ExprNode node ); 054 055 056 /** 057 * Checks to see if a node can be visited. 058 * 059 * @param node the node to be visited 060 * @return whether or node the node should be visited 061 */ 062 boolean canVisit( ExprNode node ); 063 064 065 /** 066 * Determines whether the visitation order is prefix or postfix. 067 * 068 * @return true if the visitation is in prefix order, false otherwise. 069 */ 070 boolean isPrefix(); 071 072 073 /** 074 * Get the array of children to visit sequentially to determine the order of 075 * child visitations. Some children may not be returned at all if canVisit() 076 * returns false on them. 077 * 078 * @param node the parent branch node 079 * @param children the child node array 080 * @return the new reordered array of children 081 */ 082 List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); 083}