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 / spi / AbstractDataProviderIterator.java @ 46315
History | View | Annotate | Download (3.28 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
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 3
|
||
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 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.spi; |
25 | |||
26 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
27 | import org.gvsig.fmap.dal.resource.Resource; |
||
28 | import org.gvsig.fmap.dal.resource.ResourceAction; |
||
29 | import org.gvsig.tools.dispose.DisposableIterator; |
||
30 | import org.gvsig.tools.dispose.impl.AbstractDisposable; |
||
31 | |||
32 | /**
|
||
33 | * Abstract base implementation for data iterators.
|
||
34 | *
|
||
35 | * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
||
36 | */
|
||
37 | public abstract class AbstractDataProviderIterator extends AbstractDisposable |
||
38 | implements DisposableIterator {
|
||
39 | |||
40 | private final DataStoreProvider dataStoreProvider; |
||
41 | |||
42 | private final ResourceAction nextResourceAction = new ResourceAction() { |
||
43 | public Object run() throws Exception { |
||
44 | dataStoreProvider.open(); |
||
45 | return internalNext();
|
||
46 | } |
||
47 | }; |
||
48 | |||
49 | private final ResourceAction hasNextResourceAction = new ResourceAction() { |
||
50 | public Object run() throws Exception { |
||
51 | boolean value = internalHasNext();
|
||
52 | return value ? Boolean.TRUE : Boolean.FALSE; |
||
53 | } |
||
54 | }; |
||
55 | |||
56 | /**
|
||
57 | * Creates a new iterator instance.
|
||
58 | *
|
||
59 | * @param storeProvider
|
||
60 | * to load the {@link FeatureProvider}s from
|
||
61 | */
|
||
62 | public AbstractDataProviderIterator(DataStoreProvider dataStoreProvider) {
|
||
63 | this.dataStoreProvider = dataStoreProvider;
|
||
64 | } |
||
65 | |||
66 | public Object next() { |
||
67 | return getResource().execute(nextResourceAction);
|
||
68 | } |
||
69 | |||
70 | public boolean hasNext() { |
||
71 | Object hasNext = getResource().execute(hasNextResourceAction);
|
||
72 | return ((Boolean) hasNext).booleanValue(); |
||
73 | } |
||
74 | |||
75 | /**
|
||
76 | * Returns the {@link Resource} from where the data is going to be loaded.
|
||
77 | *
|
||
78 | * @return the {@link Resource} from where the data is going to be loaded
|
||
79 | */
|
||
80 | protected final Resource getResource() { |
||
81 | return getDataStoreProvider().getResource();
|
||
82 | } |
||
83 | |||
84 | /**
|
||
85 | * Returns the {@link DataStoreProvider} to load the Iterator data.
|
||
86 | *
|
||
87 | * @return the {@link DataStoreProvider}
|
||
88 | */
|
||
89 | protected DataStoreProvider getDataStoreProvider() {
|
||
90 | return dataStoreProvider;
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * Returns the next iterator element. It is the child classes implementation
|
||
95 | * for the {@link #next()} method.
|
||
96 | *
|
||
97 | * @return the next element
|
||
98 | */
|
||
99 | protected abstract Object internalNext(); |
||
100 | |||
101 | /**
|
||
102 | * Returns if there are more elements to get from the iterator. It is the
|
||
103 | * child classes implementation for the {@link #hasNext()} method.
|
||
104 | *
|
||
105 | * @return if there are more elements
|
||
106 | */
|
||
107 | protected abstract boolean internalHasNext(); |
||
108 | 40767 | jjdelcerro | } |