root / org.gvsig.projection / trunk / org.gvsig.projection.api / src / main / java / org / gvsig / fmap / crs / persistence / CoordTransPersistenceFactory.java @ 259
History | View | Annotate | Download (3.13 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.gvsig.fmap.crs.persistence; |
25 |
|
26 |
import org.cresques.DataTypes; |
27 |
import org.cresques.cts.ICoordTrans; |
28 |
import org.cresques.cts.IProjection; |
29 |
|
30 |
import org.gvsig.tools.dynobject.DynStruct; |
31 |
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory; |
32 |
import org.gvsig.tools.persistence.PersistentState; |
33 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
34 |
|
35 |
|
36 |
/**
|
37 |
* @author gvSIG Team
|
38 |
* @version $Id$
|
39 |
*
|
40 |
*/
|
41 |
public class CoordTransPersistenceFactory extends AbstractSinglePersistenceFactory { |
42 |
|
43 |
private static final String FIELD_SOURCE_PROJECTION = "source"; |
44 |
private static final String DESCRIPTION_SOURCE_PROJECTION = "Source projection"; |
45 |
|
46 |
private static final String FIELD_DESTINATION_PROJECTION = "destination"; |
47 |
private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection"; |
48 |
|
49 |
private static final String DYNCLASS_NAME = "CoordTrans"; |
50 |
private static final String DYNCLASS_DESCRIPTION = "Coordinates Transformation"; |
51 |
|
52 |
/**
|
53 |
* Creates a new {@link CoordTransPersistenceFactory}.
|
54 |
*/
|
55 |
public CoordTransPersistenceFactory() {
|
56 |
super(ICoordTrans.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null); |
57 |
|
58 |
DynStruct definition = this.getDefinition();
|
59 |
|
60 |
definition.addDynFieldObject(FIELD_SOURCE_PROJECTION).setDescription( |
61 |
DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
|
62 |
|
63 |
definition.addDynFieldObject(FIELD_DESTINATION_PROJECTION).setDescription( |
64 |
DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
|
65 |
} |
66 |
|
67 |
public Object createFromState(PersistentState state) |
68 |
throws PersistenceException {
|
69 |
IProjection sourceProjection = (IProjection)state.get(FIELD_SOURCE_PROJECTION); |
70 |
IProjection destinationProjection = (IProjection)state.get(FIELD_DESTINATION_PROJECTION); |
71 |
return sourceProjection.getCT(destinationProjection);
|
72 |
} |
73 |
|
74 |
public void saveToState(PersistentState state, Object obj) |
75 |
throws PersistenceException {
|
76 |
state.set(FIELD_SOURCE_PROJECTION, ((ICoordTrans) obj).getPOrig()); |
77 |
state.set(FIELD_DESTINATION_PROJECTION, ((ICoordTrans) obj).getPDest()); |
78 |
} |
79 |
} |