Revision 44669 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/coerce/CoerceToGeometry.java
CoerceToGeometry.java | ||
---|---|---|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.fmap.geom.GeometryLocator; |
28 | 28 |
import org.gvsig.fmap.geom.GeometryManager; |
29 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
29 | 30 |
import org.gvsig.tools.dataTypes.CoercionException; |
30 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
31 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
31 | 32 |
|
32 | 33 |
/** |
33 | 34 |
* Convert a object to Geometry. |
... | ... | |
41 | 42 |
* |
42 | 43 |
*/ |
43 | 44 |
@SuppressWarnings("UseSpecificCatch") |
44 |
public class CoerceToGeometry implements Coercion {
|
|
45 |
public class CoerceToGeometry extends AbstractCoercion {
|
|
45 | 46 |
|
46 |
public Object coerce(Object value) throws CoercionException { |
|
47 |
try { |
|
48 |
if (value == null || value instanceof Geometry) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
Geometry geom; |
|
52 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
53 |
if (value instanceof byte[]) { |
|
54 |
geom = manager.createFrom((byte[]) value); |
|
55 |
} else { |
|
56 |
// Si no puede pasear el WKT devuelbe null y no lanza una |
|
57 |
// excepcion. |
|
58 |
geom = manager.createFrom(value.toString()); |
|
59 |
} |
|
60 |
if (geom == null) { |
|
61 |
throw new CoercionException(); |
|
62 |
} |
|
63 |
return geom; |
|
64 |
} catch (Exception e) { |
|
65 |
throw new CoercionException(e); |
|
66 |
} |
|
67 |
|
|
47 |
@Override |
|
48 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
49 |
if (value == null || value instanceof Geometry) { |
|
50 |
return value; |
|
68 | 51 |
} |
52 |
try { |
|
53 |
Geometry geom; |
|
54 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
55 |
if (value instanceof byte[]) { |
|
56 |
geom = manager.createFrom((byte[]) value); |
|
57 |
} else { |
|
58 |
// Si no puede pasear el WKT devuelbe null y no lanza una |
|
59 |
// excepcion. |
|
60 |
geom = manager.createFrom(value.toString()); |
|
61 |
} |
|
62 |
if (geom == null) { |
|
63 |
throw new CoercionException(); |
|
64 |
} |
|
65 |
return geom; |
|
66 |
} catch (Exception e) { |
|
67 |
throw new CoercionException(e); |
|
68 |
} |
|
69 | 69 |
|
70 |
} |
|
71 |
|
|
70 | 72 |
} |
Also available in: Unified diff