svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / DefaultFeatureProvider.java @ 40559
History | View | Annotate | Download (5.89 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2008 {{Company}} {{Task}}
|
||
27 | */
|
||
28 | |||
29 | package org.gvsig.fmap.dal.feature.spi; |
||
30 | |||
31 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
32 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
33 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
34 | import org.gvsig.fmap.geom.Geometry; |
||
35 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
36 | |||
37 | /**
|
||
38 | * Default implementation for {@link FeatureProvider}
|
||
39 | *
|
||
40 | */
|
||
41 | public class DefaultFeatureProvider implements FeatureProvider { |
||
42 | |||
43 | protected FeatureType featureType;
|
||
44 | protected boolean[] nulls; |
||
45 | protected Object[] values; |
||
46 | protected Geometry defaultGeometry;
|
||
47 | protected Envelope envelope;
|
||
48 | private Object oid; |
||
49 | private boolean isNew=false; |
||
50 | |||
51 | public DefaultFeatureProvider(FeatureType type) {
|
||
52 | if (type instanceof EditableFeatureType) { |
||
53 | throw new IllegalArgumentException("type can't by editable."); |
||
54 | } |
||
55 | this.featureType = type;
|
||
56 | this.values = new Object[featureType.size()]; |
||
57 | this.nulls = new boolean[featureType.size()]; |
||
58 | |||
59 | this.envelope = null; |
||
60 | this.defaultGeometry = null; |
||
61 | this.oid = null; |
||
62 | } |
||
63 | |||
64 | public DefaultFeatureProvider(FeatureType type, Object oid) { |
||
65 | this(type);
|
||
66 | this.oid = oid;
|
||
67 | } |
||
68 | |||
69 | /*
|
||
70 | * (non-Javadoc)
|
||
71 | *
|
||
72 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(int,
|
||
73 | * java.lang.Object)
|
||
74 | */
|
||
75 | public void set(int i, Object value) { |
||
76 | if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
||
77 | defaultGeometry = (Geometry) value; |
||
78 | envelope = null;
|
||
79 | } |
||
80 | if (value == null) { |
||
81 | nulls[i] = true;
|
||
82 | values[i] = featureType.getAttributeDescriptor(i).getDefaultValue(); |
||
83 | } else {
|
||
84 | values[i] = value; |
||
85 | nulls[i] = false;
|
||
86 | } |
||
87 | } |
||
88 | |||
89 | /*
|
||
90 | * (non-Javadoc)
|
||
91 | *
|
||
92 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
||
93 | * java.lang.Object)
|
||
94 | */
|
||
95 | public void set(String name, Object value) { |
||
96 | set(featureType.getIndex(name), value); |
||
97 | } |
||
98 | |||
99 | /*
|
||
100 | * (non-Javadoc)
|
||
101 | *
|
||
102 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
||
103 | */
|
||
104 | public Object get(int i) { |
||
105 | return values[i];
|
||
106 | } |
||
107 | |||
108 | /*
|
||
109 | * (non-Javadoc)
|
||
110 | *
|
||
111 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
||
112 | */
|
||
113 | public Object get(String name) { |
||
114 | FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name); |
||
115 | return values[featureAttributeDescriptor.getIndex()];
|
||
116 | } |
||
117 | |||
118 | /*
|
||
119 | * (non-Javadoc)
|
||
120 | *
|
||
121 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
||
122 | */
|
||
123 | public FeatureType getType() {
|
||
124 | return featureType;
|
||
125 | } |
||
126 | |||
127 | /*
|
||
128 | * (non-Javadoc)
|
||
129 | *
|
||
130 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
||
131 | */
|
||
132 | public FeatureProvider getCopy() {
|
||
133 | DefaultFeatureProvider data = new DefaultFeatureProvider(
|
||
134 | this.getType());
|
||
135 | return getCopy(data);
|
||
136 | } |
||
137 | |||
138 | /**
|
||
139 | * Copy values from current instance to <code>data</code>
|
||
140 | */
|
||
141 | protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
||
142 | data.oid = this.oid;
|
||
143 | System.arraycopy(this.values, 0, data.values, 0, this.values.length); |
||
144 | data.defaultGeometry = this.defaultGeometry;
|
||
145 | data.envelope = this.envelope;
|
||
146 | data.isNew=this.isNew;
|
||
147 | return data;
|
||
148 | } |
||
149 | |||
150 | /*
|
||
151 | * (non-Javadoc)
|
||
152 | *
|
||
153 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
||
154 | */
|
||
155 | public Envelope getDefaultEnvelope() {
|
||
156 | if (envelope == null && defaultGeometry != null) { |
||
157 | envelope = defaultGeometry.getEnvelope(); |
||
158 | } |
||
159 | return envelope;
|
||
160 | } |
||
161 | |||
162 | /*
|
||
163 | * (non-Javadoc)
|
||
164 | *
|
||
165 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
||
166 | */
|
||
167 | public Geometry getDefaultGeometry() {
|
||
168 | return this.defaultGeometry; |
||
169 | } |
||
170 | |||
171 | /*
|
||
172 | * (non-Javadoc)
|
||
173 | *
|
||
174 | * @see
|
||
175 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org
|
||
176 | * .gvsig.fmap.geom.primitive.Envelope)
|
||
177 | */
|
||
178 | public void setDefaultEnvelope(Envelope envelope) { |
||
179 | this.envelope = envelope;
|
||
180 | } |
||
181 | |||
182 | /*
|
||
183 | * (non-Javadoc)
|
||
184 | *
|
||
185 | * @see
|
||
186 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultGeometry(org
|
||
187 | * .gvsig.fmap.geom.Geometry)
|
||
188 | */
|
||
189 | public void setDefaultGeometry(Geometry geom) { |
||
190 | int i = featureType.getDefaultGeometryAttributeIndex();
|
||
191 | defaultGeometry = geom; |
||
192 | envelope = null;
|
||
193 | values[i] = geom; |
||
194 | } |
||
195 | |||
196 | /*
|
||
197 | * (non-Javadoc)
|
||
198 | *
|
||
199 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(int)
|
||
200 | */
|
||
201 | public boolean isNull(int i) { |
||
202 | return nulls[i];
|
||
203 | } |
||
204 | |||
205 | /*
|
||
206 | * (non-Javadoc)
|
||
207 | *
|
||
208 | * @see
|
||
209 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String)
|
||
210 | */
|
||
211 | public boolean isNull(String name) { |
||
212 | int i = featureType.getIndex(name);
|
||
213 | return isNull(i);
|
||
214 | } |
||
215 | |||
216 | /*
|
||
217 | * (non-Javadoc)
|
||
218 | *
|
||
219 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID()
|
||
220 | */
|
||
221 | public Object getOID() { |
||
222 | return this.oid; |
||
223 | } |
||
224 | |||
225 | /*
|
||
226 | * (non-Javadoc)
|
||
227 | *
|
||
228 | * @see
|
||
229 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object)
|
||
230 | */
|
||
231 | public void setOID(Object oid) { |
||
232 | this.oid = oid;
|
||
233 | } |
||
234 | |||
235 | /*
|
||
236 | * (non-Javadoc)
|
||
237 | *
|
||
238 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew()
|
||
239 | */
|
||
240 | public boolean isNew(){ |
||
241 | return isNew;
|
||
242 | } |
||
243 | |||
244 | /*
|
||
245 | * (non-Javadoc)
|
||
246 | *
|
||
247 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean)
|
||
248 | */
|
||
249 | public void setNew(boolean isNew){ |
||
250 | this.isNew=isNew;
|
||
251 | } |
||
252 | } |