org.apache.directory.shared.ldap.filter
Class BranchNormalizedVisitor

java.lang.Object
  extended byorg.apache.directory.shared.ldap.filter.BranchNormalizedVisitor
All Implemented Interfaces:
FilterVisitor

public class BranchNormalizedVisitor
extends java.lang.Object
implements FilterVisitor

Visitor which traverses a filter tree while normalizing the branch node order. Filter expressions can change the order of expressions in branch nodes without effecting the logical meaning of the expression. This visitor orders the children of expression tree branch nodes consistantly. It is really useful for comparing expression trees which may be altered for performance or altered because of codec idiosyncracies: for example the SNACC4J codec uses a hashmap to store expressions in a sequence which rearranges the order of children based on object hashcodes. We need this visitor to remove such inconsitancies in order hence normalizing the branch node's child order.

Version:
$Rev: 379008 $
Author:
Apache Directory Project

Constructor Summary
BranchNormalizedVisitor()
           
 
Method Summary
 boolean canVisit(ExprNode node)
          Checks to see if a node can be visited.
static java.lang.String getNormalizedFilter(ExprNode filter)
          Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.
static java.lang.String getNormalizedFilter(java.lang.String filter)
          Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.
 java.util.ArrayList getOrder(BranchNode node, java.util.ArrayList children)
          Get the array of children to visit sequentially to determine the order of child visitations.
 boolean isPrefix()
          Determines whether the visitation order is prefix or postfix.
 void visit(ExprNode node)
          Visits a filter expression AST using a specific visitation order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BranchNormalizedVisitor

public BranchNormalizedVisitor()
Method Detail

visit

public void visit(ExprNode node)
Description copied from interface: FilterVisitor
Visits a filter expression AST using a specific visitation order.

Specified by:
visit in interface FilterVisitor
Parameters:
node - the node to visit

canVisit

public boolean canVisit(ExprNode node)
Description copied from interface: FilterVisitor
Checks to see if a node can be visited.

Specified by:
canVisit in interface FilterVisitor
Parameters:
node - the node to be visited
Returns:
whether or node the node should be visited

isPrefix

public boolean isPrefix()
Description copied from interface: FilterVisitor
Determines whether the visitation order is prefix or postfix.

Specified by:
isPrefix in interface FilterVisitor
Returns:
true if the visitation is in prefix order, false otherwise.

getOrder

public java.util.ArrayList getOrder(BranchNode node,
                                    java.util.ArrayList children)
Description copied from interface: FilterVisitor
Get the array of children to visit sequentially to determine the order of child visitations. Some children may not be returned at all if canVisit() returns false on them.

Specified by:
getOrder in interface FilterVisitor
Parameters:
node - the parent branch node
children - the child node array
Returns:
the new reordered array of children

getNormalizedFilter

public static java.lang.String getNormalizedFilter(java.lang.String filter)
                                            throws java.io.IOException,
                                                   java.text.ParseException
Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.

Parameters:
filter - the filter to normalize
Returns:
the normalized version of the filter
Throws:
java.io.IOException - if filter parser cannot be created
java.text.ParseException - if the filter is malformed

getNormalizedFilter

public static java.lang.String getNormalizedFilter(ExprNode filter)
Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.

Parameters:
filter - the filter to normalize
Returns:
the normalized String version of the filter


Copyright © 2003-2006 . All Rights Reserved.