Revision 2316 org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataParameters.java
AbstractRasterDataParameters.java | ||
---|---|---|
23 | 23 |
package org.gvsig.raster.impl.store; |
24 | 24 |
|
25 | 25 |
import java.io.File; |
26 |
import java.net.URI; |
|
27 |
import java.net.URISyntaxException; |
|
28 | 26 |
|
29 | 27 |
import org.cresques.DataTypes; |
30 | 28 |
import org.cresques.cts.IProjection; |
31 | 29 |
import org.gvsig.fmap.crs.CRSFactory; |
30 |
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer; |
|
32 | 31 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
33 | 32 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.dynobject.DynClass; |
|
36 |
import org.gvsig.tools.dynobject.DynField; |
|
37 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
38 | 33 |
import org.gvsig.tools.dynobject.DynStruct; |
39 |
import org.gvsig.tools.persistence.PersistentState; |
|
40 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
41 | 34 |
|
42 | 35 |
/** |
43 | 36 |
* Base class for all kind of parameters in raster |
... | ... | |
50 | 43 |
public static final String PERSISTENT_NAME = "AbstractRasterDataParameters_Persistent"; |
51 | 44 |
public static final String PERSISTENT_DESCRIPTION = "AbstractRasterDataParameters Persistent"; |
52 | 45 |
|
53 |
//protected static final String FIELD_URI = RasterDataParameters.FIELD_URI; |
|
54 |
//private static final String FIELD_CRS = RasterDataParameters.FIELD_CRS; |
|
55 |
//private static final String FIELD_RMF_FOLDER = RasterDataParameters.FIELD_RMF_FOLDER; |
|
56 | 46 |
private static final String FIELD_FRAME = "frame"; |
57 | 47 |
private static final String FIELD_ALPHABAND = "alphaband"; |
58 | 48 |
private static final String FIELD_VISIBLE = "visible"; |
59 | 49 |
private static final String FIELD_REPROJ_OPTION = "selected_option"; |
60 | 50 |
|
51 |
protected IProjection crs = null; |
|
52 |
|
|
61 | 53 |
|
62 |
public static DynClass registerDynClass(String dynClassName) { |
|
63 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
|
64 |
DynField field; |
|
54 |
public static void registerDynClass(DynStruct definition) { |
|
55 |
definition.addDynFieldString(FIELD_URI) |
|
56 |
.setDescription("Uniform Resource Identifier (File name or URL)") |
|
57 |
.setType(DataTypes.STRING) |
|
58 |
.setMandatory(false); |
|
65 | 59 |
|
66 |
if(dynman == null) |
|
67 |
return null; |
|
60 |
definition.addDynFieldInt(FIELD_FRAME) |
|
61 |
.setDescription("frame") |
|
62 |
.setType(DataTypes.INT) |
|
63 |
.setMandatory(false) |
|
64 |
.setHidden(true); |
|
68 | 65 |
|
69 |
DynClass dynClass = dynman.add(dynClassName); |
|
70 |
|
|
71 |
field = dynClass.addDynFieldString(FIELD_URI); |
|
72 |
field.setDescription("Uniform Resource Identifier (File name or URL)"); |
|
73 |
field.setType(DataTypes.STRING); |
|
74 |
field.setMandatory(false); |
|
75 |
|
|
76 |
field = dynClass.addDynFieldObject(FIELD_CRS); |
|
77 |
field.setDescription("CRS"); |
|
78 |
field.setType(DataTypes.CRS); |
|
79 |
field.setMandatory(false); |
|
80 |
field.setHidden(true); |
|
81 |
|
|
82 |
field = dynClass.addDynFieldInt(FIELD_FRAME); |
|
83 |
field.setDescription("frame"); |
|
84 |
field.setType(DataTypes.INT); |
|
85 |
field.setMandatory(false); |
|
86 |
field.setHidden(true); |
|
87 |
|
|
88 |
field = dynClass.addDynFieldInt(FIELD_ALPHABAND); |
|
89 |
field.setDescription("alphaband"); |
|
90 |
field.setType(DataTypes.INT); |
|
91 |
field.setMandatory(false); |
|
92 |
field.setHidden(true); |
|
66 |
definition.addDynFieldInt(FIELD_ALPHABAND) |
|
67 |
.setDescription("alphaband") |
|
68 |
.setType(DataTypes.INT) |
|
69 |
.setMandatory(false) |
|
70 |
.setHidden(true); |
|
93 | 71 |
|
94 |
field = dynClass.addDynFieldObject(FIELD_VISIBLE); |
|
95 |
field.setDescription("If the boolean in i position is true, that means that the i provider is visible"); |
|
96 |
field.setMandatory(false); |
|
97 |
field.setClassOfValue(Object.class); |
|
98 |
field.setHidden(true); |
|
72 |
definition.addDynFieldBoolean(FIELD_VISIBLE) |
|
73 |
.setDescription("If the boolean in i position is true, that means that the i provider is visible") |
|
74 |
.setMandatory(false) |
|
75 |
.setHidden(true); |
|
99 | 76 |
|
100 |
field = dynClass.addDynFieldInt(FIELD_REPROJ_OPTION);
|
|
101 |
field.setDescription("Reprojection option");
|
|
102 |
field.setType(DataTypes.INT);
|
|
103 |
field.setDefaultFieldValue(new Integer(0));
|
|
104 |
field.setMandatory(false);
|
|
105 |
field.setHidden(true);
|
|
77 |
definition.addDynFieldInt(FIELD_REPROJ_OPTION)
|
|
78 |
.setDescription("Reprojection option")
|
|
79 |
.setType(DataTypes.INT)
|
|
80 |
.setDefaultFieldValue(new Integer(0))
|
|
81 |
.setMandatory(false)
|
|
82 |
.setHidden(true); |
|
106 | 83 |
|
107 |
field = dynClass.addDynFieldObject(FIELD_RMF_FOLDER); |
|
108 |
field.setDescription("Folder to store the RMF file"); |
|
109 |
field.setType(DataTypes.FILE); |
|
110 |
field.setMandatory(false); |
|
111 |
field.setHidden(true); |
|
112 |
|
|
113 |
return dynClass; |
|
84 |
definition.addDynFieldFile(FIELD_RMF_FOLDER) |
|
85 |
.setDescription("Folder to store the RMF file") |
|
86 |
.setMandatory(false) |
|
87 |
.setHidden(true); |
|
114 | 88 |
} |
89 |
|
|
90 |
public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) { |
|
91 |
setRMFFolder(par.getRMFFolder()); |
|
92 |
setReprojectionOption(par.getReprojectionOption()); |
|
93 |
setVisible(par.isVisible()); |
|
94 |
setAlphaBand(par.getAlphaBand()); |
|
95 |
setFrame(par.getFrame()); |
|
96 |
setURI(par.getURI()); |
|
97 |
} |
|
115 | 98 |
|
116 | 99 |
public AbstractRasterDataParameters() { |
117 | 100 |
super(); |
118 | 101 |
} |
119 | 102 |
|
120 |
/* |
|
121 |
* (non-Javadoc) |
|
122 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#setReprojectionOption(int) |
|
123 |
*/ |
|
124 | 103 |
public void setReprojectionOption(int option) { |
125 | 104 |
this.setDynValue(FIELD_REPROJ_OPTION, option); |
126 | 105 |
} |
127 | 106 |
|
128 |
/* |
|
129 |
* (non-Javadoc) |
|
130 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters#getReprojectionOption() |
|
131 |
*/ |
|
132 | 107 |
public int getReprojectionOption() { |
133 | 108 |
Integer b = (Integer)getDynValue(FIELD_REPROJ_OPTION); |
134 | 109 |
if(b != null) |
... | ... | |
157 | 132 |
} |
158 | 133 |
|
159 | 134 |
public String getSRSID() { |
160 |
IProjection srs = (IProjection) getDynValue(FIELD_CRS); |
|
161 |
if (srs == null) { |
|
135 |
if (crs == null) { |
|
162 | 136 |
return null; |
163 | 137 |
} |
164 |
return srs.getAbrev();
|
|
138 |
return crs.getAbrev();
|
|
165 | 139 |
} |
166 | 140 |
|
167 | 141 |
public void setSRSID(String srsid) { |
168 | 142 |
if (srsid == null) { |
169 |
setDynValue(FIELD_CRS, null);
|
|
143 |
crs = null;
|
|
170 | 144 |
} else { |
171 |
setDynValue(FIELD_CRS, CRSFactory.getCRS(srsid));
|
|
145 |
crs = CRSFactory.getCRS(srsid);
|
|
172 | 146 |
} |
173 | 147 |
} |
174 | 148 |
|
175 | 149 |
public void setSRS(IProjection srs) { |
176 |
setDynValue(FIELD_CRS, srs);
|
|
150 |
this.crs = srs;
|
|
177 | 151 |
} |
178 | 152 |
|
179 | 153 |
public IProjection getSRS() { |
180 | 154 |
if (this.getSRSID() == null) { |
181 | 155 |
return null; |
182 | 156 |
} |
183 |
return (IProjection) getDynValue(FIELD_CRS);
|
|
157 |
return crs;
|
|
184 | 158 |
} |
185 | 159 |
|
186 | 160 |
/** |
... | ... | |
235 | 209 |
public boolean isSourceTiled() { |
236 | 210 |
return false; |
237 | 211 |
} |
238 |
|
|
239 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
240 |
String uriString = null; |
|
241 |
try { |
|
242 |
URI uri = state.getURI(FIELD_URI); |
|
243 |
if(uri != null) { |
|
244 |
File file = new File(uri.toString()); |
|
245 |
if(file.isFile() && file.exists()) |
|
246 |
uriString = file.getAbsolutePath(); |
|
247 |
else { |
|
248 |
uriString = uri.toString(); |
|
249 |
if(uri.getScheme() == null || "file".equalsIgnoreCase(uri.getScheme())) |
|
250 |
uriString = uri.getPath(); |
|
251 |
} |
|
252 |
} |
|
253 |
} catch(ClassCastException e) { |
|
254 |
uriString = state.getString(FIELD_URI); |
|
255 |
} |
|
256 |
|
|
257 |
setURI(uriString); |
|
258 |
setSRS((IProjection)state.get(FIELD_CRS)); |
|
259 |
setAlphaBand(state.getInt(FIELD_ALPHABAND)); |
|
260 |
setFrame(state.getInt(FIELD_FRAME)); |
|
261 |
setVisible(state.getBoolean(FIELD_VISIBLE)); |
|
262 |
setRMFFolder(state.getFile(FIELD_RMF_FOLDER)); |
|
263 |
} |
|
264 |
|
|
265 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
266 |
try { |
|
267 |
String uri = getURI(); |
|
268 |
if(uri != null) { |
|
269 |
File file = new File(uri); |
|
270 |
if(file.exists()) |
|
271 |
state.set(FIELD_URI, file.toURI()); |
|
272 |
else |
|
273 |
state.set(FIELD_URI, new URI(uri)); |
|
274 |
} |
|
275 |
} catch (URISyntaxException e) { |
|
276 |
throw new PersistenceException(e); |
|
277 |
} |
|
278 |
state.set(FIELD_CRS, getSRS()); |
|
279 |
state.set(FIELD_ALPHABAND, getAlphaBand()); |
|
280 |
state.set(FIELD_FRAME, getFrame()); |
|
281 |
state.set(FIELD_VISIBLE, isVisible()); |
|
282 |
state.set(FIELD_RMF_FOLDER, getRMFFolder()); |
|
283 |
} |
|
284 |
|
|
285 |
public static void registerPersistence(DynStruct definition) { |
|
286 |
definition.addDynFieldURI(FIELD_URI).setMandatory(false); |
|
287 |
definition.addDynFieldObject(FIELD_CRS).setClassOfValue(IProjection.class).setMandatory(false); |
|
288 |
definition.addDynFieldInt(FIELD_ALPHABAND).setMandatory(false); |
|
289 |
definition.addDynFieldInt(FIELD_FRAME).setMandatory(false); |
|
290 |
definition.addDynFieldBoolean(FIELD_VISIBLE).setMandatory(false); |
|
291 |
definition.addDynFieldFile(FIELD_RMF_FOLDER).setMandatory(false); |
|
292 |
} |
|
293 | 212 |
} |
Also available in: Unified diff