Revision 32880 branches/v2_0_0_prep/libraries/libProjection/src/org/gvsig/fmap/crs/persistence/ProjectionPersistenceFactory.java
ProjectionPersistenceFactory.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import org.cresques.cts.IProjection; |
30 | 30 |
import org.gvsig.fmap.crs.CRSFactory; |
31 |
import org.gvsig.tools.ToolsLocator; |
|
32 | 31 |
import org.gvsig.tools.dataTypes.DataTypes; |
33 |
import org.gvsig.tools.dynobject.DynField; |
|
34 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
35 | 32 |
import org.gvsig.tools.dynobject.DynStruct; |
36 |
import org.gvsig.tools.persistence.AbstractHierarchyPersistenceFactory; |
|
37 |
import org.gvsig.tools.persistence.PersistenceException; |
|
33 |
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory; |
|
38 | 34 |
import org.gvsig.tools.persistence.PersistenceManager; |
39 | 35 |
import org.gvsig.tools.persistence.PersistentState; |
40 |
import org.slf4j.Logger; |
|
41 |
import org.slf4j.LoggerFactory; |
|
36 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
42 | 37 |
|
43 | 38 |
/** |
44 | 39 |
* Factory to persist {@link IProjection} objects. The information about the |
... | ... | |
51 | 46 |
* from the project Library. |
52 | 47 |
* </p> |
53 | 48 |
* |
54 |
* @author gvSIG Team |
|
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 |
|
55 | 52 |
*/ |
56 | 53 |
public class ProjectionPersistenceFactory extends |
57 |
AbstractHierarchyPersistenceFactory {
|
|
54 |
AbstractSinglePersistenceFactory {
|
|
58 | 55 |
|
59 |
// Persisted atribute name with the projection code
|
|
60 |
private static final String FULLCODE = "fullcode";
|
|
56 |
private static final String FIELD_FULLCODE = "fullcode";
|
|
57 |
private static final String DESCRIPTION_FULLCODE = "Projection abbreviature";
|
|
61 | 58 |
|
62 |
private static final String FULLCODE_DESCRIPTION = "Projection abbreviature"; |
|
59 |
private static final String DYNCLASS_NAME = "Projection"; |
|
60 |
private static final String DYNCLASS_DESCRIPTION = "Projection"; |
|
63 | 61 |
|
64 |
// DynClass name for the IProjection objects |
|
65 |
private static final String PROJ_DYNCLASS_NAME = "Projection"; |
|
66 |
|
|
67 |
private static final String PROJ_DYNCLASS_DESCRIPTION = "Projection"; |
|
68 |
|
|
69 |
private DynStruct projectionDynStruct; |
|
70 |
|
|
71 | 62 |
/** |
72 | 63 |
* Creates a new {@link ProjectionPersistenceFactory}. |
73 | 64 |
*/ |
74 | 65 |
public ProjectionPersistenceFactory() { |
66 |
super(IProjection.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, |
|
67 |
null); |
|
75 | 68 |
|
76 |
// Create the DynStruct related to the IProjection objects persisted |
|
77 |
// data, which will be its full code. |
|
78 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
|
69 |
DynStruct definition = this.getDefinition(); |
|
79 | 70 |
|
80 |
projectionDynStruct = dynman.add(PROJ_DYNCLASS_NAME, |
|
81 |
PROJ_DYNCLASS_DESCRIPTION); |
|
82 |
|
|
83 |
DynField field = projectionDynStruct.addDynField(FULLCODE); |
|
84 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
|
85 |
field.setDescription(FULLCODE_DESCRIPTION); |
|
86 |
field.setMandatory(true); |
|
87 |
field.setType(DataTypes.STRING); |
|
71 |
definition.addDynField(FIELD_FULLCODE).setDescription( |
|
72 |
DESCRIPTION_FULLCODE).setMandatory(true).setType( |
|
73 |
DataTypes.STRING); |
|
88 | 74 |
} |
89 | 75 |
|
90 |
public DynStruct getProjectionDynStruct() { |
|
91 |
return projectionDynStruct; |
|
92 |
} |
|
93 |
|
|
94 |
public Object createFromState(PersistentState state, Class classToUse) |
|
76 |
public Object createFromState(PersistentState state) |
|
95 | 77 |
throws PersistenceException { |
96 |
return CRSFactory.getCRS(state.getString(FULLCODE)); |
|
78 |
return CRSFactory.getCRS(state.getString(FIELD_FULLCODE));
|
|
97 | 79 |
} |
98 | 80 |
|
99 |
public void loadFromState(PersistentState state, Object object) |
|
100 |
throws PersistenceException { |
|
101 |
// Nothing to do here, the Projection object hasn't any more |
|
102 |
// properties to set. |
|
103 |
} |
|
104 |
|
|
105 | 81 |
public void saveToState(PersistentState state, Object obj) |
106 | 82 |
throws PersistenceException { |
107 |
state.set(FULLCODE, ((IProjection) obj).getFullCode()); |
|
83 |
state.set(FIELD_FULLCODE, ((IProjection) obj).getFullCode());
|
|
108 | 84 |
} |
109 |
|
|
110 |
public String getDomainName() { |
|
111 |
// Use the default domain name |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
public String getDomainURL() { |
|
116 |
// Use the default domain url |
|
117 |
return null; |
|
118 |
} |
|
119 |
|
|
120 |
protected Class getParentClass() { |
|
121 |
return IProjection.class; |
|
122 |
} |
|
123 |
|
|
124 |
protected DynStruct getParentClassDefinition() { |
|
125 |
return getProjectionDynStruct(); |
|
126 |
} |
|
127 | 85 |
} |
Also available in: Unified diff