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 * <li> 037 * <ul> 038 * <li>Visitation rejection with canVisit() and/or getOrder()</li> 039 * <li>Recursive visitation ordering with isPrefix()</li> 040 * <li>Child visitation ordering with getOrder()</li> 041 * </ul> 042 * </li> 043 * </ul> 044 * 045 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 046 */ 047public interface FilterVisitor 048{ 049 /** 050 * Visits a filter expression AST using a specific visitation order. 051 * 052 * @param node the node to visit 053 * @return node the resulting modified node 054 */ 055 Object visit( ExprNode node ); 056 057 058 /** 059 * Checks to see if a node can be visited. 060 * 061 * @param node the node to be visited 062 * @return whether or node the node should be visited 063 */ 064 boolean canVisit( ExprNode node ); 065 066 067 /** 068 * Determines whether the visitation order is prefix or postfix. 069 * 070 * @return true if the visitation is in prefix order, false otherwise. 071 */ 072 boolean isPrefix(); 073 074 075 /** 076 * Get the array of children to visit sequentially to determine the order of 077 * child visitations. Some children may not be returned at all if canVisit() 078 * returns false on them. 079 * 080 * @param node the parent branch node 081 * @param children the child node array 082 * @return the new reordered array of children 083 */ 084 List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); 085}