Statistics
| Revision:

root / org.gvsig.projection / trunk / src / main / java / org / gvsig / fmap / crs / persistence / CoordTransPersistenceFactory.java @ 84

History | View | Annotate | Download (3.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.fmap.crs.persistence;
23

    
24
import org.cresques.DataTypes;
25
import org.cresques.cts.ICoordTrans;
26
import org.cresques.cts.IProjection;
27

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

    
33

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

    
41
    private static final String FIELD_SOURCE_PROJECTION = "source";
42
    private static final String DESCRIPTION_SOURCE_PROJECTION  = "Source projection";
43
    
44
    private static final String FIELD_DESTINATION_PROJECTION = "destination";
45
    private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection";
46

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

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

    
56
        DynStruct definition = this.getDefinition();
57

    
58
        definition.addDynField(FIELD_SOURCE_PROJECTION).setDescription(
59
            DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setType(
60
                DataTypes.CRS);
61
        
62
        definition.addDynField(FIELD_DESTINATION_PROJECTION).setDescription(
63
            DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setType(
64
                DataTypes.CRS);
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
}