svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer.spi / src / main / java / org / gvsig / raster / lib / buffer / spi / operations / AbstractOperation.java @ 43865
History | View | Annotate | Download (4.8 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.raster.lib.buffer.spi.operations; |
24 |
|
25 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
26 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
27 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
28 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
29 |
import org.gvsig.tools.ToolsLocator; |
30 |
import org.gvsig.tools.dynobject.DynObject; |
31 |
import org.gvsig.tools.task.TaskStatus; |
32 |
import org.gvsig.tools.task.TaskStatusManager; |
33 |
|
34 |
|
35 |
/**
|
36 |
* @author fdiaz
|
37 |
*
|
38 |
*/
|
39 |
public abstract class AbstractOperation implements OperationServices { |
40 |
|
41 |
static public String COPY_UNPROCESSED_BANDS_PARAM = "copy_unprocessed_bands"; |
42 |
|
43 |
private Buffer buffer; |
44 |
private DynObject parameters;
|
45 |
private Buffer outputBuffer; |
46 |
private final OperationFactory factory; |
47 |
private TaskStatus taskStatus;
|
48 |
|
49 |
private boolean copyUnprocessedBands; |
50 |
|
51 |
/**
|
52 |
*
|
53 |
* @param factory
|
54 |
*/
|
55 |
protected AbstractOperation(OperationFactory factory) {
|
56 |
this.factory = factory;
|
57 |
} |
58 |
|
59 |
protected boolean mustCopyUnprocessedBands() { |
60 |
return copyUnprocessedBands;
|
61 |
} |
62 |
|
63 |
@Override
|
64 |
public void preProcess() throws BufferOperationException { |
65 |
if (this.parameters.getDynClass().getDynField(COPY_UNPROCESSED_BANDS_PARAM) != null |
66 |
&& this.parameters.hasDynValue(COPY_UNPROCESSED_BANDS_PARAM)) {
|
67 |
copyUnprocessedBands = (Boolean) this.parameters.getDynValue(COPY_UNPROCESSED_BANDS_PARAM); |
68 |
} else {
|
69 |
copyUnprocessedBands = true;
|
70 |
} |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public TaskStatus getTaskStatus() {
|
75 |
if( this.taskStatus==null ) { |
76 |
TaskStatusManager taskStatusManager = ToolsLocator.getTaskStatusManager(); |
77 |
this.taskStatus = taskStatusManager.createDefaultSimpleTaskStatus(
|
78 |
this.getFactory().getName());
|
79 |
} |
80 |
return this.taskStatus; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void process() throws ProcessingOperationException { |
85 |
//Nothing to do
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void postProcess() throws BufferOperationException { |
90 |
//Nothing to do
|
91 |
} |
92 |
|
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see org.gvsig.raster.lib.buffer.api.Operation#execute(org.gvsig.raster.lib.buffer.api.Buffer, org.gvsig.tools.dynobject.DynObject)
|
96 |
*/
|
97 |
@Override
|
98 |
public Buffer execute(TaskStatus status, Buffer buffer, DynObject parameters) throws BufferOperationException { |
99 |
this.buffer = buffer;
|
100 |
this.parameters = parameters;
|
101 |
this.taskStatus = status;
|
102 |
this.preProcess();
|
103 |
this.process();
|
104 |
this.postProcess();
|
105 |
return this.getOutputBuffer(); |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.raster.lib.buffer.api.Operation#getFactory()
|
110 |
*/
|
111 |
@Override
|
112 |
public OperationFactory getFactory() {
|
113 |
return factory;
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see org.gvsig.raster.lib.buffer.spi.OperationServices#getParameters()
|
118 |
*/
|
119 |
@Override
|
120 |
public DynObject getParameters() {
|
121 |
return parameters;
|
122 |
} |
123 |
|
124 |
@Override
|
125 |
public Object getParameter(String name, Object defaultValue) { |
126 |
if(this.parameters.getDynClass().getDynField(name)!=null) { |
127 |
return this.getParameters().getDynValue(name); |
128 |
} |
129 |
return defaultValue;
|
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void setParameter(String name, Object value) { |
134 |
this.getParameters().setDynValue(name, value);
|
135 |
} |
136 |
|
137 |
/* (non-Javadoc)
|
138 |
* @see org.gvsig.raster.lib.buffer.spi.OperationServices#getInputBuffer()
|
139 |
*/
|
140 |
@Override
|
141 |
public Buffer getInputBuffer() { |
142 |
return this.buffer; |
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.raster.lib.buffer.spi.OperationServices#getOutputBuffer()
|
147 |
*/
|
148 |
@Override
|
149 |
public Buffer getOutputBuffer() { |
150 |
return outputBuffer;
|
151 |
} |
152 |
|
153 |
@Override
|
154 |
public void setOutputBuffer(Buffer theOutputBuffer) { |
155 |
this.outputBuffer = theOutputBuffer;
|
156 |
} |
157 |
|
158 |
|
159 |
} |