Revision 966
org.gvsig.projection/trunk/org.gvsig.projection.api/src/main/java/org/cresques/coerce/CoerceToCRS.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import org.cresques.cts.IProjection; |
26 | 26 |
import org.gvsig.fmap.crs.CRSFactory; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
27 | 28 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion;
|
|
29 |
import org.gvsig.tools.dataTypes.CoercionContext;
|
|
29 | 30 |
|
30 | 31 |
/** |
31 | 32 |
* Convert a string value of projection code to IProjection |
... | ... | |
34 | 35 |
* @version $Id$ |
35 | 36 |
* |
36 | 37 |
*/ |
37 |
public class CoerceToCRS implements Coercion {
|
|
38 |
public class CoerceToCRS extends AbstractCoercion {
|
|
38 | 39 |
|
39 |
public Object coerce(Object value) throws CoercionException { |
|
40 |
if (value == null) { |
|
41 |
return null;
|
|
40 |
public Object coerce(Object value, CoercionContext context) throws CoercionException {
|
|
41 |
if (value == null || value instanceof IProjection) {
|
|
42 |
return value;
|
|
42 | 43 |
} |
43 | 44 |
try { |
44 |
if (value instanceof IProjection) { |
|
45 |
return value; |
|
46 |
} |
|
47 | 45 |
Object proj = CRSFactory.getCRS(value.toString()); |
48 | 46 |
if (proj == null) { |
49 | 47 |
throw new CoercionException("Can't convert value '" + getValueAsString(value) + "' to IProjection. Probably not a valid format for a projection."); |
org.gvsig.projection/trunk/org.gvsig.projection.api/src/main/java/org/cresques/coerce/CoerceToString.java | ||
---|---|---|
24 | 24 |
package org.cresques.coerce; |
25 | 25 |
|
26 | 26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
27 | 28 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
|
29 |
import org.gvsig.tools.dataTypes.Coercion; |
|
30 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
29 | 31 |
|
30 | 32 |
/** |
31 | 33 |
* Convert a Projection to String. |
... | ... | |
37 | 39 |
* @version $Id$ |
38 | 40 |
* |
39 | 41 |
*/ |
40 |
public class CoerceToString implements Coercion {
|
|
42 |
public class CoerceToString extends AbstractCoercion {
|
|
41 | 43 |
|
42 |
Coercion previous = null; |
|
43 |
|
|
44 | 44 |
public CoerceToString() { |
45 | 45 |
// Do nothing |
46 | 46 |
} |
47 | 47 |
|
48 |
public CoerceToString(Coercion previous) { |
|
49 |
this.previous = previous; |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
public Object coerce(Object value) throws CoercionException { |
|
48 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
49 |
if( value == null || value instanceof String ) { |
|
50 |
return value; |
|
51 |
} |
|
54 | 52 |
try { |
55 |
if( value == null || value instanceof String ) { |
|
56 |
return value; |
|
57 |
} |
|
58 | 53 |
if( value instanceof IProjection ) { |
59 | 54 |
return ((IProjection)value).getFullCode(); |
60 | 55 |
} |
61 |
if( previous != null ) { |
|
62 |
return previous.coerce(value); |
|
63 |
} |
|
64 | 56 |
} catch (Exception e) { |
65 | 57 |
throw new CoercionException(e); |
66 | 58 |
} |
org.gvsig.projection/trunk/org.gvsig.projection.api/src/main/java/org/cresques/ProjectionLibrary.java | ||
---|---|---|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
79 |
dataTypesManager.addtype(DataTypes.CRS, "CRS", "CRS", |
|
80 |
IProjection.class, new CoerceToCRS()); |
|
81 |
dataTypesManager.setCoercion(DataTypes.STRING, new CoerceToString( |
|
82 |
dataTypesManager.getCoercion(DataTypes.STRING))); |
|
79 |
dataTypesManager.addtype( |
|
80 |
DataTypes.CRS, |
|
81 |
"CRS", |
|
82 |
"CRS", |
|
83 |
IProjection.class, |
|
84 |
new CoerceToCRS() |
|
85 |
); |
|
86 |
dataTypesManager.addCoercion(DataTypes.STRING, new CoerceToString()); |
|
83 | 87 |
|
84 | 88 |
// Register the PersistenceFactory to be able to persist |
85 | 89 |
// IProjection objects |
org.gvsig.projection/trunk/org.gvsig.projection.api/pom.xml | ||
---|---|---|
405 | 405 |
<site-repository>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</site-repository> |
406 | 406 |
|
407 | 407 |
<gvsig.projection.svnroot>org.gvsig.projection</gvsig.projection.svnroot> |
408 |
<gvsig.tools.version>3.0.128</gvsig.tools.version>
|
|
408 |
<gvsig.tools.version>3.0.210-SNAPSHOT</gvsig.tools.version>
|
|
409 | 409 |
</properties> |
410 | 410 |
|
411 | 411 |
</project> |
Also available in: Unified diff