Hello,

Here is a new Expression visitor that returns a collection of the 
required attributes of this expression.
I would like someone to check it and someone working on the main module 
to commit it.
(or at least tell me that I can commit it in package : 
org.geotools.filter.visitor)

regards

-- 
Johann Sorel

Company - Geomatys GIS Developer
Mail - [EMAIL PROTECTED]



################ CODE ##############################

/*
 *    GeoTools - The Open Source Java GIS Tookit
 *    http://geotools.org
 *
 *    (C) 2004-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

package org...........;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.opengis.filter.expression.Add;
import org.opengis.filter.expression.Divide;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.ExpressionVisitor;
import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.Multiply;
import org.opengis.filter.expression.NilExpression;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.expression.Subtract;

/**
 * Expression visitor that returns a list of all Feature attributs requiered by 
this expression.
 * 
 * @author Johann Sorel
 */
public class ListingPropertyVisitor implements ExpressionVisitor {
    
    public static final ListingPropertyVisitor VISITOR = new 
ListingPropertyVisitor();
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    protected ListingPropertyVisitor() {
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( NilExpression expression, Object data ) {  
      
        return Collections.emptyList();
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( Add expression, Object data ) {
        Collection<String> names = new ArrayList<String>();
        names.addAll( (Collection<String>) expression.getExpression1().accept( 
this, data) );
        names.addAll( (Collection<String>) expression.getExpression2().accept( 
this, data) );
        return names;
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( Divide expression, Object data ) {
        Collection<String> names = new ArrayList<String>();
        names.addAll( (Collection<String>) expression.getExpression1().accept( 
this, data) );
        names.addAll( (Collection<String>) expression.getExpression2().accept( 
this, data) );
        return names;
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( Function expression, Object data ) {
           
        if( expression.getParameters() != null ){
            Collection<String> names = new ArrayList<String>(); 
            for( Expression parameter : expression.getParameters() ){
                names.addAll( (Collection<String>) parameter.accept( this, 
data) );
            }
            return names;
        }
        return Collections.emptyList();
    }
    /**
     * Literal expressions are always static.
     * @return true
     */
    public Collection<String> visit( Literal expression, Object data ) {        
        return Collections.emptyList();
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( Multiply expression, Object data ) {
        Collection<String> names = new ArrayList<String>();
        names.addAll( (Collection<String>) expression.getExpression1().accept( 
this, data) );
        names.addAll( (Collection<String>) expression.getExpression2().accept( 
this, data) );
        return names;
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( PropertyName expression, Object data ) {
        return Collections.singleton(expression.getPropertyName());
    }
    
    /** 
     * visit each expression and return all requiered Attributs 
     */
    public Collection<String> visit( Subtract expression, Object data ) {
        Collection<String> names = new ArrayList<String>();
        names.addAll( (Collection<String>) expression.getExpression1().accept( 
this, data) );
        names.addAll( (Collection<String>) expression.getExpression2().accept( 
this, data) );
        return names;
    }
    
}



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to