Index: ContainsEnvelopeEvaluator.java
===================================================================
--- ContainsEnvelopeEvaluator.java	(revision 43039)
+++ ContainsEnvelopeEvaluator.java	(revision 43040)
@@ -3,35 +3,32 @@
  *
  * Copyright (C) 2007-2013 gvSIG Association.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3 of the License, or (at your option) any later
+ * version.
  *
- * This program 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 General Public License for more details.
+ * This program 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 General Public License for more
+ * details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * For any additional information, do not hesitate to contact us
- * at info AT gvsig.com, or visit our website www.gvsig.com.
+ * For any additional information, do not hesitate to contact us at info AT
+ * gvsig.com, or visit our website www.gvsig.com.
  */
 package org.gvsig.fmap.mapcontext.layers.vectorial;
 
 import org.cresques.cts.IProjection;
+import org.gvsig.fmap.dal.ExpressionBuilder;
 
-import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
 import org.gvsig.fmap.dal.feature.Feature;
 import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
 import org.gvsig.fmap.dal.feature.FeatureType;
 import org.gvsig.fmap.geom.Geometry;
-import org.gvsig.fmap.geom.operation.GeometryOperationException;
-import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
 import org.gvsig.fmap.geom.primitive.Envelope;
 import org.gvsig.tools.evaluator.AbstractEvaluator;
 import org.gvsig.tools.evaluator.EvaluatorData;
@@ -39,25 +36,51 @@
 
 public class ContainsEnvelopeEvaluator extends AbstractEvaluator {
 
-	private Envelope envelope;
-	private String geomName;
-	private Envelope envelopeTrans;
-	private boolean isDefault;
-	private String srs;
-	private String envelopeWKT;
+    private final Envelope envelope;
+    private final String geomName;
+    private final Envelope envelopeTrans;
+    private final boolean isDefault;
+    private final ExpressionBuilder builder;
+    private final IProjection projection;
 
-	ContainsEnvelopeEvaluator(Envelope envelope,
-			IProjection envelopeProjection, FeatureType featureType,
-			String geomName) {
-		FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
-				.get(geomName);
-
-		this.isDefault = featureType.getDefaultGeometryAttributeName().equals(
-				geomName);
-		this.envelope = envelope;
-		// this.srs = envelopeProjection.getAbrev();
-		// this.projection=CRSFactory.getCRS(fad.getSRS());
-		// this.envelopeProjection=envelopeProjection;
+    /**
+     * @deprecated  use @{link org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory}
+     * @param envelope
+     * @param envelopeProjection
+     * @param featureType
+     * @param geomName
+     */
+    public ContainsEnvelopeEvaluator(
+            Envelope envelope,
+            IProjection envelopeProjection,
+            FeatureType featureType,
+            String geomName
+        ) {
+        this(
+                envelope, 
+                envelopeProjection, 
+                featureType, 
+                geomName, 
+                SpatialEvaluatorsFactory.getInstance().createBuilder()
+        );
+    }
+    
+    ContainsEnvelopeEvaluator(
+            Envelope envelope,
+            IProjection envelopeProjection,
+            FeatureType featureType,
+            String geomName,
+            ExpressionBuilder builder
+        ) {
+        FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) featureType
+                .get(geomName);
+        this.isDefault = featureType.getDefaultGeometryAttributeName().equals(geomName);
+        this.projection = envelopeProjection;
+        this.builder = builder;
+        this.envelope = envelope;
+        // this.srs = envelopeProjection.getAbrev();
+        // this.projection=CRSFactory.getCRS(fad.getSRS());
+        // this.envelopeProjection=envelopeProjection;
 //		ICoordTrans ct = null;
 //		if (!this.srs.equals(fad.getSRS())) { // FIXME comparaci�n
 //			ct = envelopeProjection.getCT(fad.getSRS());
@@ -65,46 +88,43 @@
 //		if (ct != null) {
 //			this.envelopeTrans = envelope.convert(ct);
 //		} else {
-			this.envelopeTrans = envelope;
+        this.envelopeTrans = envelope;
 //		}
-		this.geomName = geomName;
-		this.srs = envelopeProjection.getAbrev();
-		this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
+        this.geomName = geomName;
+        this.getFieldsInfo().addMatchFieldValue(geomName, envelopeTrans);
 
-	}
+    }
 
-	public Object evaluate(EvaluatorData data) throws EvaluatorException {
-		Envelope featureEnvelope;
-		if (isDefault) {
-			featureEnvelope = ((Feature) data.getContextValue("feature"))
-					.getDefaultEnvelope();
+    @Override
+    public Object evaluate(EvaluatorData data) throws EvaluatorException {
+        Envelope featureEnvelope;
+        if (isDefault) {
+            featureEnvelope = ((Feature) data.getContextValue("feature"))
+                    .getDefaultEnvelope();
 
-		} else {
-                    Geometry geom = (Geometry) data.getDataValue(geomName);
-                    if( geom == null ) {
-                        return Boolean.FALSE;
-                    }
-                    featureEnvelope = geom.getEnvelope();
-		}
-		return new Boolean(envelopeTrans.contains(featureEnvelope));
-	}
+        } else {
+            Geometry geom = (Geometry) data.getDataValue(geomName);
+            if (geom == null) {
+                return false;
+            }
+            featureEnvelope = geom.getEnvelope();
+        }
+        return envelopeTrans.contains(featureEnvelope);
+    }
 
-	public String getName() {
-		return "contains in envelope";
-	}
+    @Override
+    public String getName() {
+        return "contains in envelope";
+    }
 
-	public String getSQL() {
-		if (envelopeWKT == null) {
-			try {
-				envelopeWKT = envelope.getGeometry().convertToWKT();
-			} catch (GeometryOperationNotSupportedException e) {
-				throw new DataEvaluatorRuntimeException(e);
-			} catch (GeometryOperationException e) {
-				throw new DataEvaluatorRuntimeException(e);
-			}
-		}
-		return " ST_contains(ST_GeomFromText('" + envelopeWKT + "', '" + srs
-				+ "'), ST_envelope(" + geomName + ")) ";
-	}
+    @Override
+    public String getSQL() {
+        return this.builder.set(
+                builder.ST_Contains(
+                        builder.envelope(envelope, projection),
+                        builder.column(geomName)
+                )
+        ).toString();
+    }
 
 }
