> Works for me, but how do we deal with code that wants to throw a
> safeguard exception in the last else? The usual "there is a programing
> error, I don't know what this thing is" kind of exception.

I think that shows up as a null pointer exception; or a compile error
- since the visitor pattern demands you strongly type all the options?
You could also make a default adapter that calls a notHandled() method
for each case by default.

public void handleModifyEvent(CatalogModifyEvent event) {
>       CatalogVisitor visitor = new CatlaogAdapter() {
>           void visitDataStoreInfo( DataStoreInfo ) {
>                  // expected
>           }
>           void notHandled( Object object ){
>                  throw new IllegalStateException("Did not expect "+object );
>           }
>
>           ...
>       }
>       event.getSource().accept( visitor );
>    }
You can also try and make your visitor stateful to ensure at least one
option was called.
Or make use of that "extraData" convention to communicate the same:

boolean accepted = (boolean ) event.getSource().accept( visitor, false);

Jody

------------------------------------------------------------------------------
_______________________________________________
Geoserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Reply via email to