Index: TestExpressionBuilder.java
===================================================================
--- TestExpressionBuilder.java	(revision 44197)
+++ TestExpressionBuilder.java	(revision 44198)
@@ -1,15 +1,10 @@
 package org.gvsig.expresionevaluator.impl;
 
-import java.util.ArrayList;
-import java.util.List;
 import junit.framework.TestCase;
 import org.apache.commons.lang3.ArrayUtils;
 import org.cresques.cts.IProjection;
 import org.gvsig.expressionevaluator.ExpressionBuilder;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Config;
 import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
-import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
 import org.gvsig.expressionevaluator.impl.DefaultExpressionBuilder;
 import org.gvsig.fmap.crs.CRSFactory;
 import org.gvsig.fmap.geom.Geometry;
@@ -29,7 +24,6 @@
     protected void setUp() throws Exception {
         super.setUp();
         new DefaultLibrariesInitializer().fullInitialize();
-//        new ExpressionEvaluatorImplLibrary().initialize();
     }
 
     @Override
@@ -40,45 +34,12 @@
     // TODO add test methods here. The name must begin with 'test'. For example:
     // public void testHello() {}
     
-    List<String> getVariableNames(ExpressionBuilder builder) {
-        List<String> vars = new ArrayList<>();
-        for (Variable var : builder.getVariables()) {
-            vars.add(var.getName());
-        }
-        return vars;
-    }
-    
-    List<String> getParameterNames(ExpressionBuilder builder) {
-        List<String> params = new ArrayList<>();
-        for (Parameter param : builder.getParameters()) {
-            String s;
-            switch(param.getType()) {
-                case Constant:
-                    Object value = param.getValue();
-                    if( value==null ) {
-                        s = "null";
-                    } else if( value instanceof String ) {
-                        s = "'" + (String)value + "'";
-                    } else {
-                        s = value.toString();
-                    }    
-                    break;
-                case Geometry:
-                case Variable:
-                default:
-                    s = "\"" + param.getName() + "\"";
-            }
-            params.add(s);
-        }
-        return params;
-    }
-    
     public void test2() {
         ExpressionBuilder builder = new DefaultExpressionBuilder();
         
         builder.and(
           builder.eq(
-            builder.lcase(builder.variable("colum_name_c")),
+            builder.lower(builder.variable("colum_name_c")),
             builder.parameter("colum_name_p")
           )
         );
@@ -86,7 +47,7 @@
             builder.group(
                 builder.or(
                     builder.like(
-                        builder.lcase( builder.variable("uno")),
+                        builder.lower( builder.variable("uno")),
                         builder.constant("%10")
                     ),
                     builder.lt(
@@ -114,16 +75,16 @@
             )
         );
         assertEquals(
-                "( (LCASE(\"colum_name_c\")) = (?) ) AND ( ( (LCASE(\"uno\")) LIKE ('%10') ) OR ( (\"dos\") < (-3.5) ) ) AND ST_Intersects((\"geom1\"), (ST_Envelope(ST_GeomFromWKB((?), (?))))) AND ( (\"tres\") > (123456789) )",
+                "( (LOWER(\"colum_name_c\")) = (?) ) AND ( ( (LOWER(\"uno\")) LIKE ('%10') ) OR ( (\"dos\") < (-3.5) ) ) AND ST_Intersects((\"geom1\"), (ST_Envelope(ST_GeomFromWKB((?), (?))))) AND ( (\"tres\") > (123456789) )",
                 builder.toString()
         );
         assertEquals(
                 "[colum_name_c, dos, geom1, tres, uno]",
-                ArrayUtils.toString(getVariableNames(builder))
+                ArrayUtils.toString(builder.variables_names())
         );
         assertEquals(
                 "[\"colum_name_p\", \"geom2\", 4326]",
-                ArrayUtils.toString(getParameterNames(builder))
+                ArrayUtils.toString(builder.parameters_names())
         );
     }
     
@@ -140,13 +101,13 @@
               builder.variable("the_geom")
             )
         );
-        builder.getConfig().set(Config.geometry_type_support, GeometrySupportType.WKT);
+        builder.geometry_support_type(GeometrySupportType.WKT);
         System.out.println(builder.toString());
         assertEquals(
-                "ST_Intersects((ST_GeomFromText('POINT (10 20)', (4326))), (\"the_geom\"))",
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (\"the_geom\"))",
                 builder.toString()
         );
-        builder.getConfig().set(Config.geometry_type_support, GeometrySupportType.WKB);
+        builder.geometry_support_type(GeometrySupportType.WKB);
         System.out.println(builder.toString());
         assertEquals(
                 "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (\"the_geom\"))",
@@ -154,14 +115,214 @@
         );
         assertEquals(
                 "[the_geom]",
-                ArrayUtils.toString(getVariableNames(builder))
+                ArrayUtils.toString(builder.variables_names())
         );
         assertEquals(
                 "[]",
-                ArrayUtils.toString(getParameterNames(builder))
+                ArrayUtils.toString(builder.parameters_names())
         );
     }
     
