Package org.apache.directory.shared.ldap.model.filter

Examples of org.apache.directory.shared.ldap.model.filter.BranchNode


    }


    public Object visit( ExprNode node )
    {
        BranchNode bnode = ( BranchNode ) node;

        // --------------------------------------------------------------------
        // we want to check each child leaf node to see if it must be expanded
        // children that are branch nodes are recursively visited
        // --------------------------------------------------------------------

        final List<ExprNode> children = bnode.getChildren();
        int childNumber = 0;

        for ( ExprNode child : children )
        {
            if ( child instanceof LeafNode )
            {
                LeafNode leaf = ( LeafNode ) child;

                try
                {
                    if ( schemaManager.getAttributeTypeRegistry().hasDescendants( leaf.getAttributeType() ) )
                    {
                        // create a new OR node to hold all descendent forms
                        // add to this node the generalized leaf node and
                        // replace the old leaf with the new OR branch node
                        BranchNode orNode = new OrNode();
                        orNode.getChildren().add( leaf );
                        children.set( childNumber++, orNode );

                        // iterate through descendants adding them to the orNode
                        Iterator<AttributeType> descendants = schemaManager.getAttributeTypeRegistry().descendants( leaf.getAttributeType() );

                        while ( descendants.hasNext() )
                        {
                            LeafNode newLeaf = null;
                            AttributeType descendant = descendants.next();

                            if ( leaf instanceof PresenceNode )
                            {
                                newLeaf = new PresenceNode( descendant );
                            }
                            else if ( leaf instanceof ApproximateNode )
                            {
                                ApproximateNode approximateNode = ( ApproximateNode ) leaf;

                                newLeaf = new ApproximateNode( descendant, approximateNode.getValue() );
                            }
                            else if ( leaf instanceof EqualityNode )
                            {
                                EqualityNode equalityNode = (EqualityNode) leaf;

                                newLeaf = new EqualityNode( descendant, equalityNode.getValue() );
                            }
                            else if ( leaf instanceof GreaterEqNode )
                            {
                                GreaterEqNode greaterEqNode = ( GreaterEqNode ) leaf;

                                newLeaf = new GreaterEqNode( descendant, greaterEqNode.getValue() );
                            }
                            else if ( leaf instanceof LessEqNode )
                            {
                                LessEqNode lessEqNode = ( LessEqNode ) leaf;

                                newLeaf = new LessEqNode( descendant, lessEqNode.getValue() );
                            }
                            else if ( leaf instanceof ExtensibleNode )
                            {
                                ExtensibleNode extensibleNode = ( ExtensibleNode ) leaf;
                                newLeaf = new ExtensibleNode( descendant, extensibleNode.getValue(),
                                    extensibleNode.getMatchingRuleId(), extensibleNode.hasDnAttributes() );
                            }
                            else if ( leaf instanceof SubstringNode )
                            {
                                SubstringNode substringNode = ( SubstringNode ) leaf;
                                newLeaf = new SubstringNode( descendant, substringNode.getInitial(),
                                    substringNode.getFinal() );
                            }
                            else
                            {
                                throw new IllegalStateException( I18n.err( I18n.ERR_260, leaf ) );
                            }

                            orNode.addNode( newLeaf );
                        }
                    }
                }
                catch ( LdapException e )
                {
View Full Code Here


            }
        }
        else
        {
            // Manage AND and OR nodes.
            BranchNode branchNode = node;
            List<ExprNode> children = node.getChildren();

            // For AND and OR, we may have more than one children.
            // We may have to remove some of them, so let's create
            // a new handler to store the correct nodes.
            List<ExprNode> newChildren = new ArrayList<ExprNode>( children.size() );

            // Now, iterate through all the children
            for ( int i = 0; i < children.size(); i++ )
            {
                ExprNode child = children.get( i );

                ExprNode result = ( ExprNode ) visit( child );

                if ( result != null )
                {
                    // As the node is correct, add it to the children
                    // list.
                    newChildren.add( result );
                }
            }

            if ( ( branchNode instanceof AndNode ) && ( newChildren.size() != children.size() ) )
            {
                return null;
            }

            if ( newChildren.size() == 0 )
            {
                // No more children, return null
                return null;
            }
            else if ( newChildren.size() == 1 )
            {
                // As we only have one child, return it
                // to the caller.
                return newChildren.get( 0 );
            }
            else
            {
                branchNode.setChildren( newChildren );
            }
        }

        return node;
    }
View Full Code Here

        for ( String suffix:suffixes )
        {
            // moving the filter creation to inside loop to fix DIRSERVER-1121
            // didn't use clone() cause it is creating List objects, which IMO is not worth calling
            // in this initialization phase
            BranchNode filter = new OrNode();
            filter.addNode( new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
                SchemaConstants.GROUP_OF_NAMES_OC ) ) );
            filter.addNode( new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
                SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC ) ) );

            Dn baseDn = dnFactory.create( suffix );
            SearchControls ctls = new SearchControls();
            ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
