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 / memory / MemoryFeatureSet.java @ 40435
History | View | Annotate | Download (4.62 KB)
1 | 40435 | jjdelcerro | /* 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 | * 2009 IVER T.I {{Task}}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.dal.feature.spi.memory; |
||
28 | |||
29 | import java.util.Iterator; |
||
30 | import java.util.List; |
||
31 | |||
32 | import org.gvsig.fmap.dal.exception.DataException; |
||
33 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
34 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
35 | import org.gvsig.fmap.dal.feature.exception.IteratorIndexTooBigException; |
||
36 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
||
37 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
||
38 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
||
39 | import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
||
40 | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
||
41 | import org.gvsig.tools.dispose.Disposable; |
||
42 | import org.gvsig.tools.exception.BaseException; |
||
43 | |||
44 | /**
|
||
45 | * Implementation of {@link FeatureSetProvider} used in
|
||
46 | * {@link AbstractMemoryStoreProvider}
|
||
47 | *
|
||
48 | */
|
||
49 | public class MemoryFeatureSet extends AbstractFeatureSetProvider { |
||
50 | |||
51 | protected List data; |
||
52 | |||
53 | public MemoryFeatureSet(AbstractFeatureStoreProvider store,
|
||
54 | FeatureQuery query, FeatureType featureType, List data) {
|
||
55 | super(store, query,
|
||
56 | /*
|
||
57 | * Comprobar si los attributos solicitados son distintos a los
|
||
58 | * originales.
|
||
59 | */
|
||
60 | featureType.equals(store.getStoreServices() |
||
61 | .getProviderFeatureType(featureType.getId())) ? null
|
||
62 | : featureType); |
||
63 | this.data = data;
|
||
64 | /*
|
||
65 | * Nota: Como no sabe filtrar ni ordenar ignora el query.
|
||
66 | */
|
||
67 | } |
||
68 | |||
69 | public boolean canFilter() { |
||
70 | return false; |
||
71 | } |
||
72 | |||
73 | public boolean canOrder() { |
||
74 | return false; |
||
75 | } |
||
76 | |||
77 | public boolean canIterateFromIndex() { |
||
78 | return true; |
||
79 | } |
||
80 | |||
81 | public long getSize() throws DataException { |
||
82 | return data.size();
|
||
83 | } |
||
84 | |||
85 | public boolean isEmpty() throws DataException { |
||
86 | return data.isEmpty();
|
||
87 | } |
||
88 | |||
89 | protected void doDispose() throws BaseException { |
||
90 | //data only has to be deleted when the store.dispose method is called
|
||
91 | //data.clear();
|
||
92 | } |
||
93 | |||
94 | protected AbstractFeatureProviderIterator createFastIterator(long index) |
||
95 | throws DataException {
|
||
96 | return createIterator(index);
|
||
97 | } |
||
98 | |||
99 | protected AbstractFeatureProviderIterator createIterator(long index) |
||
100 | throws DataException {
|
||
101 | if (index > 0 && index >= data.size()) { |
||
102 | throw new IteratorIndexTooBigException(index, data.size()); |
||
103 | } |
||
104 | Iterator iter =
|
||
105 | index <= 0 ? data.iterator() : data.listIterator((int) index); |
||
106 | if (getFeatureType() == null) { |
||
107 | return new DelegatedDisposableIterator(getStore(), iter); |
||
108 | } else {
|
||
109 | return new DelegatedDisposableWrappedIterator(getStore(), iter, |
||
110 | getFeatureType()); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | protected class DelegatedDisposableIterator extends |
||
115 | AbstractFeatureProviderIterator { |
||
116 | private Iterator delegated; |
||
117 | |||
118 | public DelegatedDisposableIterator(AbstractFeatureStoreProvider store,
|
||
119 | Iterator it) {
|
||
120 | super(store);
|
||
121 | this.delegated = it;
|
||
122 | } |
||
123 | |||
124 | protected void internalDispose() { |
||
125 | this.delegated = null; |
||
126 | } |
||
127 | |||
128 | protected boolean internalHasNext() { |
||
129 | return delegated.hasNext();
|
||
130 | } |
||
131 | |||
132 | protected Object internalNext() { |
||
133 | return delegated.next();
|
||
134 | } |
||
135 | |||
136 | public void remove() { |
||
137 | throw new UnsupportedOperationException(); |
||
138 | } |
||
139 | |||
140 | protected void doDispose() throws BaseException { |
||
141 | if (delegated instanceof Disposable) { |
||
142 | ((Disposable) delegated).dispose(); |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | |||
147 | protected class DelegatedDisposableWrappedIterator extends |
||
148 | DelegatedDisposableIterator { |
||
149 | private FeatureType fType;
|
||
150 | |||
151 | public DelegatedDisposableWrappedIterator(
|
||
152 | AbstractFeatureStoreProvider store, Iterator it,
|
||
153 | FeatureType featureType) { |
||
154 | super(store, it);
|
||
155 | this.fType = featureType;
|
||
156 | } |
||
157 | |||
158 | protected Object internalNext() { |
||
159 | DefaultFeatureProvider feature = |
||
160 | (DefaultFeatureProvider) super.internalNext();
|
||
161 | if (fType == null) { |
||
162 | return feature;
|
||
163 | } else {
|
||
164 | return new MemoryFeatureProviderAttributeMapper(feature, |
||
165 | this.fType);
|
||
166 | } |
||
167 | |||
168 | } |
||
169 | } |
||
170 | } |