+    public void testParameter() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter("the_geom")
+            )
+        );
+        builder.geometry_support_type(GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (?))",
+                builder.toString()
+        );
+        builder.geometry_support_type(GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (?))",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(builder.variables_names())
+        );
+        assertEquals(
+                "[\"the_geom\"]",
+                ArrayUtils.toString(builder.parameters_names())
+        );
+    }
+    
+    public void testParameterGeomWhitoutSRS() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter("the_geom").as_geometry_variable()
+            )
+        );
+        try {
+            builder.toString();
+            fail("Geometry parameter without SRS not detected.");
+        } catch(IllegalArgumentException ex) {
+            // Do nothing, it's ok that fail if not SRS is specified.
+        }
+    }
+    
+    public void testPatameterGeomWithSRS1() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter("the_geom").srs(proj)
+            )
+        );
+        builder.geometry_support_type(GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (ST_GeomFromText((?), (4326))))",
+                builder.toString()
+        );
+        builder.geometry_support_type(GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (ST_GeomFromWKB((?), (4326))))",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(builder.variables_names())
+        );
+        assertEquals(
+                "[\"the_geom\"]",
+                ArrayUtils.toString(builder.parameters_names())
+        );
+    }
+    
+    public void testParameterGeomWithSRS2() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter("the_geom").srs(builder.constant(4326))
+            )
+        );
+        builder.geometry_support_type(GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (ST_GeomFromText((?), (4326))))",
+                builder.toString()
+        );
+        builder.geometry_support_type(GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (ST_GeomFromWKB((?), (4326))))",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(builder.variables_names())
+        );
+        assertEquals(
+                "[\"the_geom\"]",
+                ArrayUtils.toString(builder.parameters_names())
+        );
+    }
+    
+    public void testParameterGeomWithParameterSRS() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter("the_geom").srs(
+                      builder.parameter().value(proj)
+              )
+            )
+        );
+        builder.geometry_support_type(GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (ST_GeomFromText((?), (?))))",
+                builder.toString()
+        );
+        builder.geometry_support_type(GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (ST_GeomFromWKB((?), (?))))",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(builder.variables_names())
+        );
+        assertEquals(
+                "[\"the_geom\", 4326]",
+                ArrayUtils.toString(builder.parameters_names())
+        );
+    }
+    
+    public void testParameterGeomConstant() throws CreateGeometryException {
+        ExpressionBuilder builder = new DefaultExpressionBuilder();
+                
+        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
+        IProjection proj = CRSFactory.getCRS("EPSG:4326");
+        
+        Point point = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        Point point2 = geometryManager.createPoint(10, 20, Geometry.SUBTYPES.GEOM2D);
+        point2.setProjection(proj);
+        builder.set(        
+            builder.ST_Intersects(
+              builder.geometry(point,proj),
+              builder.parameter().value(point2)
+            )
+        );
+        builder.geometry_support_type(GeometrySupportType.WKT);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromText(('POINT (10 20)'), (4326))), (ST_GeomFromText((?), (?))))",
+                builder.toString()
+        );
+        builder.geometry_support_type(GeometrySupportType.WKB);
+        System.out.println(builder.toString());
+        assertEquals(
+                "ST_Intersects((ST_GeomFromWKB((DECODE('000000000140240000000000004034000000000000','hex')), (4326))), (ST_GeomFromWKB((?), (?))))",
+                builder.toString()
+        );
+        assertEquals(
+                "[]",
+                ArrayUtils.toString(builder.variables_names())
+        );
+        assertEquals(
+                "[0x000000000140240000000000004034000000000000, 4326]",
+                ArrayUtils.toString(builder.parameters_names())
+        );
+    }
+    
     public void test4() throws CreateGeometryException {
         ExpressionBuilder builder = new DefaultExpressionBuilder();
                 
@@ -186,11 +347,11 @@
         );
         assertEquals(
                 "[geom1]",
-                ArrayUtils.toString(getVariableNames(builder))
+                ArrayUtils.toString(builder.variables_names())
         );
         assertEquals(
                 "[\"geom2\", 4326]",
-                ArrayUtils.toString(getParameterNames(builder))
+                ArrayUtils.toString(builder.parameters_names())
         );
     }
         
@@ -213,11 +374,11 @@
         );
         assertEquals(
                 "[geom]",
-                ArrayUtils.toString(getVariableNames(builder))
+                ArrayUtils.toString(builder.variables_names())
         );
         assertEquals(
                 "[]",
-                ArrayUtils.toString(getParameterNames(builder))
+                ArrayUtils.toString(builder.parameters_names())
         );
     }
 }
