svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / spi / AbstractDataProviderIterator.java @ 35338
History | View | Annotate | Download (3.27 KB)
1 |
/* 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 {} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.dal.spi; |
28 |
|
29 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
30 |
import org.gvsig.fmap.dal.resource.Resource; |
31 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
32 |
import org.gvsig.tools.dispose.DisposableIterator; |
33 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
34 |
|
35 |
/**
|
36 |
* Abstract base implementation for data iterators.
|
37 |
*
|
38 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
39 |
*/
|
40 |
public abstract class AbstractDataProviderIterator extends AbstractDisposable |
41 |
implements DisposableIterator {
|
42 |
|
43 |
private final DataStoreProvider dataStoreProvider; |
44 |
|
45 |
private final ResourceAction nextResourceAction = new ResourceAction() { |
46 |
public Object run() throws Exception { |
47 |
dataStoreProvider.open(); |
48 |
return internalNext();
|
49 |
} |
50 |
}; |
51 |
|
52 |
private final ResourceAction hasNextResourceAction = new ResourceAction() { |
53 |
public Object run() throws Exception { |
54 |
boolean value = internalHasNext();
|
55 |
return value ? Boolean.TRUE : Boolean.FALSE; |
56 |
} |
57 |
}; |
58 |
|
59 |
/**
|
60 |
* Creates a new iterator instance.
|
61 |
*
|
62 |
* @param storeProvider
|
63 |
* to load the {@link FeatureProvider}s from
|
64 |
*/
|
65 |
public AbstractDataProviderIterator(DataStoreProvider dataStoreProvider) {
|
66 |
this.dataStoreProvider = dataStoreProvider;
|
67 |
} |
68 |
|
69 |
public Object next() { |
70 |
return getResource().execute(nextResourceAction);
|
71 |
} |
72 |
|
73 |
public boolean hasNext() { |
74 |
Object hasNext = getResource().execute(hasNextResourceAction);
|
75 |
return ((Boolean) hasNext).booleanValue(); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Returns the {@link Resource} from where the data is going to be loaded.
|
80 |
*
|
81 |
* @return the {@link Resource} from where the data is going to be loaded
|
82 |
*/
|
83 |
protected final Resource getResource() { |
84 |
return getDataStoreProvider().getResource();
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Returns the {@link DataStoreProvider} to load the Iterator data.
|
89 |
*
|
90 |
* @return the {@link DataStoreProvider}
|
91 |
*/
|
92 |
protected DataStoreProvider getDataStoreProvider() {
|
93 |
return dataStoreProvider;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Returns the next iterator element. It is the child classes implementation
|
98 |
* for the {@link #next()} method.
|
99 |
*
|
100 |
* @return the next element
|
101 |
*/
|
102 |
protected abstract Object internalNext(); |
103 |
|
104 |
/**
|
105 |
* Returns if there are more elements to get from the iterator. It is the
|
106 |
* child classes implementation for the {@link #hasNext()} method.
|
107 |
*
|
108 |
* @return if there are more elements
|
109 |
*/
|
110 |
protected abstract boolean internalHasNext(); |
111 |
} |