root / branches / dal_time_support / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / spi / DefaultFeatureProvider.java @ 35983
History | View | Annotate | Download (5.84 KB)
1 | 29391 | jmvivo | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
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 | * as published by the Free Software Foundation; either version 2
|
||
9 | * 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 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 {{Company}} {{Task}}
|
||
26 | */
|
||
27 | |||
28 | 24496 | jmvivo | package org.gvsig.fmap.dal.feature.spi; |
29 | 23754 | jjdelcerro | |
30 | 24496 | jmvivo | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
31 | 34629 | jpiera | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
32 | 24496 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureType; |
33 | 23754 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
34 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
35 | |||
36 | 29391 | jmvivo | /**
|
37 | * Default implementation for {@link FeatureProvider}
|
||
38 | *
|
||
39 | */
|
||
40 | 29289 | jmvivo | public class DefaultFeatureProvider implements FeatureProvider { |
41 | 23754 | jjdelcerro | |
42 | 27758 | cordinyana | protected FeatureType featureType;
|
43 | 23874 | jjdelcerro | protected boolean[] nulls; |
44 | 23754 | jjdelcerro | protected Object[] values; |
45 | protected Geometry defaultGeometry;
|
||
46 | 23874 | jjdelcerro | protected Envelope envelope;
|
47 | 24248 | jjdelcerro | private Object oid; |
48 | 25616 | vcaballero | private boolean isNew=false; |
49 | 23754 | jjdelcerro | |
50 | 29289 | jmvivo | public DefaultFeatureProvider(FeatureType type) {
|
51 | 23754 | jjdelcerro | if (type instanceof EditableFeatureType) { |
52 | throw new IllegalArgumentException("type can't by editable."); |
||
53 | } |
||
54 | 29391 | jmvivo | this.featureType = type;
|
55 | 23754 | jjdelcerro | this.values = new Object[featureType.size()]; |
56 | 23874 | jjdelcerro | this.nulls = new boolean[featureType.size()]; |
57 | 25609 | vcaballero | |
58 | this.envelope = null; |
||
59 | this.defaultGeometry = null; |
||
60 | this.oid = null; |
||
61 | 23754 | jjdelcerro | } |
62 | |||
63 | 29289 | jmvivo | public DefaultFeatureProvider(FeatureType type, Object oid) { |
64 | 25609 | vcaballero | this(type);
|
65 | this.oid = oid;
|
||
66 | } |
||
67 | 29391 | jmvivo | |
68 | /*
|
||
69 | * (non-Javadoc)
|
||
70 | *
|
||
71 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(int,
|
||
72 | * java.lang.Object)
|
||
73 | */
|
||
74 | 23754 | jjdelcerro | public void set(int i, Object value) { |
75 | 23874 | jjdelcerro | if (featureType.getDefaultGeometryAttributeIndex() == i) {
|
76 | defaultGeometry = (Geometry) value; |
||
77 | envelope = null;
|
||
78 | } |
||
79 | if (value == null) { |
||
80 | nulls[i] = true;
|
||
81 | values[i] = featureType.getAttributeDescriptor(i).getDefaultValue(); |
||
82 | } else {
|
||
83 | values[i] = value; |
||
84 | nulls[i] = false;
|
||
85 | } |
||
86 | 23754 | jjdelcerro | } |
87 | |||
88 | 29391 | jmvivo | /*
|
89 | * (non-Javadoc)
|
||
90 | *
|
||
91 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#set(java.lang.String,
|
||
92 | * java.lang.Object)
|
||
93 | */
|
||
94 | 23874 | jjdelcerro | public void set(String name, Object value) { |
95 | set(featureType.getIndex(name), value); |
||
96 | } |
||
97 | |||
98 | 29391 | jmvivo | /*
|
99 | * (non-Javadoc)
|
||
100 | *
|
||
101 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(int)
|
||
102 | */
|
||
103 | 23754 | jjdelcerro | public Object get(int i) { |
104 | return values[i];
|
||
105 | } |
||
106 | |||
107 | 29391 | jmvivo | /*
|
108 | * (non-Javadoc)
|
||
109 | *
|
||
110 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#get(java.lang.String)
|
||
111 | */
|
||
112 | 23754 | jjdelcerro | public Object get(String name) { |
113 | 35983 | jpiera | FeatureAttributeDescriptor featureAttributeDescriptor = featureType.getAttributeDescriptor(name); |
114 | 34629 | jpiera | return values[featureAttributeDescriptor.getIndex()];
|
115 | 23754 | jjdelcerro | } |
116 | |||
117 | 29391 | jmvivo | /*
|
118 | * (non-Javadoc)
|
||
119 | *
|
||
120 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getType()
|
||
121 | */
|
||
122 | 23754 | jjdelcerro | public FeatureType getType() {
|
123 | return featureType;
|
||
124 | } |
||
125 | |||
126 | 29391 | jmvivo | /*
|
127 | * (non-Javadoc)
|
||
128 | *
|
||
129 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getCopy()
|
||
130 | */
|
||
131 | 29289 | jmvivo | public FeatureProvider getCopy() {
|
132 | DefaultFeatureProvider data = new DefaultFeatureProvider(
|
||
133 | 23874 | jjdelcerro | this.getType());
|
134 | 23754 | jjdelcerro | return getCopy(data);
|
135 | } |
||
136 | |||
137 | 29391 | jmvivo | /**
|
138 | * Copy values from current instance to <code>data</code>
|
||
139 | */
|
||
140 | 29289 | jmvivo | protected FeatureProvider getCopy(DefaultFeatureProvider data) {
|
141 | 24248 | jjdelcerro | data.oid = this.oid;
|
142 | 23754 | jjdelcerro | System.arraycopy(this.values, 0, data.values, 0, this.values.length); |
143 | data.defaultGeometry = this.defaultGeometry;
|
||
144 | 23874 | jjdelcerro | data.envelope = this.envelope;
|
145 | 25915 | vcaballero | data.isNew=this.isNew;
|
146 | 23754 | jjdelcerro | return data;
|
147 | } |
||
148 | |||
149 | 29391 | jmvivo | /*
|
150 | * (non-Javadoc)
|
||
151 | *
|
||
152 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultEnvelope()
|
||
153 | */
|
||
154 | 24446 | jmvivo | public Envelope getDefaultEnvelope() {
|
155 | 24511 | jmvivo | if (envelope == null && defaultGeometry != null) { |
156 | 23874 | jjdelcerro | envelope = defaultGeometry.getEnvelope(); |
157 | } |
||
158 | return envelope;
|
||
159 | 23754 | jjdelcerro | } |
160 | |||
161 | 29391 | jmvivo | /*
|
162 | * (non-Javadoc)
|
||
163 | *
|
||
164 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getDefaultGeometry()
|
||
165 | */
|
||
166 | 23754 | jjdelcerro | public Geometry getDefaultGeometry() {
|
167 | return this.defaultGeometry; |
||
168 | } |
||
169 | |||
170 | 29391 | jmvivo | /*
|
171 | * (non-Javadoc)
|
||
172 | *
|
||
173 | * @see
|
||
174 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultEnvelope(org
|
||
175 | * .gvsig.fmap.geom.primitive.Envelope)
|
||
176 | */
|
||
177 | 23874 | jjdelcerro | public void setDefaultEnvelope(Envelope envelope) { |
178 | this.envelope = envelope;
|
||
179 | 23754 | jjdelcerro | } |
180 | |||
181 | 29391 | jmvivo | /*
|
182 | * (non-Javadoc)
|
||
183 | *
|
||
184 | * @see
|
||
185 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setDefaultGeometry(org
|
||
186 | * .gvsig.fmap.geom.Geometry)
|
||
187 | */
|
||
188 | 23754 | jjdelcerro | public void setDefaultGeometry(Geometry geom) { |
189 | 23874 | jjdelcerro | int i = featureType.getDefaultGeometryAttributeIndex();
|
190 | defaultGeometry = geom; |
||
191 | envelope = null;
|
||
192 | values[i] = geom; |
||
193 | 23754 | jjdelcerro | } |
194 | |||
195 | 29391 | jmvivo | /*
|
196 | * (non-Javadoc)
|
||
197 | *
|
||
198 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(int)
|
||
199 | */
|
||
200 | 23874 | jjdelcerro | public boolean isNull(int i) { |
201 | return nulls[i];
|
||
202 | } |
||
203 | |||
204 | 29391 | jmvivo | /*
|
205 | * (non-Javadoc)
|
||
206 | *
|
||
207 | * @see
|
||
208 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNull(java.lang.String)
|
||
209 | */
|
||
210 | 23874 | jjdelcerro | public boolean isNull(String name) { |
211 | int i = featureType.getIndex(name);
|
||
212 | return isNull(i);
|
||
213 | } |
||
214 | |||
215 | 29391 | jmvivo | /*
|
216 | * (non-Javadoc)
|
||
217 | *
|
||
218 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#getOID()
|
||
219 | */
|
||
220 | 24248 | jjdelcerro | public Object getOID() { |
221 | return this.oid; |
||
222 | } |
||
223 | |||
224 | 29391 | jmvivo | /*
|
225 | * (non-Javadoc)
|
||
226 | *
|
||
227 | * @see
|
||
228 | * org.gvsig.fmap.dal.feature.spi.FeatureProvider#setOID(java.lang.Object)
|
||
229 | */
|
||
230 | 24248 | jjdelcerro | public void setOID(Object oid) { |
231 | this.oid = oid;
|
||
232 | } |
||
233 | 29391 | jmvivo | |
234 | /*
|
||
235 | * (non-Javadoc)
|
||
236 | *
|
||
237 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#isNew()
|
||
238 | */
|
||
239 | 25616 | vcaballero | public boolean isNew(){ |
240 | return isNew;
|
||
241 | } |
||
242 | 29391 | jmvivo | |
243 | /*
|
||
244 | * (non-Javadoc)
|
||
245 | *
|
||
246 | * @see org.gvsig.fmap.dal.feature.spi.FeatureProvider#setNew(boolean)
|
||
247 | */
|
||
248 | 25616 | vcaballero | public void setNew(boolean isNew){ |
249 | this.isNew=isNew;
|
||
250 | } |
||
251 | 23754 | jjdelcerro | } |