newLeaf = new SimpleNode( descendant.getOid(), simpleNode.getValue(), simpleNode.getAssertionType() );
if ( simpleNode.getValue() instanceof String ) { newLeaf = new SimpleNode( descendant.getOid(), ( String ) simpleNode.getValue(), simpleNode.getAssertionType() ); } else if ( simpleNode.getValue() instanceof byte[] ) { newLeaf = new SimpleNode( descendant.getOid(), ( byte[] ) simpleNode.getValue(), simpleNode.getAssertionType() ); } else { newLeaf = new SimpleNode( descendant.getOid(), simpleNode.getValue().toString(), simpleNode.getAssertionType() ); }
    public void 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 children = bnode.getChildren();        final int limit = children.size();        for ( int ii = 0; ii < limit; ii++ )        {            ExprNode child = ( ExprNode ) children.get( ii );            if ( child instanceof LeafNode )            {                LeafNode leaf = ( LeafNode ) child;                try                {                    if ( attrRegistry.hasDescendants( leaf.getAttribute() ) )                    {                        // 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 BranchNode( BranchNode.OR );                        orNode.getChildren().add( leaf );                        children.set( ii, orNode );                                                // iterate through descendants adding them to the orNode                        Iterator descendants = attrRegistry.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() );                            }                            orNode.addNode( newLeaf );                        }                    }                }                catch ( NamingException e )                {                    // log something here and throw a runtime excpetion                    e.printStackTrace();                    throw new RuntimeException( "Failed to expand node" );                }            }            else            {                visit( child );            }        } // end for loop    }