Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / gvsig / fmap / crs / persistence / ProjectionPersistenceFactory.java @ 40559

History | View | Annotate | Download (3.14 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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.fmap.crs.persistence;
29

    
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.crs.CRSFactory;
32
import org.gvsig.tools.dataTypes.DataTypes;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37
import org.gvsig.tools.persistence.exception.PersistenceException;
38

    
39
/**
40
 * Factory to persist {@link IProjection} objects. The information about the
41
 * {@link IProjection} which will be persisted is its full code, containing all
42
 * required information to be able to reconstruct the {@link IProjection} object
43
 * through the {@link CRSFactory#getCRS(String)} method.
44
 * <p>
45
 * <strong>NOTE:</strong>To activate this factory, it must be instanced and
46
 * registered in the {@link PersistenceManager}. This will be usually performed
47
 * from the project Library.
48
 * </p>
49
 * 
50
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
51
 * @author 2010- <a href="jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> -
52
 *         gvSIG team
53
 */
54
public class ProjectionPersistenceFactory extends
55
                AbstractSinglePersistenceFactory {
56

    
57
        private static final String FIELD_FULLCODE = "fullcode";
58
        private static final String DESCRIPTION_FULLCODE = "Projection abbreviature";
59

    
60
        private static final String DYNCLASS_NAME = "Projection";
61
        private static final String DYNCLASS_DESCRIPTION = "Projection";
62

    
63
        /**
64
         * Creates a new {@link ProjectionPersistenceFactory}.
65
         */
66
        public ProjectionPersistenceFactory() {
67
                super(IProjection.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null,
68
                                null);
69

    
70
                DynStruct definition = this.getDefinition();
71

    
72
                definition.addDynField(FIELD_FULLCODE).setDescription(
73
                                DESCRIPTION_FULLCODE).setMandatory(true).setType(
74
                                DataTypes.STRING);
75
        }
76

    
77
        public Object createFromState(PersistentState state)
78
                        throws PersistenceException {
79
                return CRSFactory.getCRS(state.getString(FIELD_FULLCODE));
80
        }
81

    
82
        public void saveToState(PersistentState state, Object obj)
83
                        throws PersistenceException {
84
                state.set(FIELD_FULLCODE, ((IProjection) obj).getFullCode());
85
        }
86
}