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 */
020 package org.apache.directory.shared.ldap.filter;
021
022
023 import 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 * @version $Revision: 664290 $
045 */
046 public interface FilterVisitor
047 {
048 /**
049 * Visits a filter expression AST using a specific visitation order.
050 *
051 * @param node the node to visit
052 * @return node the resulting modified node
053 */
054 Object visit( ExprNode node );
055
056
057 /**
058 * Checks to see if a node can be visited.
059 *
060 * @param node the node to be visited
061 * @return whether or node the node should be visited
062 */
063 boolean canVisit( ExprNode node );
064
065
066 /**
067 * Determines whether the visitation order is prefix or postfix.
068 *
069 * @return true if the visitation is in prefix order, false otherwise.
070 */
071 boolean isPrefix();
072
073
074 /**
075 * Get the array of children to visit sequentially to determine the order of
076 * child visitations. Some children may not be returned at all if canVisit()
077 * returns false on them.
078 *
079 * @param node the parent branch node
080 * @param children the child node array
081 * @return the new reordered array of children
082 */
083 List<ExprNode> getOrder( BranchNode node, List<ExprNode> children );
084 }