Statistics
| Revision:

root / org.gvsig.proj / branches / refactor2018 / org.gvsig.proj / org.gvsig.proj.lib / org.gvsig.proj.lib.api / src / main / java / org / gvsig / fmap / crs / persistence / CoordTransPersistenceFactory.java @ 827

History | View | Annotate | Download (3.1 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.cts.ICoordTrans;
27
import org.cresques.cts.IProjection;
28

    
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
31
import org.gvsig.tools.persistence.PersistentState;
32
import org.gvsig.tools.persistence.exception.PersistenceException;
33

    
34

    
35
/**
36
 * @author gvSIG Team
37
 * @version $Id$
38
 *
39
 */
40
public class CoordTransPersistenceFactory extends AbstractSinglePersistenceFactory {
41

    
42
    private static final String FIELD_SOURCE_PROJECTION = "source";
43
    private static final String DESCRIPTION_SOURCE_PROJECTION  = "Source projection";
44

    
45
    private static final String FIELD_DESTINATION_PROJECTION = "destination";
46
    private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection";
47

    
48
    private static final String DYNCLASS_NAME = "CoordTrans";
49
    private static final String DYNCLASS_DESCRIPTION = "Coordinates Transformation";
50

    
51
    /**
52
     * Creates a new {@link CoordTransPersistenceFactory}.
53
     */
54
    public CoordTransPersistenceFactory() {
55
        super(ICoordTrans.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null);
56

    
57
        DynStruct definition = this.getDefinition();
58

    
59
        definition.addDynFieldObject(FIELD_SOURCE_PROJECTION).setDescription(
60
            DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
61

    
62
        definition.addDynFieldObject(FIELD_DESTINATION_PROJECTION).setDescription(
63
            DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setClassOfValue(IProjection.class);
64
    }
65

    
66
    public Object createFromState(PersistentState state)
67
            throws PersistenceException {
68
        IProjection sourceProjection = (IProjection)state.get(FIELD_SOURCE_PROJECTION);
69
        IProjection destinationProjection = (IProjection)state.get(FIELD_DESTINATION_PROJECTION);
70
        return sourceProjection.getCT(destinationProjection);
71
    }
72

    
73
    public void saveToState(PersistentState state, Object obj)
74
            throws PersistenceException {
75
        state.set(FIELD_SOURCE_PROJECTION, ((ICoordTrans) obj).getPOrig());
76
        state.set(FIELD_DESTINATION_PROJECTION, ((ICoordTrans) obj).getPDest());
77
    }
78
}