svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / srs / SRSJsonSerializer.java @ 46086
History | View | Annotate | Download (2.45 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 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, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.srs; |
24 |
|
25 |
import javax.json.JsonObject; |
26 |
import org.apache.commons.lang3.StringUtils; |
27 |
import org.cresques.cts.IProjection; |
28 |
import org.gvsig.fmap.crs.CRSFactory; |
29 |
import org.gvsig.json.Json; |
30 |
import org.gvsig.json.JsonManager; |
31 |
import org.gvsig.json.JsonObjectBuilder; |
32 |
import org.gvsig.tools.util.IsApplicable; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author gvSIG Team
|
37 |
*/
|
38 |
public class SRSJsonSerializer implements JsonManager.JsonSerializer, IsApplicable { |
39 |
|
40 |
@Override
|
41 |
public Class getObjectClass() { |
42 |
return IProjection.class;
|
43 |
} |
44 |
|
45 |
@Override
|
46 |
public Object toObject(JsonObject json) { |
47 |
IProjection proj = CRSFactory.getCRS(json.getString("fullcode"));
|
48 |
return proj;
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public JsonObjectBuilder toJsonBuilder(Object value) { |
53 |
IProjection proj = (IProjection) value; |
54 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
55 |
builder.add_class(IProjection.class); |
56 |
builder.add("abrev", proj.getAbrev());
|
57 |
builder.add("fullcode", proj.getFullCode());
|
58 |
return builder;
|
59 |
} |
60 |
|
61 |
@Override
|
62 |
public boolean isApplicable(Object... args) { |
63 |
if( args[0] instanceof IProjection) { |
64 |
return true; |
65 |
} |
66 |
if( !(args[0] instanceof JsonObject) ) { |
67 |
return false; |
68 |
} |
69 |
JsonObject json = (JsonObject) args[0];
|
70 |
String className = json.getString(JsonManager.ATTRIBUTE_NAME_CLASS, null); |
71 |
return StringUtils.equalsIgnoreCase(className, IProjection.class.getName());
|
72 |
} |
73 |
|
74 |
public static void selfRegister() { |
75 |
Json.registerSerializer(new SRSJsonSerializer());
|
76 |
} |
77 |
|
78 |
} |