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 / DefaultBandQuery.java @ 43876
History | View | Annotate | Download (4.29 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.HashMap; |
27 |
import java.util.Map; |
28 |
|
29 |
import org.gvsig.fmap.dal.raster.BandDescriptor; |
30 |
import org.gvsig.fmap.dal.raster.BandQuery; |
31 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dynobject.DynStruct; |
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
35 |
import org.gvsig.tools.persistence.PersistentState; |
36 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
37 |
|
38 |
/**
|
39 |
* Default implementation of {@link BandQuery}.
|
40 |
*
|
41 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
42 |
*
|
43 |
*/
|
44 |
public class DefaultBandQuery implements BandQuery { |
45 |
|
46 |
private static final String PERSISTENCE_NAME = "BandQuery"; |
47 |
private static final String PERSISTENCE_DESCRIPTION = ""; |
48 |
|
49 |
private static final String BAND_FIELD_NAME = "band"; |
50 |
private static final String BAND_DESCRIPTOR_FIELD_NAME = "bandDescriptor"; |
51 |
private static final String VALUES_FIELD_NAME = "values"; |
52 |
|
53 |
private int band; |
54 |
private BandDescriptor bandDescriptor;
|
55 |
private Map<String, Object> values; |
56 |
|
57 |
/**
|
58 |
* Empty constructor
|
59 |
*/
|
60 |
public DefaultBandQuery() {
|
61 |
|
62 |
} |
63 |
|
64 |
/**
|
65 |
* Default constructor
|
66 |
*
|
67 |
* @param band
|
68 |
* Band of this BandQuery
|
69 |
* @param bandDescriptor
|
70 |
* Descriptor of band
|
71 |
*/
|
72 |
public DefaultBandQuery(int band, BandDescriptor bandDescriptor) { |
73 |
super();
|
74 |
this.band = band;
|
75 |
this.bandDescriptor = bandDescriptor;
|
76 |
this.values = new HashMap<String, Object>(); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public int getBand() { |
81 |
return this.band; |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public BandDescriptor getDescriptor() {
|
86 |
return this.bandDescriptor; |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void setValue(String name, Object value) { |
91 |
// TODO Validate name and value
|
92 |
this.values.put(name, value);
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public Object getValue(String name) { |
97 |
return this.values.get(name); |
98 |
} |
99 |
|
100 |
public static void registerPersistenceDefinition(){ |
101 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
102 |
DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME); |
103 |
if(definition == null){ |
104 |
|
105 |
definition = persistenceManager.addDefinition(BandQuery.class, PERSISTENCE_NAME, |
106 |
PERSISTENCE_DESCRIPTION, null, null); |
107 |
definition.addDynFieldInt(BAND_FIELD_NAME); |
108 |
definition.addDynFieldObject(BAND_DESCRIPTOR_FIELD_NAME).setClassOfValue(BandDescriptor.class); |
109 |
definition.addDynFieldMap(VALUES_FIELD_NAME); |
110 |
} |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public void saveToState(PersistentState state) throws PersistenceException { |
115 |
state.set(BAND_FIELD_NAME, this.getBand());
|
116 |
state.set(BAND_DESCRIPTOR_FIELD_NAME, this.getDescriptor());
|
117 |
state.set(VALUES_FIELD_NAME, this.values);
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void loadFromState(PersistentState state) throws PersistenceException { |
122 |
this.band = state.getInt(BAND_FIELD_NAME);
|
123 |
this.bandDescriptor = (BandDescriptor) state.get(BAND_DESCRIPTOR_FIELD_NAME);
|
124 |
this.values = new HashMap<String, Object>(state.getMap(VALUES_FIELD_NAME)); |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public Object clone() throws CloneNotSupportedException { |
129 |
return new DefaultBandQuery(this.band, (BandDescriptor) this.getDescriptor().clone()); |
130 |
} |
131 |
} |