Skip to content
Browse files

Follow up to previous commit, make dynamic properties work with attri…

…bute extraction
  • Loading branch information...
1 parent 73e8d07 commit 86072b9a7ada612d1e8495d288bd6071ce4d67b8 @aaime aaime committed Jul 18, 2012
View
36 modules/library/main/src/main/java/org/geotools/filter/FilterAttributeExtractor.java
@@ -20,9 +20,11 @@
import java.util.HashSet;
import java.util.Set;
+import org.geotools.filter.function.FilterFunction_property;
import org.geotools.filter.visitor.DefaultFilterVisitor;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.expression.VolatileFunction;
@@ -55,6 +57,7 @@
protected Set<String> attributeNames = new HashSet<String>();
protected Set<PropertyName> propertyNames = new HashSet<PropertyName>();
protected boolean usingVolatileFunctions;
+ protected boolean usingDynamicProperties;
/** feature type to evaluate against */
protected SimpleFeatureType featureType;
@@ -139,6 +142,27 @@ public Object visit(org.opengis.filter.expression.Function expression, Object da
if (expression instanceof VolatileFunction) {
usingVolatileFunctions = true;
}
+ if(expression instanceof FilterFunction_property) {
+ boolean foundLiteral = false;
+ // dynamic property usage
+ if(expression.getParameters() != null && expression.getParameters().size() > 0) {
+ org.opengis.filter.expression.Expression firstParam = expression.getParameters().get(0);
+
+ FilterAttributeExtractor secondary = new FilterAttributeExtractor();
+ firstParam.accept(secondary, null);
+ if (secondary.isConstantExpression()) {
+ String name = firstParam.evaluate(null, String.class);
+ if(name != null) {
+ attributeNames.add(name);
+ foundLiteral = true;
+ }
+ }
+ }
+
+ if(!foundLiteral) {
+ usingDynamicProperties = true;
+ }
+ }
return super.visit(expression, data);
};
@@ -149,6 +173,16 @@ public Object visit(org.opengis.filter.expression.Function expression, Object da
* @return
*/
public boolean isConstantExpression() {
- return !usingVolatileFunctions && getAttributeNameSet().isEmpty();
+ return !usingVolatileFunctions && !usingDynamicProperties && getAttributeNameSet().isEmpty();
+ }
+
+ /**
+ * Returns true if the expression is using dynamic property names, so a
+ * static analysis of the expression won't be able to return all the properties in use
+ *
+ * @return
+ */
+ public boolean isUsingDynamincProperties() {
+ return usingDynamicProperties;
}
}
View
13 modules/library/main/src/test/java/org/geotools/filter/FilterAttributeExtractorTest.java
@@ -28,11 +28,13 @@
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.SchemaException;
import org.opengis.filter.Filter;
+import org.geotools.filter.function.EnvFunction;
import org.opengis.filter.Id;
import org.opengis.filter.Or;
import org.opengis.filter.PropertyIsEqualTo;
import org.opengis.filter.PropertyIsLike;
import org.opengis.filter.PropertyIsNull;
+import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.spatial.DWithin;
@@ -265,4 +267,15 @@ public void testLogic() throws IllegalFilterException {
assertAttributeName(filter, "testString");
}
+
+ public void testDynamicProperty() throws Exception {
+ Function func = fac.function("property", fac.function("env", fac.literal("pname")));
+ PropertyIsEqualTo filter = fac.equals(func, fac.literal("test"));
+ try {
+ EnvFunction.setLocalValue("pname", "name");
+ assertAttributeName(filter, "name");
+ } finally {
+ EnvFunction.clearLocalValues();
+ }
+ }
}
View
7 modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java
@@ -1465,6 +1465,9 @@ private int findRenderingBuffer(LiteFeatureTypeStyle[] styles) {
}
}
+ if(sae.isUsingDynamincProperties()) {
+ return null;
+ }
Set<PropertyName> attributes = sae.getAttributes();
Set<String> attributeNames = sae.getAttributeNameSet();
@@ -2850,9 +2853,7 @@ private void processSymbolizers(final Graphics2D graphics,
}
}
}
-
-
- } else if ( currLayer.getSource() != null ) {
+ } if ( currLayer.getSource() != null ) {
return currLayer.getSource().getCRS();
}

0 comments on commit 86072b9

Please sign in to comment.
Something went wrong with that request. Please try again.