@Override public <T> T evaluate(Object object, Class<T> context) { // Selection of the first expression Expression clazzExpression = parameters.get(0); // Getting the defined class Class clazz = clazzExpression.evaluate(object, Class.class); // Checking the result boolean result = false; // If the input class is Object, the function always returns true if (clazz != null) { if (clazz == Object.class) { result = true; } else { // Otherwise the function checks if the class is an instance of the // input class result = clazz.isAssignableFrom(object.getClass()); } } // Finally the result is converted to the defined context class return Converters.convert(result, context); }
@Override public void visit(Mark mark) { final Expression wellKnownName = mark.getWellKnownName(); if (wellKnownName instanceof Literal) { final String name = wellKnownName.evaluate(null, String.class); if (name.startsWith("resource:/")) { try { Resource r = resourceLoader.fromURL(name); if (r != null && r.getType() != Type.UNDEFINED) { resources.add(r); } } catch (IllegalArgumentException e) { GeoServerConfigPersister.LOGGER.log( Level.WARNING, "Error attemping to process SLD resource", e); } } } }
private String evalToString(Expression exp, Object f, String fallback) { if (exp == null) { return fallback; } String s = exp.evaluate(f, String.class); if (s != null) { return s; } return fallback; }
protected Object getValue(final Expression expression, Object sourceFeature) { Object value = expression.evaluate(sourceFeature); if (value instanceof Attribute) { value = ((Attribute) value).getValue(); } return value; }
public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException { if (sqlOnBorrow != null && !"".equals(sqlOnBorrow)) { String command = sqlOnBorrow.evaluate(null, String.class); Statement st = null; try { st = cx.createStatement(); st.execute(command); } finally { store.closeSafe(st); } } }
public Object evaluate(Object feature) { Expression ae = (Expression) getParameters().get(0); Object value = ae.evaluate(feature); if (value == null) { return 0; } else if (value instanceof Collection) { return ((Collection<?>) value).size(); } else { return 1; } } }
public Object evaluate(Object feature) { try { Object arg = getExpression(0).evaluate(feature); Class target = getExpression(1).evaluate(feature, Class.class); return Converters.convert(arg, target); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function convert argument #1 - expected type Class"); } } }
public Object evaluate(Object feature) { org.opengis.filter.expression.Expression geom; geom = (org.opengis.filter.expression.Expression) getParameters().get(0); Geometry g = (Geometry) geom.evaluate(feature); return new Double(getArea(g)); }
/** Computes and returns the contour style */ public java.awt.Composite getContourComposite() { Stroke stroke = ls.getStroke(); if (stroke == null) { return null; } float opacity = ((Float) stroke.getOpacity().evaluate(feature, Float.class)).floatValue(); Composite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity); return composite; }
public void visit(org.opengis.feature.Feature feature) { Object value = expr.evaluate(feature); if (value != null) { if (strategy == null) { Class type = value.getClass(); strategy = createStrategy(type); } strategy.add(value); } }
protected Expression copyCqlExpression(Expression expression) { if (expression == null) return null; Expression simplified = null; if (expression instanceof Literal) { String value = expression.evaluate(null, String.class); if (value != null && value.startsWith("${")) { expression = ExpressionExtractor.extractCqlExpressions(value); } } simplified = (Expression) expression.accept(simplifier, ff); return simplified; }
public void visit(Feature feature) { Object value = expr.evaluate(feature); if (value != null) { if (strategy == null) { strategy = createStrategy(value.getClass()); } strategy.add(value); } }
public Object evaluate(Object feature) { Geometry arg0; try { // attempt to get value and perform conversion arg0 = getExpression(0).evaluate(feature, Geometry.class); } catch (Exception e) // probably a type error { throw new IllegalArgumentException( "Filter Function problem for function convexHull argument #0 - expected type Geometry"); } return (StaticGeometry.convexHull(arg0)); } }
public Object evaluate(Object object) { String path = (String) this.params.get(0).evaluate(object); if (object == null) { return new AttributeExpressionImpl(new NameImpl(path)); } return MongoComplexUtilities.getValues(object, path); }
@Override public Object evaluate(Object object) { PropertyName name = (PropertyName) getParameters().get(0); Object literal = getParameters().get(1).evaluate(null); Object o = name.evaluate(object); return o.equals(Converters.convert(literal, o.getClass())); } }
public void testEvaluateWithStrings() throws Exception { org.opengis.filter.expression.Expression function = ff.function("Quantile", ff.property("group"), ff.literal(2)); Classifier classifier = (Classifier) function.evaluate(featureCollection); assertNotNull(classifier); Classifier classifier2 = (Classifier) function.evaluate(featureCollection, Classifier.class); assertNotNull(classifier2); Integer number = (Integer) function.evaluate(featureCollection, Integer.class); assertNull(number); }
@Test public void testPreserveOriginalSRS() throws NoSuchAuthorityCodeException, FactoryException { String srs = "AUTO:42004,9001,0,33"; CoordinateReferenceSystem crs = CRS.decode(srs); BBOX bbox = ff.bbox(ff.property(""), 0, 1000, 2000, 3000, srs); Geometry geom = bbox.getExpression2().evaluate(null, Geometry.class); assertEquals(crs, geom.getUserData()); assertEquals(srs, bbox.getSRS()); } }
@Test public void testRasterBandSelectionGray() throws Exception { String yaml = "raster:\n" + " channels:\n" + " gray:\n" + " name: foo\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); RasterSymbolizer r = SLD.rasterSymbolizer(SLD.defaultStyle(sld)); SelectedChannelType grayChannel = r.getChannelSelection().getGrayChannel(); assertThat(grayChannel.getChannelName().evaluate(null, String.class), equalTo("foo")); assertThat(grayChannel.getContrastEnhancement(), nullContrast()); }
@Test public void testRasterBandSelectionGrayTerse() throws Exception { String yaml = "raster:\n" + " channels:\n" + " gray: 1\n"; StyledLayerDescriptor sld = Ysld.parse(yaml); RasterSymbolizer r = SLD.rasterSymbolizer(SLD.defaultStyle(sld)); SelectedChannelType grayChannel = r.getChannelSelection().getGrayChannel(); assertThat(grayChannel.getChannelName().evaluate(null, String.class), equalTo("1")); assertThat(grayChannel.getContrastEnhancement(), nullContrast()); }