johann sorel wrote: > Jody Garnett a écrit : >> johann sorel wrote: >>> Is it possible to make a visitor that break out of the "visiting" >>> operation if he found something he doesnt like ? >> Yes; but for the specifics it depends on how the visitor interface >> was written. Some visitor interfaces explicitly return a true / false >> to indicate if they are "done". Our Filter visitor returns an Object >> and you the implementor can do with that what you want. Since our >> visitor is reponsible for navigating the Expression structure itself >> I recommend the following... >> - make a visitor for "IsStaticExpression" that returns true or false >> - when visiting something like an AND expression you can "break out" >> (ie return false) when you find your first child expression that is >> non static >> >> There are lots of examples in the code base. > Could I have some more tips because I dont see how to return something > with the expressionVisitor. It just have > N visit(..) methods that will be called on each element in the > expression. That is the trick; they *won't* be called on each element in the expression; your visitor has to navigate the Expression itself ... and if you already have the answer you want you can stop navigating.
I do hope you have read the following already? - http://docs.codehaus.org/display/GEOTDOC/FilterVisitor+Examples You need to make a visitor like this ... public class IsStaticExpressionVisitor implements ExpressionVisitor { public Boolean visit( Literal expression, Object data ) { return true; } public Boolean visit( PropertyName expression, Object data ) { return false; } public Boolean visit( Function expression, Object data ) { boolean isStatic = true; if( expression.getParameters() != null ){ for( Expression parameter : expression.getParameters() ){ isStatic = (Boolean) parameter.accept( this, data); if( isStatic == false ) break; } } return isStatic; } public Boolean visit( Add expression, Object data ) { boolean isStatic; isStatic = (Boolean) expression.getExpression1().accept( this, data); if( isStatic == false ) return false; isStatic = (Boolean) expression.getExpression2().accept( this, data); return isStatic; } ...etc... } I have committed the example as IsStaticExpressionVisitor; and provided a code example in the javadocs. Jody ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Geotools-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-devel