View Full Code Here

            if ( exprNode.isLeaf() )
            {
                return;
            }

            BranchNode branch = ( BranchNode ) exprNode;
           
            for ( ExprNode child:branch.getChildren() )
            {
                children.add( new ASTNode( this, child ) );
            }
        }
        catch ( Exception e )
View Full Code Here

        if ( node.isLeaf() )
        {
            return leafEvaluator.evaluate( ( SimpleNode ) node, objectClasses );
        }

        BranchNode bnode = (BranchNode) node;

        if ( node instanceof OrNode )
        {
            for ( ExprNode child:bnode.getChildren() )
            {
                if ( evaluate( child, objectClasses ) )
                {
                    return true;
                }
            }

            return false;
        }
        else if ( node instanceof AndNode )
        {
            for ( ExprNode child:bnode.getChildren() )
            {
                if ( !evaluate( child, objectClasses ) )
                {
                    return false;
                }
            }

            return true;
           
        }
        else if ( node instanceof NotNode )
        {
            if ( null != bnode.getFirstChild() )
            {
                return !evaluate( bnode.getFirstChild(), objectClasses );
            }

            throw new IllegalArgumentException( I18n.err( I18n.ERR_243, node ) );
           
        }
View Full Code Here

        if ( filter != null )
        {
            // Transform OR, AND or NOT leaves
            if ( filter instanceof ConnectorFilter)
            {
                BranchNode branch = null;

                if ( filter instanceof AndFilter)
                {
                    branch = new AndNode();
                }
                else if ( filter instanceof OrFilter)
                {
                    branch = new OrNode();
                }
                else if ( filter instanceof NotFilter)
                {
                    branch = new NotNode();
                }

                List<Filter> filtersSet = ( ( ConnectorFilter ) filter ).getFilterSet();

                // Loop on all AND/OR children
                if ( filtersSet != null )
                {
                    for ( Filter node : filtersSet )
                    {
                        branch.addNode( transform( node ) );
                    }
                }

                return branch;
            }
View Full Code Here

        if ( filter != null )
        {
            // Transform OR, AND or NOT leaves
            if ( filter instanceof ConnectorFilter )
            {
                BranchNode branch = null;

                if ( filter instanceof AndFilter )
                {
                    branch = new AndNode();
                }
                else if ( filter instanceof OrFilter )
                {
                    branch = new OrNode();
                }
                else if ( filter instanceof NotFilter )
                {
                    branch = new NotNode();
                }

                List<Filter> filtersSet = ( ( ConnectorFilter ) filter ).getFilterSet();

                // Loop on all AND/OR children
                if ( filtersSet != null )
                {
                    for ( Filter node : filtersSet )
                    {
                        branch.addNode( transform( node ) );
                    }
                }

                return branch;
            }
View Full Code Here

        if ( filter != null )
        {
            // Transform OR, AND or NOT leaves
            if ( filter instanceof ConnectorFilter )
            {
                BranchNode branch = null;

                if ( filter instanceof AndFilter )
                {
                    branch = new AndNode();
                }
                else if ( filter instanceof OrFilter )
                {
                    branch = new OrNode();
                }
                else if ( filter instanceof NotFilter )
                {
                    branch = new NotNode();
                }

                List<Filter> filtersSet = ( ( ConnectorFilter ) filter ).getFilterSet();

                // Loop on all AND/OR children
                if ( filtersSet != null )
                {
                    for ( Filter node : filtersSet )
                    {
                        branch.addNode( transform( node ) );
                    }
                }

                return branch;
            }
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.directory.server.core.schema.SchemaPartitionDao#hasMatchingRule(java.lang.String)
     */
    public boolean hasMatchingRule( String oid ) throws Exception
    {
        BranchNode filter = new AndNode();
        filter.addNode( new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
            MetaSchemaConstants.META_MATCHING_RULE_OC ) ) );

        if ( NUMERIC_OID_CHECKER.isValidSyntax( oid ) )
        {
            filter.addNode( new EqualityNode<String>( M_OID_AT, new StringValue( oid ) ) );
        }
        else
        {
            filter.addNode( new EqualityNode<String>( M_NAME_AT, new StringValue( oid.toLowerCase() ) ) );
        }

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        EntryFilteringCursor cursor = null;
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.directory.server.core.schema.SchemaPartitionDao#hasAttributeType(java.lang.String)
     */
    public boolean hasAttributeType( String oid ) throws Exception
    {
        BranchNode filter = new AndNode();
        filter.addNode( new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
            MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC ) ) );

        if ( NUMERIC_OID_CHECKER.isValidSyntax( oid ) )
        {
            filter.addNode( new EqualityNode<String>( M_OID_AT, new StringValue( oid ) ) );
        }
        else
        {
            filter.addNode( new EqualityNode<String>( M_NAME_AT, new StringValue( oid.toLowerCase() ) ) );
        }

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
        EntryFilteringCursor cursor = null;
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.filter.BranchNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.