Revision 2130 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/ProcessParamsManagement.java
ProcessParamsManagement.java | ||
---|---|---|
22 | 22 |
package org.gvsig.raster.algorithm.process; |
23 | 23 |
|
24 | 24 |
import java.util.ArrayList; |
25 |
import java.util.HashMap; |
|
25 | 26 |
import java.util.Hashtable; |
26 | 27 |
import java.util.Iterator; |
27 | 28 |
import java.util.List; |
... | ... | |
41 | 42 |
* @author Nacho Brodin nachobrodin@gmail.com |
42 | 43 |
*/ |
43 | 44 |
public abstract class ProcessParamsManagement extends ProcessUtils implements IIncrementable, IncrementableListener, Runnable, Disposable { |
45 |
//*********************** |
|
46 |
//Global input parameters |
|
47 |
//*********************** |
|
48 |
|
|
49 |
/** |
|
50 |
* Input parameter: If is defined then the ROIs will be used |
|
51 |
*/ |
|
52 |
public static String ROI_EPSG = "ROI_EPSG"; |
|
53 |
/** |
|
54 |
* Input parameter: Force to this bounding box. If is defined, then ROI_EPSG is not taken into account |
|
55 |
*/ |
|
56 |
public static String WINDOW = "WINDOW"; |
|
57 |
|
|
58 |
//************************ |
|
59 |
//Global output parameters |
|
60 |
//*********************** |
|
61 |
|
|
62 |
/** |
|
63 |
* Output parameter: The getResult sets the correct value in the output. |
|
64 |
*/ |
|
44 | 65 |
public static String TIME = "TIME"; |
66 |
/** |
|
67 |
* Output parameter: The getResult sets the correct value in the output. |
|
68 |
*/ |
|
45 | 69 |
public static String PROCESS = "PROCESS"; |
70 |
/** |
|
71 |
* Output parameter: The getResult sets the correct value in the output. |
|
72 |
*/ |
|
46 | 73 |
public static String PROCESS_NAME = "PROCESS_NAME"; |
47 |
|
|
48 |
protected Hashtable<String, Object> taskParams = new Hashtable<String, Object>(); |
|
74 |
|
|
49 | 75 |
public static final String REGISTER_INPUT_PARAMETERS_LABEL = "RasterProcessInputParam"; |
50 | 76 |
public static final String REGISTER_OUTPUT_PARAMETERS_LABEL = "RasterProcessOutputParam"; |
77 |
|
|
78 |
private Extent outputWindow = null; |
|
79 |
private String roiEPSG = null; |
|
51 | 80 |
|
81 |
protected Hashtable<String, Object> inputParameters = new Hashtable<String, Object>(); |
|
82 |
protected HashMap<String, Object> outputParameters = new HashMap<String, Object>(); |
|
83 |
|
|
52 | 84 |
/** |
53 | 85 |
* Registers input parameters of a raster process |
54 | 86 |
*/ |
... | ... | |
70 | 102 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
71 | 103 |
ExtensionPoint point = extensionPoints.add(type + "_" + processLabel); |
72 | 104 |
point.append(parameterLabel, "", parameterClass); |
105 |
registerGlobalInputParameters(parameterLabel, parameterClass, processLabel); |
|
73 | 106 |
registerGlobalOutputParameters(parameterLabel, parameterClass, processLabel); |
74 | 107 |
} |
75 | 108 |
|
109 |
public static void registerGlobalInputParameters(String parameterLabel, Class<?> parameterClass, String processLabel) { |
|
110 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
111 |
ExtensionPoint point = extensionPoints.add(REGISTER_INPUT_PARAMETERS_LABEL + "_" + processLabel); |
|
112 |
if(!point.has(ROI_EPSG)) |
|
113 |
point.append(ROI_EPSG, "", Long.class); |
|
114 |
if(!point.has(WINDOW)) |
|
115 |
point.append(WINDOW, "", DataProcess.class); |
|
116 |
} |
|
117 |
|
|
76 | 118 |
public static void registerGlobalOutputParameters(String parameterLabel, Class<?> parameterClass, String processLabel) { |
77 | 119 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
78 | 120 |
ExtensionPoint point = extensionPoints.add(REGISTER_OUTPUT_PARAMETERS_LABEL + "_" + processLabel); |
79 |
if(!point.has(TIME) && !point.has(PROCESS)) {
|
|
121 |
if(!point.has(TIME))
|
|
80 | 122 |
point.append(TIME, "", Long.class); |
123 |
if(!point.has(PROCESS)) |
|
81 | 124 |
point.append(PROCESS, "", DataProcess.class); |
125 |
if(!point.has(PROCESS_NAME)) |
|
82 | 126 |
point.append(PROCESS_NAME, "", String.class); |
83 |
} |
|
84 | 127 |
} |
85 | 128 |
|
86 | 129 |
/** |
... | ... | |
139 | 182 |
|
140 | 183 |
@Override |
141 | 184 |
protected void finalize() throws Throwable { |
142 |
if(taskParams != null) {
|
|
143 |
taskParams.clear();
|
|
144 |
taskParams = null;
|
|
185 |
if(inputParameters != null) {
|
|
186 |
inputParameters.clear();
|
|
187 |
inputParameters = null;
|
|
145 | 188 |
} |
146 | 189 |
super.finalize(); |
147 | 190 |
} |
... | ... | |
154 | 197 |
*/ |
155 | 198 |
public void addParam(String key, Object param) { |
156 | 199 |
if (param != null) |
157 |
taskParams.put(key, param);
|
|
200 |
inputParameters.put(key, param);
|
|
158 | 201 |
else |
159 |
taskParams.remove(key);
|
|
202 |
inputParameters.remove(key);
|
|
160 | 203 |
} |
161 | 204 |
|
162 | 205 |
/** |
... | ... | |
164 | 207 |
* @param name key |
165 | 208 |
*/ |
166 | 209 |
public void removeParam(String key) { |
167 |
taskParams.remove(key);
|
|
210 |
inputParameters.remove(key);
|
|
168 | 211 |
} |
169 | 212 |
|
170 | 213 |
/** |
... | ... | |
173 | 216 |
* @return parameter |
174 | 217 |
*/ |
175 | 218 |
public Object getParam(String key) { |
176 |
return taskParams.get(key);
|
|
219 |
return inputParameters.get(key);
|
|
177 | 220 |
} |
178 | 221 |
|
179 | 222 |
/** |
... | ... | |
182 | 225 |
* @return parameter |
183 | 226 |
*/ |
184 | 227 |
public String getStringParam(String key) { |
185 |
Object value = taskParams.get(key);
|
|
228 |
Object value = inputParameters.get(key);
|
|
186 | 229 |
return (value != null && value instanceof String) ? (String)value : null; |
187 | 230 |
} |
188 | 231 |
|
... | ... | |
192 | 235 |
* @return parameter |
193 | 236 |
*/ |
194 | 237 |
public byte getByteParam(String name) { |
195 |
Object value = taskParams.get(name);
|
|
238 |
Object value = inputParameters.get(name);
|
|
196 | 239 |
return (value != null && value instanceof Byte) ? ((Byte)value).byteValue() : 0; |
197 | 240 |
} |
198 | 241 |
|
... | ... | |
202 | 245 |
* @return parameter |
203 | 246 |
*/ |
204 | 247 |
public float getFloatParam(String name) { |
205 |
Object value = taskParams.get(name);
|
|
248 |
Object value = inputParameters.get(name);
|
|
206 | 249 |
return (value != null && value instanceof Float) ? ((Float)value).floatValue() : 0F; |
207 | 250 |
} |
208 | 251 |
|
... | ... | |
212 | 255 |
* @return parameter |
213 | 256 |
*/ |
214 | 257 |
public double getDoubleParam(String name) { |
215 |
Object value = taskParams.get(name);
|
|
258 |
Object value = inputParameters.get(name);
|
|
216 | 259 |
return (value != null && value instanceof Double) ? ((Double)value).doubleValue() : 0D; |
217 | 260 |
} |
218 | 261 |
|
... | ... | |
222 | 265 |
* @return parameter |
223 | 266 |
*/ |
224 | 267 |
public int getIntParam(String name) { |
225 |
Object value = taskParams.get(name);
|
|
268 |
Object value = inputParameters.get(name);
|
|
226 | 269 |
return (value != null && value instanceof Integer) ? ((Integer)value).intValue() : 0; |
227 | 270 |
} |
228 | 271 |
|
... | ... | |
232 | 275 |
* @return parameter |
233 | 276 |
*/ |
234 | 277 |
public boolean getBooleanParam(String name) { |
235 |
Object value = taskParams.get(name);
|
|
278 |
Object value = inputParameters.get(name);
|
|
236 | 279 |
return (value != null && value instanceof Boolean) ? ((Boolean)value).booleanValue() : false; |
237 | 280 |
} |
238 | 281 |
|
... | ... | |
242 | 285 |
* @return parameter |
243 | 286 |
*/ |
244 | 287 |
public int[] getIntArrayParam(String name) { |
245 |
Object value = taskParams.get(name);
|
|
288 |
Object value = inputParameters.get(name);
|
|
246 | 289 |
return (value != null && value instanceof int[]) ? ((int[])value) : null; |
247 | 290 |
} |
248 | 291 |
|
... | ... | |
252 | 295 |
* @return parameter |
253 | 296 |
*/ |
254 | 297 |
public double[] getDoubleArrayParam(String name) { |
255 |
Object value = taskParams.get(name);
|
|
298 |
Object value = inputParameters.get(name);
|
|
256 | 299 |
return (value != null && value instanceof double[]) ? ((double[])value) : null; |
257 | 300 |
} |
258 | 301 |
|
... | ... | |
262 | 305 |
* @return parameter |
263 | 306 |
*/ |
264 | 307 |
public Extent getExtentParam(String name) { |
265 |
Object value = taskParams.get(name);
|
|
308 |
Object value = inputParameters.get(name);
|
|
266 | 309 |
return (value != null && value instanceof Extent) ? ((Extent)value) : null; |
267 | 310 |
} |
311 |
|
|
312 |
/** |
|
313 |
* Gets the default EPSG for the regions of interest. If this parameter is null |
|
314 |
* @return |
|
315 |
*/ |
|
316 |
protected String getROIEPSG() { |
|
317 |
return roiEPSG; |
|
318 |
} |
|
319 |
|
|
320 |
/** |
|
321 |
* Gets the bounding box defined by the user to the process |
|
322 |
* @return |
|
323 |
*/ |
|
324 |
protected Extent getOutputWindow() { |
|
325 |
return outputWindow; |
|
326 |
} |
|
327 |
|
|
328 |
/** |
|
329 |
* Loads global parameters defined in this class |
|
330 |
*/ |
|
331 |
protected void loadGlobalParameters() { |
|
332 |
roiEPSG = getStringParam(ROI_EPSG); |
|
333 |
outputWindow = getParam(WINDOW) != null ? (Extent)getParam(WINDOW) : null; |
|
334 |
} |
|
268 | 335 |
} |
Also available in: Unified diff