01: /**
02: *
03: */package net.refractions.udig.project.command.provider;
04:
05: import java.io.IOException;
06:
07: import net.refractions.udig.core.IBlockingProvider;
08: import net.refractions.udig.project.ILayer;
09:
10: import org.eclipse.core.runtime.IProgressMonitor;
11: import org.geotools.data.FeatureSource;
12: import org.geotools.feature.Feature;
13: import org.geotools.feature.FeatureIterator;
14: import org.geotools.filter.FidFilter;
15: import org.geotools.filter.FilterFactoryFinder;
16:
17: public class FIDFeatureProvider implements IBlockingProvider<Feature> {
18:
19: private IBlockingProvider<ILayer> layer;
20: private String fid;
21: private Feature feature;
22:
23: public FIDFeatureProvider(String fid2,
24: IBlockingProvider<ILayer> layer2) {
25: this .layer = layer2;
26: this .fid = fid2;
27: }
28:
29: public synchronized Feature get(IProgressMonitor monitor) {
30: if (feature == null) {
31: FidFilter fidFilter = FilterFactoryFinder
32: .createFilterFactory().createFidFilter(fid);
33: try {
34: FeatureSource source = layer.get(monitor).getResource(
35: FeatureSource.class, monitor);
36: FeatureIterator iter = source.getFeatures(fidFilter)
37: .features();
38: try {
39: feature = iter.next();
40: } finally {
41: iter.close();
42: }
43:
44: } catch (IOException e) {
45: throw (RuntimeException) new RuntimeException()
46: .initCause(e);
47: }
48: }
49: return feature;
50: }
51:
52: }
|