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 @ 40455
History | View | Annotate | Download (3.09 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {DiSiD Technologies} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.crs.persistence; |
28 |
|
29 |
import org.cresques.cts.IProjection; |
30 |
import org.gvsig.fmap.crs.CRSFactory; |
31 |
import org.gvsig.tools.dataTypes.DataTypes; |
32 |
import org.gvsig.tools.dynobject.DynStruct; |
33 |
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory; |
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
35 |
import org.gvsig.tools.persistence.PersistentState; |
36 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
37 |
|
38 |
/**
|
39 |
* Factory to persist {@link IProjection} objects. The information about the
|
40 |
* {@link IProjection} which will be persisted is its full code, containing all
|
41 |
* required information to be able to reconstruct the {@link IProjection} object
|
42 |
* through the {@link CRSFactory#getCRS(String)} method.
|
43 |
* <p>
|
44 |
* <strong>NOTE:</strong>To activate this factory, it must be instanced and
|
45 |
* registered in the {@link PersistenceManager}. This will be usually performed
|
46 |
* from the project Library.
|
47 |
* </p>
|
48 |
*
|
49 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
50 |
* @author 2010- <a href="jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> -
|
51 |
* gvSIG team
|
52 |
*/
|
53 |
public class ProjectionPersistenceFactory extends |
54 |
AbstractSinglePersistenceFactory { |
55 |
|
56 |
private static final String FIELD_FULLCODE = "fullcode"; |
57 |
private static final String DESCRIPTION_FULLCODE = "Projection abbreviature"; |
58 |
|
59 |
private static final String DYNCLASS_NAME = "Projection"; |
60 |
private static final String DYNCLASS_DESCRIPTION = "Projection"; |
61 |
|
62 |
/**
|
63 |
* Creates a new {@link ProjectionPersistenceFactory}.
|
64 |
*/
|
65 |
public ProjectionPersistenceFactory() {
|
66 |
super(IProjection.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, |
67 |
null);
|
68 |
|
69 |
DynStruct definition = this.getDefinition();
|
70 |
|
71 |
definition.addDynField(FIELD_FULLCODE).setDescription( |
72 |
DESCRIPTION_FULLCODE).setMandatory(true).setType(
|
73 |
DataTypes.STRING); |
74 |
} |
75 |
|
76 |
public Object createFromState(PersistentState state) |
77 |
throws PersistenceException {
|
78 |
return CRSFactory.getCRS(state.getString(FIELD_FULLCODE));
|
79 |
} |
80 |
|
81 |
public void saveToState(PersistentState state, Object obj) |
82 |
throws PersistenceException {
|
83 |
state.set(FIELD_FULLCODE, ((IProjection) obj).getFullCode()); |
84 |
} |
85 |
} |