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.
> My objective is to have something fast that does have to go through 
> all the expression if the first thing found  in the expression tells 
> him it's not a static expression.
Understood.
> I tryed this :
> Object obj = expColor.evaluate(null);
> System.out.println(obj);
> and it return me : #00FFFF
> which is what I want.
But it is *not* what you want!

What you want is:
String obj = exprColor.evaulate(null, String.class ); // will force a 
color to #00FFFF form if needed

Or possibly:
Color obj = exprColor.evaualte(null,Color.class); // will force a String 
into a Color if needed

By violating object encapsulation you are missing out on functionality; 
and writing "dangerous" code.
> How does the expression works on an evaluate(null)?
Step through with the debugger and look. It does what you would expect; 
but when you get to functions and so on they will ask for their 
parameters using evaulate( null, Class ) in order not to be broken.
> The javadoc in geoapi doesnt tell me what it's supposed to return if I 
> use a null parameter.
It should not matter in this case; the parameter there is the Object or 
Feature or Metadata or Bean you are "Evaluating" against; for a "static" 
expression this object you are evaualting against is not even going to 
be used; so null is fine. You could put a Feature or Object or Bean in 
there and it would still work out the same.
> No exception are throw by the evaluate method so I believe it should 
> return something if he doesnt need a feature and null if he can't 
> evaluate it.
I did not understand that statement? If the expression contained a 
PropertyName or Function that used the *object* then you would of gotten 
an error right? In the larger picture if a Style (or WFS Query) does not 
want an error due to null then the user can use:
IsNull( propertyName) AND  <some more filters>

Cheers,
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

Reply via email to