Statistics
| Revision:

root / org.gvsig.projection / trunk / org.gvsig.projection.api / src / main / java / org / gvsig / fmap / crs / persistence / ProjectionPersistenceFactory.java @ 431

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

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

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

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

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

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

    
71
                DynStruct definition = this.getDefinition();
72

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

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

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