01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.build.feature;
18:
19: import org.geotools.feature.Feature;
20: import org.geotools.graph.build.GraphBuilder;
21: import org.geotools.graph.build.GraphGenerator;
22: import org.geotools.graph.build.basic.BasicGraphGenerator;
23: import org.geotools.graph.structure.Graph;
24: import org.geotools.graph.structure.Graphable;
25:
26: /**
27: * Builds a graph from {@link org.geotools.feature.Feature} objects.
28: * <p>
29: * This graph generator decorates another graph generator which
30: * builds a graph from geometries.
31: * </p>
32: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
33: *
34: */
35: public class FeatureGraphGenerator extends BasicGraphGenerator {
36:
37: /**
38: * The underling "geometry" building graph generator
39: */
40: GraphGenerator decorated;
41:
42: public FeatureGraphGenerator(GraphGenerator decorated) {
43: this .decorated = decorated;
44: }
45:
46: public Graph getGraph() {
47: return decorated.getGraph();
48: }
49:
50: public GraphBuilder getGraphBuilder() {
51: return decorated.getGraphBuilder();
52: }
53:
54: public Graphable add(Object obj) {
55: Feature feature = (Feature) obj;
56: Graphable g = decorated.add(feature.getDefaultGeometry());
57: g.setObject(feature);
58:
59: return g;
60: }
61:
62: public Graphable remove(Object obj) {
63: Feature feature = (Feature) obj;
64: return decorated.remove(feature.getDefaultGeometry());
65: }
66:
67: public Graphable get(Object obj) {
68: Feature feature = (Feature) obj;
69: return decorated.get(feature.getDefaultGeometry());
70: }
71: }
|