Hi all, sorry for the cross-posting,
in porting GSIP-69 proposal to OGC Filter as per community feedback,
I'm following Andrea's suggestion of using anonymous inner classes
that implement Function to overcome the lack of Filter extensibility
other than through functions, for predicates that are to be executed
exclusively at runtime (can't be encoded to SQL, for example),and at
the same time without bloating the Function SPI with (GeoServer
Catalog) domain specific functions.
So, such a predicate can be:
public abstract class CatalogFunction<T extends CatalogInfo> extends
FunctionImpl implements
Function, VolatileFunction {
public CatalogFunction() {
setName("DynamicGeoServerCatalogFunction");
}
public abstract Object evaluate(T object);
public <C> C evaluate(T object, Class<C> context) {
return (C) super.evaluate((Object) object, context);
}
@Override
public Object evaluate(Object object) {
return evaluate((T) object);
}
}
....
CatalogFunction<T> visible = new CatalogFunction<T>() {
/**
* Returns {@code false} if the catalog info shall be
hidden, {@code true} otherwise.
*/
@Override
public Object evaluate(T object) {
WrapperPolicy policy = buildWrapperPolicy(user, object);
AccessLevel accessLevel = policy.getAccessLevel();
boolean visible = !AccessLevel.HIDDEN.equals(accessLevel);
return Boolean.valueOf(visible);
}
};
FilterFactory ff = ...
Filter filter = ff.equals(ff.literal(true), visible);
This works ok except when it comes to use SimplifyingFilterVisitor
down in the call chain (an hence any DuplicatingFilterVisitor
specialization), because visit(Function) will try to return a new
instance looking up the function factory by name, which does not
exist.
For this reason, and in order to keep it as simple as possible, I
wonder if it would be ok to say that VolatileFunctions are not
"cloneable", and so instruct DuplicatingFilterVisitor.visit(Function,
Object) not to go through the SPI lookup for VolatileFunctions, but
return them directly.
Another possibility is to add a separate marker interface, but I would
rather avoid bloating the API.
Thoughts?
TIA,
Gabriel
--
Gabriel Roldan
OpenGeo - http://opengeo.org
Expert service straight from the developers.