Statistics
| Revision:

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 / AbstractFeatureSetProvider.java @ 47198

History | View | Annotate | Download (5.33 KB)

1
/**
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
package org.gvsig.fmap.dal.feature.spi;
25

    
26
import java.util.Iterator;
27
import org.apache.commons.lang3.builder.ToStringBuilder;
28

    
29
import org.gvsig.fmap.dal.exception.DataException;
30
import org.gvsig.fmap.dal.feature.FeatureQuery;
31
import org.gvsig.fmap.dal.feature.FeatureType;
32
import org.gvsig.tools.dispose.DisposableIterator;
33
import org.gvsig.tools.dispose.impl.AbstractDisposable;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
/**
38
 * Base implementation for {@link FeatureSetProvider}s, adding some utility
39
 * methods.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public abstract class AbstractFeatureSetProvider extends AbstractDisposable
44
                implements FeatureSetProvider {
45

    
46
        protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractFeatureSetProvider.class);
47
                
48
        private final AbstractFeatureStoreProvider store;
49
        private final FeatureQuery query;
50
        private final FeatureType featureType;
51

    
52
        /**
53
         * Creates a new {@link FeatureSetProvider}.
54
         * 
55
         * @param store
56
         *            the underlying {@link FeatureStoreProvider} to get the data
57
         *            from
58
         * @param query
59
         *            used to create the {@link FeatureSetProvider}
60
         * @param featureType
61
         *            the type of feature to get
62
         */
63
        public AbstractFeatureSetProvider(AbstractFeatureStoreProvider store,
64
                        FeatureQuery query, FeatureType featureType) {
65
                this.store = store;
66
                this.query = query;
67
                this.featureType = featureType;
68
        }
69

    
70
        /**
71
         * Return the {@link AbstractFeatureStoreProvider}.
72
         * 
73
         * @return the store
74
         */
75
        protected AbstractFeatureStoreProvider getStore() {
76
                return store;
77
        }
78

    
79
        /**
80
         * Returns the {@link FeatureQuery} used to create this set.
81
         * 
82
         * @return the query
83
         */
84
        protected FeatureQuery getQuery() {
85
                return query;
86
        }
87
    
88
        /**
89
         * Returns the type of features to load.
90
         * 
91
         * @return the featureType
92
         */
93
        protected FeatureType getFeatureType() {
94
                return featureType;
95
        }
96
    
97
    @Override
98
        public final DisposableIterator fastIterator() throws DataException {
99
                return fastIterator(0);
100
        }
101

    
102
        public final DisposableIterator fastIterator(long index)
103
                        throws DataException {
104
                return createFastIterator(index);
105
        }
106

    
107
    @Override
108
    public final DisposableIterator fastIterator(long index, long elements) throws DataException {
109
                return createFastIterator(index, elements);
110
        }
111

    
112
    @Override
113
        public final DisposableIterator iterator() throws DataException {
114
                return iterator(0);
115
        }
116

    
117
        public final DisposableIterator iterator(long index) throws DataException {
118
                return createIterator(index);
119
        }
120

    
121
    @Override
122
        public final DisposableIterator iterator(long index, long elements) throws DataException {
123
                return createIterator(index, elements);
124
        }
125

    
126
        /**
127
         * Creates a new {@link Iterator}, begginning at the specified data index.
128
         * 
129
         * @param index
130
         *            the first element position to be returned by the
131
         *            {@link Iterator}
132
         * @return a new {@link Iterator}
133
         * @throws DataException
134
         *             if there is an error creating the {@link Iterator}
135
         */
136
        protected abstract AbstractFeatureProviderIterator createIterator(long index)
137
                        throws DataException;
138

    
139
        protected AbstractFeatureProviderIterator createIterator(long index, long elements)
140
                        throws DataException {
141
            return createIterator(index);
142
    }
143

    
144
    /**
145
         * Creates a new fast {@link Iterator}, begginning at the specified data
146
         * index. By fast this means the object instances of data (
147
         * {@link FeatureProvider}) may be reused between the
148
         * {@link Iterator#next()} method invocations.
149
         * 
150
         * @param index
151
         *            the first element position to be returned by the
152
         *            {@link Iterator}
153
         * @return a new {@link Iterator}
154
         * @throws DataException
155
         *             if there is an error creating the {@link Iterator}
156
         */
157
        protected abstract AbstractFeatureProviderIterator createFastIterator(
158
                        long index) throws DataException;
159
        
160
        protected AbstractFeatureProviderIterator createFastIterator(
161
                        long index, long elements) throws DataException {
162
            return createFastIterator(index);
163
        }
164

    
165
    @Override
166
    public String toString() {
167
        try {
168
            ToStringBuilder builder = new ToStringBuilder(this);
169
            builder.append("store", this.store, true);
170
            builder.append("query", this.query, true);
171
            return builder.toString();
172
        } catch (Exception e) {
173
            return super.toString();
174
        }
175
    }
176
}