if ( !filter.isLeaf() ) { expVisitor.visit( filter ); } else { LeafNode leaf = ( LeafNode ) filter; if ( attributeRegistry.hasDescendants( leaf.getAttribute() ) ) {   BranchNode bnode = new BranchNode( BranchNode.OR ); bnode.getChildren().add( filter ); filter = bnode;   Iterator descendants = attributeRegistry.descendants( leaf.getAttribute() );  while ( descendants.hasNext() ) { LeafNode newLeaf = null; AttributeType descendant = ( AttributeType ) descendants.next();  switch( leaf.getAssertionType() ) { case( LeafNode.EXTENSIBLE ): ExtensibleNode extensibleNode = ( ExtensibleNode ) leaf; newLeaf = new ExtensibleNode( descendant.getOid(), extensibleNode.getValue(), extensibleNode.getMatchingRuleId(), extensibleNode.dnAttributes() ); break; case( LeafNode.PRESENCE ): newLeaf = new PresenceNode( descendant.getOid() ); break; case( LeafNode.SUBSTRING ): SubstringNode substringNode = ( SubstringNode ) leaf; newLeaf = new SubstringNode( descendant.getOid(), substringNode.getInitial(), substringNode.getFinal() ); break; case( LeafNode.APPROXIMATE ): case( LeafNode.EQUALITY ): case( LeafNode.GREATEREQ ): case( LeafNode.LESSEQ ): SimpleNode simpleNode = ( SimpleNode ) leaf; newLeaf = new SimpleNode( descendant.getOid(), simpleNode.getValue(), simpleNode.getAssertionType() ); break; default: throw new IllegalStateException( "Unknown assertion type: " + leaf.getAssertionType() ); }  bnode.getChildren().add( newLeaf ); } } }
    public NamingEnumeration search( NextInterceptor nextInterceptor, LdapDN base, Map env, ExprNode filter,        SearchControls searchCtls ) throws NamingException    {        base.normalize( attributeRegistry.getNormalizerMapping());        if ( filter.isLeaf() )        {            LeafNode ln = ( LeafNode ) filter;            if ( !attributeRegistry.hasAttributeType( ln.getAttribute() ) )            {                StringBuffer buf = new StringBuffer();                buf.append( "undefined filter based on undefined attributeType '" );                buf.append( ln.getAttribute() );                buf.append( "' not evaluted at all.  Returning empty enumeration." );                log.warn( buf.toString() );                return new EmptyEnumeration();            }        }        boolean isFailure = true;        while ( isFailure && ( filter != null ) )        {            try            {                if ( filter.isLeaf() )                {                    LeafNode ln = ( LeafNode ) filter;                    if ( !attributeRegistry.hasAttributeType( ln.getAttribute() ) )                    {                        StringBuffer buf = new StringBuffer();                        buf.append( "undefined filter based on undefined attributeType '" );                        buf.append( ln.getAttribute() );                        buf.append( "' not evaluted at all.  Returning empty enumeration." );                        log.warn( buf.toString() );                        return new EmptyEnumeration();                    }                }                filter.accept( visitor );                isFailure = false;            }            catch( UndefinedFilterAttributeException e )            {                isFailure = true;                if ( log.isWarnEnabled() )                {                    log.warn( "An undefined attribute was found within the supplied search filter.  " +                            "The node associated with the filter has been removed.", e.getCause() );                }                // we can only get here if the filter is a branch node with only leaves                // note that in this case the undefined node will not be removed.                BranchNode bnode = ( BranchNode ) filter;                if ( bnode.isNegation() )                {                    return new EmptyEnumeration();                }                                bnode.getChildren().remove( e.getUndefinedFilterNode() );                                if ( bnode.getOperator() == BranchNode.AND )                {                    return new EmptyEnumeration();                }                                if ( bnode.getChildren().size() < 2 )                {                    filter = bnode.getChild();                }            }        }        // check that after pruning we have valid branch node at the top        if ( !filter.isLeaf() )        {            BranchNode child = ( BranchNode ) filter;            // if the remaining filter branch node has no children return an empty enumeration            if ( child.getChildren().size() == 0 || child.get( "undefined" ) == Boolean.TRUE )            {                log.warn( "Undefined branchnode filter without child nodes not " +                        "evaluted at all.  Returning empty enumeration." );                return new EmptyEnumeration();            }            // now for AND & OR nodes with a single child left replace them with their child            if ( child.getChildren().size() == 1 && child.getOperator() != BranchNode.NOT )            {                filter = child.getChild();            }        }        return nextInterceptor.search( base, env, filter, searchCtls );    }