gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.raster / org.gvsig.fmap.dal.raster.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultBandAttributeDescriptor.java @ 6302
History | View | Annotate | Download (4.68 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.Collections; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.dal.raster.api.BandAttributeDescriptor; |
31 |
import org.gvsig.tools.ToolsLocator; |
32 |
import org.gvsig.tools.dynobject.DynStruct; |
33 |
import org.gvsig.tools.lang.Cloneable; |
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 BandAttributeDescriptor}.
|
40 |
*
|
41 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
42 |
*
|
43 |
*/
|
44 |
public class DefaultBandAttributeDescriptor implements BandAttributeDescriptor { |
45 |
|
46 |
private static final String PERSISTENCE_NAME = "BandAttributeDescriptor"; |
47 |
private static final String PERSISTENCE_DESCRIPTION = ""; |
48 |
|
49 |
private static final String BAND_FIELD_NAME = "band"; |
50 |
private static final String NAME_FIELD_NAME = "name"; |
51 |
private static final String DESCRIPTION_FIELD_NAME = "description"; |
52 |
private static final String VALUES_FIELD_NAME = "values"; |
53 |
|
54 |
private int band; |
55 |
private String name; |
56 |
private String description; |
57 |
private List<Object> values; |
58 |
|
59 |
/**
|
60 |
*
|
61 |
* @param band
|
62 |
* @param name
|
63 |
* @param description
|
64 |
* @param values
|
65 |
*/
|
66 |
public DefaultBandAttributeDescriptor(int band, String name, String description, |
67 |
List<Object> values) { |
68 |
super();
|
69 |
this.band = band;
|
70 |
this.name = name;
|
71 |
this.values = values;
|
72 |
this.description = description;
|
73 |
} |
74 |
|
75 |
@Override
|
76 |
public int getBand() { |
77 |
return this.band; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public String getName() { |
82 |
return this.name; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public String getDescription() { |
87 |
return this.description; |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public List<Object> getValues() { |
92 |
return Collections.unmodifiableList(this.values); |
93 |
} |
94 |
|
95 |
public static void registerPersitenceDefinition() { |
96 |
|
97 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
98 |
DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME); |
99 |
if (definition == null) { |
100 |
|
101 |
definition = |
102 |
persistenceManager.addDefinition(BandAttributeDescriptor.class, PERSISTENCE_NAME, |
103 |
PERSISTENCE_DESCRIPTION, null, null); |
104 |
definition.addDynFieldInt(BAND_FIELD_NAME); |
105 |
definition.addDynFieldString(NAME_FIELD_NAME); |
106 |
definition.addDynFieldString(DESCRIPTION_FIELD_NAME); |
107 |
definition.addDynFieldList(VALUES_FIELD_NAME).setClassOfItems(Object.class);
|
108 |
} |
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void saveToState(PersistentState state) throws PersistenceException { |
113 |
state.set(BAND_FIELD_NAME, this.getBand());
|
114 |
state.set(NAME_FIELD_NAME, this.getName());
|
115 |
state.set(DESCRIPTION_FIELD_NAME, this.getDescription());
|
116 |
state.set(VALUES_FIELD_NAME, this.getValues());
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public void loadFromState(PersistentState state) throws PersistenceException { |
121 |
this.band = state.getInt(BAND_FIELD_NAME);
|
122 |
this.name = state.getString(NAME_FIELD_NAME);
|
123 |
this.description = state.getString(DESCRIPTION_FIELD_NAME);
|
124 |
this.values = new ArrayList<Object>(state.getList(VALUES_FIELD_NAME)); |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public Object clone() throws CloneNotSupportedException { |
129 |
List<Object> newValues = new ArrayList<Object>(); |
130 |
for (Object object : values) { |
131 |
if( object instanceof Cloneable){ |
132 |
newValues.add(((Cloneable) object).clone());
|
133 |
} else {
|
134 |
newValues.add(object); |
135 |
} |
136 |
} |
137 |
return new DefaultBandAttributeDescriptor(this.band, this.name, this.description, newValues); |
138 |
} |
139 |
} |