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/CoerceToByteArray.java
CoerceToByteArray.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.geom.jts.coerce; |
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
28 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
27 | 29 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
30 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
29 | 31 |
|
30 | 32 |
/** |
31 | 33 |
* Convert a Geometry to Byte Array encoded as WKB. |
... | ... | |
34 | 36 |
* @version $Id$ |
35 | 37 |
* |
36 | 38 |
*/ |
37 |
public class CoerceToByteArray implements Coercion { |
|
39 |
@SuppressWarnings("UseSpecificCatch") |
|
40 |
public class CoerceToByteArray extends AbstractCoercion { |
|
38 | 41 |
|
39 |
Coercion previous = null; |
|
42 |
public CoerceToByteArray() { |
|
43 |
// Do nothing |
|
44 |
} |
|
40 | 45 |
|
41 |
public CoerceToByteArray() { |
|
42 |
// Do nothing |
|
43 |
} |
|
46 |
@Override |
|
47 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
48 |
if (value == null || value instanceof Byte[]) { |
|
49 |
return value; |
|
50 |
} |
|
51 |
try { |
|
52 |
if (value instanceof Geometry) { |
|
53 |
return ((Geometry) value).convertToWKB(); |
|
54 |
} |
|
55 |
} catch (Exception e) { |
|
56 |
throw new CoercionException(e); |
|
57 |
} |
|
58 |
throw new CoercionException(); |
|
59 |
} |
|
44 | 60 |
|
45 |
public CoerceToByteArray(Coercion previous) { |
|
46 |
this.previous = previous; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public Object coerce(Object value) throws CoercionException { |
|
51 |
try { |
|
52 |
if( value == null || value instanceof byte[] ) { |
|
53 |
return value; |
|
54 |
} |
|
55 |
if( value instanceof Geometry ) { |
|
56 |
return ((Geometry)value).convertToWKB(); |
|
57 |
} |
|
58 |
if( previous != null ) { |
|
59 |
return previous.coerce(value); |
|
60 |
} |
|
61 |
} catch (Exception e) { |
|
62 |
throw new CoercionException(e); |
|
63 |
} |
|
64 |
throw new CoercionException(); |
|
65 |
} |
|
66 |
|
|
67 | 61 |
} |
Also available in: Unified diff