svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultBandDescriptor.java @ 43876
History | View | Annotate | Download (7.3 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 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 |
|
24 |
package org.gvsig.fmap.dal.raster.impl; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.dal.raster.BandAttributeDescriptor; |
31 |
import org.gvsig.fmap.dal.raster.BandDescriptor; |
32 |
import org.gvsig.fmap.dal.raster.RasterStore; |
33 |
import org.gvsig.fmap.dal.raster.spi.BandDescriptorServices; |
34 |
import org.gvsig.fmap.dal.raster.spi.RasterStoreProviderServices; |
35 |
import org.gvsig.raster.lib.buffer.api.NoData; |
36 |
import org.gvsig.tools.ToolsLocator; |
37 |
import org.gvsig.tools.dispose.DisposeUtils; |
38 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
39 |
import org.gvsig.tools.dynobject.DynStruct; |
40 |
import org.gvsig.tools.exception.BaseException; |
41 |
import org.gvsig.tools.persistence.PersistenceManager; |
42 |
import org.gvsig.tools.persistence.PersistentState; |
43 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
44 |
|
45 |
/**
|
46 |
* Default implementation of {@link BandDescriptor}.
|
47 |
*
|
48 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
49 |
*
|
50 |
*/
|
51 |
public class DefaultBandDescriptor extends AbstractDisposable implements BandDescriptorServices { |
52 |
|
53 |
private static final String PERSISTENCE_NAME = "BandDescriptor"; |
54 |
private static final String PERSISTENCE_DESCRIPTION = ""; |
55 |
|
56 |
private static final String BAND_FIELD_NAME = "band"; |
57 |
private static final String BAND_ATTRIBUTE_DESCRIPTORS_FIELD_NAME = "bandAttributeDescriptors"; |
58 |
|
59 |
private List<BandAttributeDescriptor> bandAttributeDescriptors; |
60 |
private int band; |
61 |
private RasterStore store;
|
62 |
private NoData noData;
|
63 |
private int dataType; |
64 |
private String name; |
65 |
private String description; |
66 |
|
67 |
/**
|
68 |
*
|
69 |
* @param band
|
70 |
* @param attributeDescriptors
|
71 |
*/
|
72 |
public DefaultBandDescriptor(RasterStore store, int band, List<BandAttributeDescriptor> attributeDescriptors) { |
73 |
this.band = band;
|
74 |
this.bandAttributeDescriptors = attributeDescriptors;
|
75 |
this.noData = null; |
76 |
this.store = store;
|
77 |
// No debemos incrementar las referencias al store para evitar referencias circulares
|
78 |
// no tiene sentido forzar que no se pueda hacer un dispose del store aqu?.
|
79 |
// ToolsLocator.getDisposableManager().bind(store);
|
80 |
this.name = String.valueOf(this.band); |
81 |
this.description = ""; |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public int getBand() { |
86 |
return this.band; |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public BandAttributeDescriptor get(int index) { |
91 |
if (index >= 0 && index < bandAttributeDescriptors.size()) { |
92 |
return bandAttributeDescriptors.get(index);
|
93 |
} |
94 |
return null; |
95 |
} |
96 |
|
97 |
@Override
|
98 |
public BandAttributeDescriptor get(String name) { |
99 |
for (BandAttributeDescriptor bandAttributeDescriptor : bandAttributeDescriptors) {
|
100 |
if (bandAttributeDescriptor.getName().equals(name)) {
|
101 |
return bandAttributeDescriptor;
|
102 |
} |
103 |
} |
104 |
return null; |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public int size() { |
109 |
return bandAttributeDescriptors.size();
|
110 |
} |
111 |
|
112 |
@Override
|
113 |
public Iterator<BandAttributeDescriptor> iterator() { |
114 |
return bandAttributeDescriptors.iterator();
|
115 |
} |
116 |
|
117 |
public static void registerPersitenceDefinition() { |
118 |
|
119 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
120 |
DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME); |
121 |
|
122 |
if (definition == null) { |
123 |
definition = |
124 |
persistenceManager.addDefinition(BandDescriptor.class, PERSISTENCE_NAME, |
125 |
PERSISTENCE_DESCRIPTION, null, null); |
126 |
definition.addDynFieldInt(BAND_FIELD_NAME); |
127 |
definition.addDynFieldList(BAND_ATTRIBUTE_DESCRIPTORS_FIELD_NAME).setClassOfItems( |
128 |
BandAttributeDescriptor.class); |
129 |
} |
130 |
} |
131 |
|
132 |
@Override
|
133 |
public void saveToState(PersistentState state) throws PersistenceException { |
134 |
state.set(BAND_FIELD_NAME, this.getBand());
|
135 |
state.set(BAND_ATTRIBUTE_DESCRIPTORS_FIELD_NAME, this.bandAttributeDescriptors);
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void loadFromState(PersistentState state) throws PersistenceException { |
140 |
this.band = state.getInt(BAND_FIELD_NAME);
|
141 |
this.bandAttributeDescriptors =
|
142 |
new ArrayList<BandAttributeDescriptor>( |
143 |
state.getList(BAND_ATTRIBUTE_DESCRIPTORS_FIELD_NAME)); |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public Object clone() throws CloneNotSupportedException { |
148 |
|
149 |
DefaultBandDescriptor newBandDescriptor = (DefaultBandDescriptor) super.clone();
|
150 |
|
151 |
newBandDescriptor.bandAttributeDescriptors = |
152 |
new ArrayList<BandAttributeDescriptor>(); |
153 |
|
154 |
for (BandAttributeDescriptor bandAttributeDescriptor : this.bandAttributeDescriptors) { |
155 |
newBandDescriptor.bandAttributeDescriptors.add((BandAttributeDescriptor) bandAttributeDescriptor.clone()); |
156 |
} |
157 |
|
158 |
return newBandDescriptor;
|
159 |
} |
160 |
|
161 |
@Override
|
162 |
public RasterStore getStore() {
|
163 |
return this.store; |
164 |
} |
165 |
|
166 |
@Override
|
167 |
public NoData getNoData() {
|
168 |
return this.noData; |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public void setNoData(NoData noData) { |
173 |
this.noData = noData;
|
174 |
} |
175 |
|
176 |
@Override
|
177 |
protected void doDispose() throws BaseException { |
178 |
// ?Si no tiene sentido hacer un bind en el constructor, lo tiene hacer un dispose aqu??
|
179 |
// Ver comentario en el constructor
|
180 |
// DisposeUtils.disposeQuietly(this.store);
|
181 |
this.store = null; |
182 |
this.bandAttributeDescriptors = null; |
183 |
this.noData = null; |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public BandAttributeDescriptor add(BandAttributeDescriptor bandAttributeDescriptor) {
|
188 |
this.bandAttributeDescriptors.add(bandAttributeDescriptor);
|
189 |
return bandAttributeDescriptor;
|
190 |
} |
191 |
|
192 |
@Override
|
193 |
public BandAttributeDescriptor add(String name, Object value) { |
194 |
BandAttributeDescriptor x = ((RasterStoreProviderServices)this.store).createBandAttributeDescriptor(band, name, value, null, null, null); |
195 |
return x;
|
196 |
} |
197 |
|
198 |
@Override
|
199 |
public int getDataType() { |
200 |
return this.dataType; |
201 |
} |
202 |
|
203 |
@Override
|
204 |
public void setDataType(int dataType) { |
205 |
this.dataType = dataType;
|
206 |
|
207 |
} |
208 |
|
209 |
@Override
|
210 |
public String getName() { |
211 |
return this.name; |
212 |
} |
213 |
|
214 |
@Override
|
215 |
public String getDescription() { |
216 |
return this.description; |
217 |
} |
218 |
|
219 |
@Override
|
220 |
public void setName(String name) { |
221 |
this.name = name;
|
222 |
} |
223 |
|
224 |
@Override
|
225 |
public void setDescription(String description) { |
226 |
this.description = description;
|
227 |
} |
228 |
} |