root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.lib / org.gvsig.proj.lib.api / src / main / java / org / cresques / coerce / CoerceToString.java @ 827
History | View | Annotate | Download (1.87 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.cresques.coerce; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.tools.dataTypes.CoercionException; |
28 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
29 |
|
30 |
/**
|
31 |
* Convert a Projection to String.
|
32 |
*
|
33 |
* Support convert:
|
34 |
* - Projection to String (do nothing)
|
35 |
*
|
36 |
* @author gvSIG Team
|
37 |
* @version $Id$
|
38 |
*
|
39 |
*/
|
40 |
public class CoerceToString implements Coercion { |
41 |
|
42 |
Coercion previous = null;
|
43 |
|
44 |
public CoerceToString() {
|
45 |
// Do nothing
|
46 |
} |
47 |
|
48 |
public CoerceToString(Coercion previous) {
|
49 |
this.previous = previous;
|
50 |
} |
51 |
|
52 |
|
53 |
public Object coerce(Object value) throws CoercionException { |
54 |
try {
|
55 |
if( value == null || value instanceof String ) { |
56 |
return value;
|
57 |
} |
58 |
if( value instanceof IProjection ) { |
59 |
return ((IProjection)value).getFullCode();
|
60 |
} |
61 |
if( previous != null ) { |
62 |
return previous.coerce(value);
|
63 |
} |
64 |
} catch (Exception e) { |
65 |
throw new CoercionException(e); |
66 |
} |
67 |
throw new CoercionException(); |
68 |
} |
69 |
|
70 |
} |