svn-gvsig-desktop / trunk / org.gvsig.desktop / 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 @ 44831
History | View | Annotate | Download (5.15 KB)
1 | 44831 | jjdelcerro | /* 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.SimpleTaskStatus; |
||
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 SimpleTaskStatus 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 SimpleTaskStatus getTaskStatus() {
|
||
75 | if( this.taskStatus==null ) { |
||
76 | TaskStatusManager taskStatusManager = ToolsLocator.getTaskStatusManager(); |
||
77 | this.taskStatus = taskStatusManager.createDefaultSimpleTaskStatus(
|
||
78 | this.getFactory().getName());
|
||
79 | this.taskStatus.setAutoremove(true); |
||
80 | this.taskStatus.add();
|
||
81 | } |
||
82 | return this.taskStatus; |
||
83 | } |
||
84 | |||
85 | @Override
|
||
86 | public void process() throws ProcessingOperationException { |
||
87 | //Nothing to do
|
||
88 | } |
||
89 | |||
90 | @Override
|
||
91 | public void postProcess() throws BufferOperationException { |
||
92 | //Nothing to do
|
||
93 | } |
||
94 | |||
95 | |||
96 | /* (non-Javadoc)
|
||
97 | * @see org.gvsig.raster.lib.buffer.api.Operation#execute(org.gvsig.raster.lib.buffer.api.Buffer, org.gvsig.tools.dynobject.DynObject)
|
||
98 | */
|
||
99 | @Override
|
||
100 | public Buffer execute(SimpleTaskStatus status, Buffer buffer, DynObject parameters) throws BufferOperationException { |
||
101 | this.buffer = buffer;
|
||
102 | this.parameters = parameters;
|
||
103 | this.taskStatus = status;
|
||
104 | try {
|
||
105 | this.taskStatus.push();
|
||
106 | |||
107 | this.preProcess();
|
||
108 | this.process();
|
||
109 | this.postProcess();
|
||
110 | return this.getOutputBuffer(); |
||
111 | } finally {
|
||
112 | if( this.taskStatus.isRunning() ) { |
||
113 | this.taskStatus.terminate();
|
||
114 | } |
||
115 | this.taskStatus.pop();
|
||
116 | } |
||
117 | } |
||
118 | |||
119 | /* (non-Javadoc)
|
||
120 | * @see org.gvsig.raster.lib.buffer.api.Operation#getFactory()
|
||
121 | */
|
||
122 | @Override
|
||
123 | public OperationFactory getFactory() {
|
||
124 | return factory;
|
||
125 | } |
||
126 | |||
127 | /* (non-Javadoc)
|
||
128 | * @see org.gvsig.raster.lib.buffer.spi.OperationServices#getParameters()
|
||
129 | */
|
||
130 | @Override
|
||
131 | public DynObject getParameters() {
|
||
132 | return parameters;
|
||
133 | } |
||
134 | |||
135 | @Override
|
||
136 | public Object getParameter(String name, Object defaultValue) { |
||
137 | if(this.parameters.getDynClass().getDynField(name)!=null) { |
||
138 | return this.getParameters().getDynValue(name); |
||
139 | } |
||
140 | return defaultValue;
|
||
141 | } |
||
142 | |||
143 | @Override
|
||
144 | public void setParameter(String name, Object value) { |
||
145 | this.getParameters().setDynValue(name, value);
|
||
146 | } |
||
147 | |||
148 | /* (non-Javadoc)
|
||
149 | * @see org.gvsig.raster.lib.buffer.spi.OperationServices#getInputBuffer()
|
||
150 | */
|
||
151 | @Override
|
||
152 | public Buffer getInputBuffer() { |
||
153 | return this.buffer; |
||
154 | } |
||
155 | |||
156 | /* (non-Javadoc)
|
||
157 | * @see org.gvsig.raster.lib.buffer.spi.OperationServices#getOutputBuffer()
|
||
158 | */
|
||
159 | @Override
|
||
160 | public Buffer getOutputBuffer() { |
||
161 | return outputBuffer;
|
||
162 | } |
||
163 | |||
164 | @Override
|
||
165 | public void setOutputBuffer(Buffer theOutputBuffer) { |
||
166 | this.outputBuffer = theOutputBuffer;
|
||
167 | } |
||
168 | |||
169 | |||
170 | } |