static void checkTwoArguments( String name, TypedObjectNode[] vals1, TypedObjectNode[] vals2 ) throws FilterEvaluationException { if ( vals1.length == 0 || vals2.length == 0 ) { String msg = "The " + name + " function expects two arguments, but "; if ( vals1.length == 0 && vals2.length == 0 ) { msg += "both arguments were missing."; } else { msg += "the "; msg += vals1.length == 0 ? "first" : "second"; msg += " argument was missing."; } throw new FilterEvaluationException( msg ); } }
@Override public boolean hasNext() { if ( !nextCalled ) { return next != null; } next = null; while ( iter.hasNext() ) { Feature candidate = iter.next(); try { if ( filter.evaluate( candidate, evaluator ) ) { nextCalled = false; next = candidate; break; } } catch ( FilterEvaluationException e ) { throw new RuntimeException( e.getMessage(), e ); } } return next != null; }
@Override public void updateStep( LinkedList<Symbolizer<?>> base, Feature f, XPathEvaluator<Feature> evaluator ) { try { if ( filter == null || f == null || filter.evaluate( f, evaluator ) || ( base.isEmpty() && filter == ELSEFILTER ) ) { base.addAll( syms ); } } catch ( FilterEvaluationException e ) { LOG.warn( "Evaluating the following expression resulted in an error '{}':\n'{}'", e.getLocalizedMessage(), filter.toString() ); LOG.debug( "Stack trace:", e ); } }
/** * Evaluates the function for the given arguments (without a context object). * <p> * The double-dimension of input arguments is due to the fact that input arguments usually stem from * XPath-evaluation performed on a {@link TypedObjectNode}. Therefore, multiple values per input may occur. The * outer list contains one entry per parameter, the inner array contain the values for each parameter. Depending on * the type of function it may return multiple outputs as well. * </p> * * @param args * input arguments, must match the parameter signature, can be empty, but never <code>null</code> * @return output values, can be empty, but never <code>null</code> * @throws FilterEvaluationException */ public TypedObjectNode[] evaluate( List<TypedObjectNode[]> args ) throws FilterEvaluationException { throw new FilterEvaluationException( "Evaluation of function '" + getName() + "' is not implemented (or not supported without a context object." ); }
private boolean excludeByTimeSliceFilter( Property property ) { final TimeSlice timeSlice = (TimeSlice) property.getValue(); for ( final Filter timeSliceFilter : timeSliceFilters ) { TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator(); try { if ( !timeSliceFilter.evaluate( timeSlice, evaluator ) ) { return true; } } catch ( FilterEvaluationException e ) { LOG.warn( "Unable to evaluate time slice projection filter: " + e.getMessage() ); } } return false; }
@Override public void updateStep( StringBuffer base, Feature f, XPathEvaluator<Feature> evaluator ) { try { Object[] evald = expr.evaluate( f, evaluator ); if ( evald.length == 0 ) { LOG.warn( "The following expression in a style evaluated to null:\n{}", expr ); } else { base.append( evald[0] ); } } catch ( FilterEvaluationException e ) { LOG.warn( "Evaluating the following expression resulted in an error '{}':\n{}", e.getLocalizedMessage(), expr ); } } } );
@Override public TypedObjectNode[] eval( TypedObjectNode particle, ValueReference path ) throws FilterEvaluationException { if ( particle instanceof GMLObject ) { return eval( (GMLObject) particle, path ); } if ( particle instanceof ElementNode ) { return eval( (ElementNode) particle, path ); } throw new FilterEvaluationException( "Evaluation of XPath expressions on '" + particle.getClass() + "' is not supported." ); }
private List<Property> getTargetProperties( final Feature feature, final ValueReference propName ) throws FeatureStoreException { if (propName == null) { return emptyList(); } try { final TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator(); final TypedObjectNode[] nodes = evaluator.eval( feature, propName ); final List<Property> props = new ArrayList<Property>(); if ( nodes != null ) { for ( final TypedObjectNode node : nodes ) { if ( !( node instanceof Property ) ) { final String msg = propName + " does not refer to a property."; throw new FeatureStoreException( msg ); } props.add( (Property) node ); } } return props; } catch ( FilterEvaluationException e ) { throw new FeatureStoreException( e.getMessage(), e ); } }
@Override public void updateStep( Styling<?> base, Feature obj, XPathEvaluator<Feature> evaluator ) { try { Object[] evald = expr2.evaluate( obj, evaluator ); if ( evald.length == 0 ) { LOG.warn( "The following expression in a style evaluated to null:\n{}", expr2 ); } else { updater.update( base, evald[0].toString() ); } } catch ( FilterEvaluationException e ) { LOG.warn( "Evaluating the following expression resulted in an error '{}':\n{}", e.getLocalizedMessage(), expr2 ); } } };
/** * Constructs a new <code>SpecialCharString</code> instance from the given parameters. * * @param encodedString * @param wildCard * must be exacly one character * @param singleChar * must be exacly one character * @param escape * must be exacly one character * @throws FilterEvaluationException * if wildCard, singleChar or escapeChar are not exactly one character */ public IsLikeString( String encodedString, String wildCard, String singleChar, String escape ) throws FilterEvaluationException { if ( wildCard.length() != 1 || singleChar.length() != 1 || escape.length() != 1 ) { String msg = "At the moment, wildCard, singleChar and escapeChar must each be exactly one character."; throw new FilterEvaluationException( msg ); } this.wildCard = wildCard; this.singleChar = singleChar; this.escape = escape; this.parts = decode( encodedString ); }
private String getExternalRef( Feature building ) { String result = null; NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace( "cgml", NS ); ValueReference propName = new ValueReference( "cgml:externalReference/cgml:informationSystem/text()", nsContext ); TypedObjectNodeXPathEvaluator evaluator = new TypedObjectNodeXPathEvaluator( ); TypedObjectNode[] tons; try { tons = evaluator.eval( building, propName ); if ( tons.length > 0 ) { result = ( (PrimitiveValue) tons[0] ).getAsText().trim(); } } catch ( FilterEvaluationException e ) { LOG.error( "Retrieving of information system property failed: " + e.getMessage() ); } return result; }
@Override public void updateStep( T base, Feature f, XPathEvaluator<Feature> evaluator ) { StringBuilder tmp = new StringBuilder(); for ( Pair<String, Pair<Expression, String>> p : text ) { if ( p.first != null ) { tmp.append( p.first ); } if ( p.second != null ) { try { TypedObjectNode[] evald = p.second.first.evaluate( f, evaluator ); if ( evald.length == 0 ) { LOG.warn( "The following expression in a style evaluated to null:\n'{}'", p.second.second ); } else { tmp.append( evald[0] ); } } catch ( FilterEvaluationException e ) { LOG.warn( "Evaluating the following expression resulted in an error '{}':\n'{}'", e.getLocalizedMessage(), p.second.second ); } } } updater.update( base, tmp.toString() ); } };
@Override public <T> TypedObjectNode[] evaluate( T obj, XPathEvaluator<T> xpathEvaluator ) throws FilterEvaluationException { TypedObjectNode[] vals = getParams()[0].evaluate( obj, xpathEvaluator ); if ( vals.length != 1 ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument must evaluate" + " to exactly one value." ); } Geometry geom = FilterUtils.getGeometryValue( vals[0] ); if ( geom == null ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument did" + " not evaluate to a geometry." ); } // TODO is handling of multi geometries like this ok? boolean isPoint = geom instanceof Point || geom instanceof MultiPoint; return new TypedObjectNode[] { new PrimitiveValue( Boolean.toString( isPoint ) ) }; } };
throw new FeatureStoreException( e.getMessage(), e );
@Override public void render( RenderContext context ) throws InterruptedException { FeatureInputStream features = null; try { // TODO Should this always be done on this level? What about queueSize value? features = featureStore.query( queries.toArray( new Query[queries.size()] ) ); features = new ThreadedFeatureInputStream( features, 100 ); FeatureStreamRenderer renderer = new FeatureStreamRenderer( context, maxFeatures, evaluator ); renderer.renderFeatureStream( features, style ); } catch ( InterruptedException e ) { throw e; } catch ( FilterEvaluationException e ) { LOG.warn( "A filter could not be evaluated. The error was '{}'.", e.getLocalizedMessage() ); LOG.trace( "Stack trace:", e ); } catch ( Throwable e ) { LOG.warn( "Data could not be fetched from the feature store. The error was '{}'.", e.getLocalizedMessage() ); LOG.trace( "Stack trace:", e ); } finally { if ( features != null ) { features.close(); } } }
@Override public <T> TypedObjectNode[] evaluate( T obj, XPathEvaluator<T> xpathEvaluator ) throws FilterEvaluationException { TypedObjectNode[] vals = getParams()[0].evaluate( obj, xpathEvaluator ); if ( vals.length != 1 ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument must evaluate" + " to exactly one value." ); } Geometry geom = FilterUtils.getGeometryValue( vals[0] ); if ( geom == null ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument did" + " not evaluate to a geometry." ); } // TODO is handling of multi geometries like this ok? boolean result = geom instanceof Curve || geom instanceof MultiCurve<?> || geom instanceof MultiLineString; return new TypedObjectNode[] { new PrimitiveValue( Boolean.toString( result ) ) }; } };
throw new FeatureStoreException( e.getMessage(), e );
new Object[] { file, line, col, e.getLocalizedMessage() } ); LOG.trace( "Stack trace:", e );
@Override public <T> TypedObjectNode[] evaluate( T obj, XPathEvaluator<T> xpathEvaluator ) throws FilterEvaluationException { TypedObjectNode[] vals = getParams()[0].evaluate( obj, xpathEvaluator ); if ( vals.length != 1 ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument must evaluate" + " to exactly one value." ); } Geometry geom = FilterUtils.getGeometryValue( vals[0] ); if ( geom == null ) { throw new FilterEvaluationException( "The " + NAME + " function's first argument did" + " not evaluate to a geometry." ); } // TODO is handling of multi geometries like this ok? boolean isSurface = geom instanceof Surface || geom instanceof MultiPolygon || geom instanceof MultiSurface<?>; return new TypedObjectNode[] { new PrimitiveValue( Boolean.toString( isSurface ) ) }; } };
LOG.error( "Could not create a geometry layer texture because: " + e.getLocalizedMessage(), e ); } catch ( FilterEvaluationException e ) { LOG.error( "Could not create a geometry layer texture because: " + e.getLocalizedMessage(), e );