/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.filter; import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import org.geotools.factory.CommonFactoryFinder; import org.geotools.factory.Hints; import org.geotools.filter.function.ClassificationFunction; import org.opengis.filter.expression.Function; import org.opengis.filter.expression.Literal; /** * Isolate function lookup code from Factory implementation(s). *
* This is done to look for two things: *
* You can create a function to represent an SQL function or a function hosted on
* an external service; the fallback value will be used if you evulate
* by a Java implementation on the classpath.
* @param name Function name; this will need to be an exact match
* @param parameters Set of Expressions to use as function parameters
* @param fallbackValue Literal to use if an implementation could not be found
* @return Function for the provided name, may be a FallbackFunction if an implementation could not be found
*/
public Function findFunction(String name, List parameters, Literal fallback ) {
name = functionName(name);
try {
// load the caches at first access
synchronized (this) {
if (functionExpressionCache == null) {
// scan for all the functions on the classpath
functionExpressionCache = new HashMap();
functionImplCache = new HashMap();
functionCache = new HashMap();
// Get all the GeoTools FunctionExpression implementations
// and store in functionExpressionCache
// (these are implementations of the legacy GeoTools FunctionExpression
// interface)
Set functions = CommonFactoryFinder.getFunctionExpressions(null);
for (Iterator it = functions.iterator(); it.hasNext();) {
FunctionExpression function = (FunctionExpression) it.next();
functionExpressionCache.put(function.getName().toLowerCase(),
(Class