Revision 7061
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.topology.lib</artifactId> |
|
6 |
<version>1.0.119</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.topology.lib.impl</artifactId> |
|
9 |
<name>${project.artifactId}</name> |
|
10 |
<dependencies> |
|
11 |
<dependency> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.topology.lib.api</artifactId> |
|
14 |
<scope>compile</scope> |
|
15 |
</dependency> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
19 |
<scope>compile</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.fmap.dal.swing.api</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.json</groupId> |
|
33 |
<artifactId>json</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>org.gvsig</groupId> |
|
38 |
<artifactId>org.gvsig.tools.dynform.spi</artifactId> |
|
39 |
<scope>compile</scope> |
|
40 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>commons-collections</groupId> |
|
43 |
<artifactId>commons-collections</artifactId> |
|
44 |
<scope>compile</scope> |
|
45 |
</dependency> |
|
46 |
</dependencies> |
|
47 |
</project> |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyManager.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
import org.gvsig.fmap.dal.DataStore; |
|
32 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
33 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
34 |
import org.gvsig.topology.lib.api.TopologyPlan; |
|
35 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
|
36 |
import org.gvsig.topology.lib.api.TopologyServices; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
public class DefaultTopologyManager implements TopologyManager { |
|
43 |
|
|
44 |
private final Map<String,TopologyRuleFactory> factories; |
|
45 |
private TopologyServices services; |
|
46 |
|
|
47 |
public DefaultTopologyManager() { |
|
48 |
this.factories = new HashMap<>(); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public TopologyPlan createTopologyPlan() { |
|
53 |
TopologyPlan plan = new DefaultTopologyPlan(this, this.services); |
|
54 |
return plan; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public List<TopologyRuleFactory> getRuleFactories() { |
|
59 |
List<TopologyRuleFactory> l = new ArrayList<>(this.factories.values()); |
|
60 |
return Collections.unmodifiableList(l); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public List<TopologyRuleFactory> getRuleFactories(TopologyDataSet dataSet) { |
|
65 |
List<TopologyRuleFactory> f = new ArrayList<>(); |
|
66 |
for (TopologyRuleFactory factory : this.factories.values()) { |
|
67 |
if( factory.canApplyToDataSet(dataSet) ) { |
|
68 |
f.add(factory); |
|
69 |
} |
|
70 |
} |
|
71 |
return f; |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public TopologyRuleFactory getRulefactory(String id) { |
|
76 |
if( id==null ) { |
|
77 |
return null; |
|
78 |
} |
|
79 |
TopologyRuleFactory factory = this.factories.get(id.toLowerCase()); |
|
80 |
return factory; |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public void addRuleFactories(TopologyRuleFactory factory) { |
|
85 |
if( factory==null ) { |
|
86 |
throw new IllegalArgumentException("Invalid null value."); |
|
87 |
} |
|
88 |
this.factories.put(factory.getId().toLowerCase(), factory); |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public TopologyDataSet createDataSet(String name, DataStore store) { |
|
93 |
TopologyDataSet dataSet = new DefaultTopologyDataSet(this.services, name, store); |
|
94 |
return dataSet; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public void setDefaultServices(TopologyServices services) { |
|
99 |
this.services = services; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public TopologyServices getDefaultServices() { |
|
104 |
return this.services; |
|
105 |
} |
|
106 |
|
|
107 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyPlan.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collection; |
|
28 |
import java.util.Collections; |
|
29 |
import java.util.Date; |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.List; |
|
32 |
import java.util.Map; |
|
33 |
import javax.json.JsonArray; |
|
34 |
import javax.json.JsonObject; |
|
35 |
import javax.json.JsonValue; |
|
36 |
import org.gvsig.fmap.dal.DataStore; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
38 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
39 |
import org.gvsig.fmap.geom.GeometryManager; |
|
40 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
41 |
import org.gvsig.json.Json; |
|
42 |
import org.gvsig.json.JsonArrayBuilder; |
|
43 |
import org.gvsig.json.JsonObjectBuilder; |
|
44 |
import org.gvsig.tools.ToolsLocator; |
|
45 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
46 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
47 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
48 |
import org.gvsig.topology.lib.api.TopologyPlan; |
|
49 |
import org.gvsig.topology.lib.api.TopologyRule; |
|
50 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
|
51 |
import org.gvsig.topology.lib.api.TopologyServices; |
|
52 |
import org.gvsig.topology.lib.spi.AbstractTopologyRule; |
|
53 |
import org.slf4j.Logger; |
|
54 |
import org.slf4j.LoggerFactory; |
|
55 |
|
|
56 |
/** |
|
57 |
* |
|
58 |
* @author jjdelcerro |
|
59 |
*/ |
|
60 |
@SuppressWarnings("UseSpecificCatch") |
|
61 |
public class DefaultTopologyPlan implements TopologyPlan { |
|
62 |
|
|
63 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTopologyPlan.class); |
|
64 |
|
|
65 |
private final TopologyManager manager; |
|
66 |
private final Map<String,TopologyDataSet> dataSets; |
|
67 |
private final List<TopologyRule> rules; |
|
68 |
|
|
69 |
private String name; |
|
70 |
private DefaultTopologyReport report; |
|
71 |
private TopologyServices services; |
|
72 |
private double tolerance; |
|
73 |
private SimpleTaskStatus taskStatus; |
|
74 |
private boolean useUI; |
|
75 |
private boolean acceptExceptions; |
|
76 |
|
|
77 |
public DefaultTopologyPlan(TopologyManager manager, TopologyServices services) { |
|
78 |
this.manager = manager; |
|
79 |
this.services = services; |
|
80 |
this.dataSets = new HashMap<>(); |
|
81 |
this.rules = new ArrayList<>(); |
|
82 |
this.report = null; |
|
83 |
this.name = "TopologyPlan-" + String.format("%08X", new Date().getTime()); |
|
84 |
this.tolerance = 0; |
|
85 |
this.useUI = true; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public void setName(String name) { |
|
90 |
this.name = name; |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public String getName() { |
|
95 |
return this.name; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void clear() { |
|
100 |
this.name = ""; |
|
101 |
this.tolerance = 0; |
|
102 |
this.services = null; |
|
103 |
this.report = null; |
|
104 |
this.dataSets.clear(); |
|
105 |
this.rules.clear(); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public double getTolerance() { |
|
110 |
return tolerance; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void setTolerance(double tolerance) { |
|
115 |
this.tolerance = tolerance; |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public void setTopologyServices(TopologyServices services) { |
|
120 |
this.services = services; |
|
121 |
for (TopologyDataSet dataSet : this.dataSets.values()) { |
|
122 |
if(dataSet instanceof DefaultTopologyDataSet){ |
|
123 |
((DefaultTopologyDataSet)dataSet).setTopologyServices(services); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public TopologyServices getTopologyServices() { |
|
130 |
return this.services; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public SimpleTaskStatus getTaskStatus() { |
|
135 |
if( this.taskStatus == null ) { |
|
136 |
this.taskStatus = ToolsLocator.getTaskStatusManager() |
|
137 |
.createDefaultSimpleTaskStatus(this.getName()); |
|
138 |
} |
|
139 |
return this.taskStatus; |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public void execute() { |
|
144 |
SimpleTaskStatus theTaskStatus = this.getTaskStatus(); |
|
145 |
try { |
|
146 |
theTaskStatus.restart(); |
|
147 |
theTaskStatus.message("Preparing the execution of the plan"); |
|
148 |
theTaskStatus.setAutoremove(true); |
|
149 |
theTaskStatus.setIndeterminate(); |
|
150 |
for (TopologyDataSet dataSet : this.dataSets.values()) { |
|
151 |
dataSet.restart(); |
|
152 |
} |
|
153 |
this.getReport().removeAllLines(); |
|
154 |
long steps = 0; |
|
155 |
for (TopologyRule rule : this.rules) { |
|
156 |
steps += rule.getSteps(); |
|
157 |
steps++; |
|
158 |
} |
|
159 |
|
|
160 |
theTaskStatus.setRangeOfValues(0, steps); |
|
161 |
theTaskStatus.setCurValue(0); |
|
162 |
for (TopologyRule rule : this.rules) { |
|
163 |
if( theTaskStatus.isCancellationRequested() ) { |
|
164 |
theTaskStatus.cancel(); |
|
165 |
break; |
|
166 |
} |
|
167 |
theTaskStatus.message(rule.getName()); |
|
168 |
rule.execute(theTaskStatus, this.getReport()); |
|
169 |
theTaskStatus.incrementCurrentValue(); |
|
170 |
} |
|
171 |
} catch(Exception ex) { |
|
172 |
LOGGER.warn("Problems executing topology plan '"+this.getName()+"'.", ex); |
|
173 |
theTaskStatus.abort(); |
|
174 |
} finally { |
|
175 |
if( theTaskStatus.isRunning() ) { |
|
176 |
theTaskStatus.terminate(); |
|
177 |
} |
|
178 |
this.getReport().setCompleted(true); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
@Override |
|
183 |
public TopologyDataSet addDataSet(String name, DataStore store) { |
|
184 |
TopologyDataSet dataSet = manager.createDataSet(name, store); |
|
185 |
return this.addDataSet(dataSet); |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public TopologyDataSet addDataSet(TopologyDataSet dataSet) { |
|
190 |
if( this.dataSets.containsKey(dataSet.getName()) ) { |
|
191 |
throw new IllegalArgumentException("Already exists a dataSet with this name ("+dataSet.getName()+")."); |
|
192 |
} |
|
193 |
this.dataSets.put(dataSet.getName(), dataSet); |
|
194 |
return dataSet; |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public TopologyDataSet getDataSet(String name) { |
|
199 |
return this.dataSets.get(name); |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public boolean containsDataSet(String name) { |
|
204 |
return this.dataSets.containsKey(name); |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public Collection<TopologyDataSet> getDataSets() { |
|
209 |
Collection<TopologyDataSet> x = dataSets.values(); |
|
210 |
return Collections.unmodifiableCollection(x); |
|
211 |
} |
|
212 |
|
|
213 |
@Override |
|
214 |
public Collection<TopologyDataSet> getSecondaryDataSets(TopologyRuleFactory ruleFactory) { |
|
215 |
List<TopologyDataSet> secondaryDataSets = new ArrayList<>(); |
|
216 |
for (TopologyDataSet dataSet : dataSets.values()) { |
|
217 |
if( ruleFactory.canApplyToSecondaryDataSet(dataSet) ) { |
|
218 |
secondaryDataSets.add(dataSet); |
|
219 |
} |
|
220 |
} |
|
221 |
return secondaryDataSets; |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public TopologyRule addRule(String id, String dataSet1, String dataSet2, double tolerance) { |
|
226 |
TopologyRuleFactory factory = this.manager.getRulefactory(id); |
|
227 |
if( factory == null ) { |
|
228 |
throw new IllegalArgumentException("Can't locate factory for rule '"+id+"'."); |
|
229 |
} |
|
230 |
if( ! this.canApplyRule(factory, dataSet1, dataSet2) ) { |
|
231 |
throw new IllegalArgumentException( |
|
232 |
"Can't apply rule '"+factory.getName()+"' to the datasets '"+dataSet1+"/"+dataSet2+"'." |
|
233 |
); |
|
234 |
} |
|
235 |
TopologyRule rule = factory.createRule(dataSet1, dataSet2, tolerance); |
|
236 |
return this.addRule(rule); |
|
237 |
} |
|
238 |
|
|
239 |
@Override |
|
240 |
public TopologyRule addRule(TopologyRule rule) { |
|
241 |
if( rule.getPlan()!=null && rule.getPlan()!=this ) { |
|
242 |
rule = (AbstractTopologyRule) org.gvsig.tools.lang.Cloneable.cloneQuietly(rule); |
|
243 |
} |
|
244 |
((AbstractTopologyRule)rule).setPlan(this); |
|
245 |
this.rules.add(rule); |
|
246 |
return rule; |
|
247 |
} |
|
248 |
|
|
249 |
private boolean canApplyRule(TopologyRuleFactory factory, String dataSet1, String dataSet2) { |
|
250 |
try { |
|
251 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
252 |
TopologyDataSet dataset = this.getDataSet(dataSet1); |
|
253 |
FeatureStore store = (FeatureStore) dataset.getStore(); |
|
254 |
GeometryType gt = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType(); |
|
255 |
for (Integer geometryType1 : factory.getGeometryTypeDataSet1()) { |
|
256 |
if( gt.isTypeOf(geometryType1) ) { |
|
257 |
if( factory.getGeometryTypeDataSet2()==null ) { |
|
258 |
return true; |
|
259 |
} |
|
260 |
dataset = this.getDataSet(dataSet2); |
|
261 |
store = (FeatureStore) dataset.getStore(); |
|
262 |
gt = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType(); |
|
263 |
for (Integer geometryType2 : factory.getGeometryTypeDataSet2()) { |
|
264 |
if( gt.isTypeOf(geometryType2) ) { |
|
265 |
return true; |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
return false; |
|
271 |
} catch(Exception ex) { |
|
272 |
return false; |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
@Override |
|
277 |
public Collection<TopologyRule> getRules() { |
|
278 |
return Collections.unmodifiableList(rules); |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public boolean hasRules() { |
|
283 |
return !this.rules.isEmpty(); |
|
284 |
} |
|
285 |
|
|
286 |
@Override |
|
287 |
public DefaultTopologyReport getReport() { |
|
288 |
if( this.report == null ) { |
|
289 |
this.report = new DefaultTopologyReport(this); |
|
290 |
} |
|
291 |
return this.report; |
|
292 |
} |
|
293 |
|
|
294 |
@Override |
|
295 |
public JsonObject toJson() { |
|
296 |
return this.toJsonBuilder().build(); |
|
297 |
} |
|
298 |
|
|
299 |
@Override |
|
300 |
public JsonObjectBuilder toJsonBuilder() { |
|
301 |
JsonObjectBuilder me = Json.createObjectBuilder(); |
|
302 |
me.add_class(this); |
|
303 |
me.add("name", this.name); |
|
304 |
me.add("tolerance", this.tolerance); |
|
305 |
me.add("acceptExceptions", this.acceptExceptions); |
|
306 |
|
|
307 |
JsonArrayBuilder jsonDataSets = Json.createArrayBuilder(); |
|
308 |
for (TopologyDataSet dataSet : this.dataSets.values()) { |
|
309 |
jsonDataSets.add((DefaultTopologyDataSet)dataSet); |
|
310 |
} |
|
311 |
me.add("dataSets", jsonDataSets); |
|
312 |
|
|
313 |
JsonArrayBuilder jsonRules = Json.createArrayBuilder(); |
|
314 |
for (TopologyRule rule : this.rules) { |
|
315 |
jsonRules.add(rule); |
|
316 |
} |
|
317 |
me.add("rules", jsonRules); |
|
318 |
|
|
319 |
return me; |
|
320 |
} |
|
321 |
|
|
322 |
@Override |
|
323 |
public void fromJson(JsonObject jsonPlan) { |
|
324 |
this.name = jsonPlan.getString("name"); |
|
325 |
this.tolerance = jsonPlan.getJsonNumber("tolerance").doubleValue(); |
|
326 |
this.acceptExceptions = jsonPlan.getBoolean("acceptExceptions"); |
|
327 |
|
|
328 |
JsonArray jsonDataSets = jsonPlan.getJsonArray("dataSets"); |
|
329 |
for (JsonValue o : jsonDataSets) { |
|
330 |
TopologyDataSet dataSet = new DefaultTopologyDataSet(); |
|
331 |
dataSet.fromJson((JsonObject) o); |
|
332 |
this.dataSets.put(dataSet.getName(),dataSet); |
|
333 |
} |
|
334 |
|
|
335 |
JsonArray jsonRules = jsonPlan.getJsonArray("rules"); |
|
336 |
for (JsonValue o : jsonRules) { |
|
337 |
TopologyRule rule = (TopologyRule) Json.toObject(o); |
|
338 |
this.addRule(rule); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
@Override |
|
343 |
public void removeDataSet(TopologyDataSet dataSet) { |
|
344 |
this.dataSets.remove(dataSet.getName()); |
|
345 |
} |
|
346 |
|
|
347 |
@Override |
|
348 |
public void removeRule(TopologyRule rule) { |
|
349 |
this.rules.remove(rule); |
|
350 |
} |
|
351 |
|
|
352 |
@Override |
|
353 |
public boolean canUseUI() { |
|
354 |
return this.useUI; |
|
355 |
} |
|
356 |
|
|
357 |
@Override |
|
358 |
public void setUseUI(boolean useUI) { |
|
359 |
this.useUI = useUI; |
|
360 |
} |
|
361 |
|
|
362 |
@Override |
|
363 |
public int getLastStatus() { |
|
364 |
if(this.report != null){ |
|
365 |
return this.report.getStatus(); |
|
366 |
|
|
367 |
} |
|
368 |
return TopologyManager.TOPOLOGY_PLAN_STATUS_NOT_EXECUTED; |
|
369 |
} |
|
370 |
|
|
371 |
@Override |
|
372 |
public boolean getAcceptExceptions() { |
|
373 |
return this.acceptExceptions; |
|
374 |
} |
|
375 |
|
|
376 |
@Override |
|
377 |
public void setAcceptExceptions(boolean acceptExceptions) { |
|
378 |
this.acceptExceptions = acceptExceptions; |
|
379 |
} |
|
380 |
|
|
381 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyReport.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.List; |
|
29 |
import org.gvsig.expressionevaluator.Code; |
|
30 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
31 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
32 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
33 |
import org.gvsig.fmap.dal.feature.Feature; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
35 |
import org.gvsig.fmap.geom.Geometry; |
|
36 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
37 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
38 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
39 |
import static org.gvsig.topology.lib.api.TopologyManager.TOPOLOGY_PLAN_STATUS_PASSED; |
|
40 |
import org.gvsig.topology.lib.api.TopologyPlan; |
|
41 |
import org.gvsig.topology.lib.api.TopologyReport; |
|
42 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
|
43 |
import org.gvsig.topology.lib.api.TopologyReportLineSet; |
|
44 |
import org.gvsig.topology.lib.api.TopologyRule; |
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
47 |
|
|
48 |
/** |
|
49 |
* |
|
50 |
* @author jjdelcerro |
|
51 |
*/ |
|
52 |
@SuppressWarnings("UseSpecificCatch") |
|
53 |
public class DefaultTopologyReport |
|
54 |
extends AbstractTopologyReportLineSet |
|
55 |
implements TopologyReport |
|
56 |
{ |
|
57 |
|
|
58 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTopologyReport.class); |
|
59 |
|
|
60 |
private class DefaultTopologyReportLineSet extends AbstractTopologyReportLineSet { |
|
61 |
|
|
62 |
public DefaultTopologyReportLineSet() { |
|
63 |
super(); |
|
64 |
} |
|
65 |
|
|
66 |
public void polulate(List<TopologyReportLine> allLines, String filter) { |
|
67 |
this.lines.clear(); |
|
68 |
if (filter == null) { |
|
69 |
this.lines.addAll(allLines); |
|
70 |
this.completed = true; |
|
71 |
return; |
|
72 |
} |
|
73 |
SimpleTaskStatus theTaskStatus = plan.getTaskStatus(); |
|
74 |
try { |
|
75 |
theTaskStatus.push(); |
|
76 |
theTaskStatus.restart(); |
|
77 |
theTaskStatus.message("Preparing filter"); |
|
78 |
theTaskStatus.setAutoremove(true); |
|
79 |
theTaskStatus.setIndeterminate(); |
|
80 |
|
|
81 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
82 |
|
|
83 |
TopologyReportLineSymbolTable lineSymbolTable = new TopologyReportLineSymbolTable(); |
|
84 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
|
85 |
symbolTable.addSymbolTable(lineSymbolTable); |
|
86 |
|
|
87 |
Code code = manager.compile(filter); |
|
88 |
code = manager.optimize(symbolTable, code); |
|
89 |
|
|
90 |
theTaskStatus.setRangeOfValues(0, allLines.size()); |
|
91 |
theTaskStatus.setCurValue(0); |
|
92 |
for (TopologyReportLine line : allLines) { |
|
93 |
lineSymbolTable.setLine(line); |
|
94 |
Object value = manager.evaluate(symbolTable, code); |
|
95 |
if (value instanceof Boolean && ((Boolean) value)) { |
|
96 |
this.lines.add(line); |
|
97 |
this.changeListenerHelper.fireEvent(); |
|
98 |
} |
|
99 |
theTaskStatus.incrementCurrentValue(); |
|
100 |
} |
|
101 |
|
|
102 |
} catch (Exception ex) { |
|
103 |
LOGGER.warn("Problems filtering.", ex); |
|
104 |
theTaskStatus.abort(); |
|
105 |
} finally { |
|
106 |
if (theTaskStatus.isRunning()) { |
|
107 |
theTaskStatus.terminate(); |
|
108 |
} |
|
109 |
theTaskStatus.pop(); |
|
110 |
this.completed = true; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
// TODO: Habria que meter las lineas del report en disco |
|
118 |
private final TopologyPlan plan; |
|
119 |
|
|
120 |
private int status; |
|
121 |
|
|
122 |
public DefaultTopologyReport(TopologyPlan plan) { |
|
123 |
this.plan = plan; |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public TopologyReportLine addLine(TopologyRule rule, TopologyDataSet dataSet1, |
|
128 |
TopologyDataSet dataSet2, Geometry geometry, Geometry error, |
|
129 |
FeatureReference feature1, FeatureReference feature2, |
|
130 |
boolean exception, String description |
|
131 |
) { |
|
132 |
TopologyReportLine line = new DefaultTopologyReportLine( |
|
133 |
this, rule, dataSet1, dataSet2, geometry, error, feature1, |
|
134 |
feature2, -1, -1, exception, description, null |
|
135 |
); |
|
136 |
this.lines.add(line); |
|
137 |
this.fireChangeEvent(); |
|
138 |
return line; |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public TopologyReportLine addLine(TopologyRule rule, |
|
143 |
TopologyDataSet dataSet1,TopologyDataSet dataSet2, |
|
144 |
Geometry geometry, Geometry error, |
|
145 |
FeatureReference feature1, FeatureReference feature2, |
|
146 |
int primitive1, int primitive2, |
|
147 |
boolean exception, |
|
148 |
String description, |
|
149 |
String data |
|
150 |
) { |
|
151 |
TopologyReportLine line = new DefaultTopologyReportLine( |
|
152 |
this, rule, dataSet1, dataSet2, geometry, error, feature1, |
|
153 |
feature2, primitive1, primitive2, exception, description, data |
|
154 |
); |
|
155 |
this.lines.add(line); |
|
156 |
this.fireChangeEvent(); |
|
157 |
return line; |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public void removeAllLines() { |
|
162 |
this.lines.clear(); |
|
163 |
this.fireChangeEvent(); |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public TopologyReportLineSet getLineSet(final String filter) { |
|
168 |
final DefaultTopologyReportLineSet set = new DefaultTopologyReportLineSet(); |
|
169 |
Thread th = new Thread(new Runnable() { |
|
170 |
@Override |
|
171 |
public void run() { |
|
172 |
set.polulate(lines, filter); |
|
173 |
} |
|
174 |
}); |
|
175 |
th.start(); |
|
176 |
return set; |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public List<TopologyReportLine> getLines(String filter) { |
|
181 |
if (filter == null) { |
|
182 |
return Collections.unmodifiableList(this.lines); |
|
183 |
} |
|
184 |
List<TopologyReportLine> ll = new ArrayList<>(); |
|
185 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
186 |
|
|
187 |
TopologyReportLineSymbolTable lineSymbolTable = new TopologyReportLineSymbolTable(); |
|
188 |
MutableSymbolTable symbolTable = manager.createSymbolTable(); |
|
189 |
symbolTable.addSymbolTable(lineSymbolTable); |
|
190 |
|
|
191 |
Code code = manager.compile(filter); |
|
192 |
code = manager.optimize(symbolTable, code); |
|
193 |
|
|
194 |
for (TopologyReportLine line : this.lines) { |
|
195 |
lineSymbolTable.setLine(line); |
|
196 |
Object value = manager.evaluate(symbolTable, code); |
|
197 |
if (value instanceof Boolean && ((Boolean) value)) { |
|
198 |
ll.add(line); |
|
199 |
} |
|
200 |
} |
|
201 |
return Collections.unmodifiableList(ll); |
|
202 |
} |
|
203 |
|
|
204 |
@Override |
|
205 |
public int getStatus() { |
|
206 |
for (TopologyReportLine line : lines) { |
|
207 |
if(line.isException()){ |
|
208 |
continue; |
|
209 |
} |
|
210 |
return TopologyManager.TOPOLOGY_PLAN_STATUS_NOT_PASSED; |
|
211 |
} |
|
212 |
return TOPOLOGY_PLAN_STATUS_PASSED; |
|
213 |
} |
|
214 |
|
|
215 |
@Override |
|
216 |
public TopologyReportLine addCodeException(TopologyRule rule, TopologyDataSet dataSet1, Feature feature1, Throwable exception) { |
|
217 |
FeatureReference ref = null; |
|
218 |
if(feature1 != null){ |
|
219 |
ref = feature1.getReference(); |
|
220 |
} |
|
221 |
String msg = null; |
|
222 |
if(exception != null){ |
|
223 |
msg = exception.getLocalizedMessage(); |
|
224 |
} |
|
225 |
return this.addLine(rule, dataSet1, null, null, null, ref, null, false, msg); |
|
226 |
} |
|
227 |
|
|
228 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/TopologyReportLineSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.impl; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
6 |
import org.gvsig.topology.lib.api.TopologyReport; |
|
7 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
|
8 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
* @author jjdelcerro |
|
12 |
*/ |
|
13 |
class TopologyReportLineSymbolTable extends AbstractSymbolTable { |
|
14 |
|
|
15 |
private TopologyReportLine line = null; |
|
16 |
private final List<String> fieldNames; |
|
17 |
|
|
18 |
public TopologyReportLineSymbolTable() { |
|
19 |
this.fieldNames = new ArrayList<>(); |
|
20 |
this.fieldNames.add(TopologyReport.RULE_ID); |
|
21 |
this.fieldNames.add(TopologyReport.IS_ERROR); |
|
22 |
this.fieldNames.add(TopologyReport.IS_EXCEPTION); |
|
23 |
this.fieldNames.add(TopologyReport.GEOMETRY); |
|
24 |
} |
|
25 |
|
|
26 |
public void setLine(TopologyReportLine line) { |
|
27 |
this.line = line; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public boolean exists(String name) { |
|
32 |
if (name == null) { |
|
33 |
return false; |
|
34 |
} |
|
35 |
return this.fieldNames.contains(name.toUpperCase()); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object value(String name) { |
|
40 |
switch (name.toUpperCase()) { |
|
41 |
case TopologyReport.RULE_ID: |
|
42 |
return this.line.getRule().getId(); |
|
43 |
case TopologyReport.IS_ERROR: |
|
44 |
return !this.line.isException(); |
|
45 |
case TopologyReport.IS_EXCEPTION: |
|
46 |
return this.line.isException(); |
|
47 |
case TopologyReport.GEOMETRY: |
|
48 |
return this.line.getGeometry(); |
|
49 |
default: |
|
50 |
return null; |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/AbstractTopologyReportLineSet.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.impl; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collections; |
|
5 |
import java.util.List; |
|
6 |
import javax.swing.event.ChangeListener; |
|
7 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
|
8 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
9 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
|
10 |
import org.gvsig.topology.lib.api.TopologyReportLineSet; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public abstract class AbstractTopologyReportLineSet implements TopologyReportLineSet { |
|
17 |
|
|
18 |
protected final List<TopologyReportLine> lines; |
|
19 |
protected final ChangeListenerHelper changeListenerHelper; |
|
20 |
protected boolean completed = false; |
|
21 |
|
|
22 |
public AbstractTopologyReportLineSet() { |
|
23 |
this.lines = new ArrayList<>(); |
|
24 |
this.changeListenerHelper = ToolsSwingLocator.getToolsSwingManager().createChangeListenerHelper(); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public List<TopologyReportLine> getLines() { |
|
29 |
return Collections.unmodifiableList(this.lines); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void addChangeListener(ChangeListener cl) { |
|
34 |
this.changeListenerHelper.addChangeListener(cl); |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public ChangeListener[] getChangeListeners() { |
|
39 |
return this.changeListenerHelper.getChangeListeners(); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public void removeChangeListener(ChangeListener cl) { |
|
44 |
this.changeListenerHelper.removeChangeListener(cl); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public void removeAllChangeListener() { |
|
49 |
this.changeListenerHelper.removeAllChangeListener(); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public boolean hasChangeListeners() { |
|
54 |
return this.changeListenerHelper.hasChangeListeners(); |
|
55 |
} |
|
56 |
|
|
57 |
protected void fireChangeEvent() { |
|
58 |
this.changeListenerHelper.fireEvent(); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public boolean isComplete() { |
|
63 |
return this.completed; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public int size() { |
|
68 |
return this.lines.size(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public TopologyReportLine get(int index) { |
|
73 |
return this.lines.get(index); |
|
74 |
} |
|
75 |
|
|
76 |
public void setCompleted(boolean completed) { |
|
77 |
this.completed = completed; |
|
78 |
} |
|
79 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/TopologyImplLibrary.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.DALLibrary; |
|
27 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
28 |
import org.gvsig.tools.ToolsLibrary; |
|
29 |
import org.gvsig.tools.library.AbstractLibrary; |
|
30 |
import org.gvsig.tools.library.LibraryException; |
|
31 |
import org.gvsig.topology.lib.api.TopologyLibrary; |
|
32 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
33 |
import org.gvsig.topology.lib.impl.customizablerule.CustomizableRule0ActionsFactory; |
|
34 |
import org.gvsig.topology.rule.GeometryIsValidFactory; |
|
35 |
import org.gvsig.topology.rule.GeometryMustNotBeNullRuleFactory; |
|
36 |
import org.gvsig.topology.rule.LineMustBeCoveredByBoundaryOfPolygonRuleFactory; |
|
37 |
import org.gvsig.topology.rule.PolygonContainsPointRuleFactory; |
|
38 |
import org.gvsig.topology.rule.LineMustBeLargerThanToleranceRuleFactory; |
|
39 |
import org.gvsig.topology.rule.PolygonMustNotOverlapPolygonRuleFactory; |
|
40 |
import org.gvsig.topology.rule.PointMustBeProperlyInsidePolygonRuleFactory; |
|
41 |
import org.gvsig.topology.rule.PolygonContainsOnePointRuleFactory; |
|
42 |
import org.gvsig.topology.rule.PolygonContainsPolygonRuleFactory; |
|
43 |
import org.gvsig.topology.rule.PolygonMustBeCoveredByPolygonRuleFactory; |
|
44 |
import org.gvsig.topology.rule.PolygonMustNotOverlapWithPolygonRuleFactory; |
|
45 |
|
|
46 |
/** |
|
47 |
* |
|
48 |
* @author jjdelcerro |
|
49 |
*/ |
|
50 |
public class TopologyImplLibrary extends AbstractLibrary { |
|
51 |
|
|
52 |
@Override |
|
53 |
public void doRegistration() { |
|
54 |
super.doRegistration(); |
|
55 |
registerAsImplementationOf(TopologyLibrary.class); |
|
56 |
this.require(ToolsLibrary.class); |
|
57 |
this.require(DALLibrary.class); |
|
58 |
this.require(GeometryLibrary.class); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
protected void doInitialize() throws LibraryException { |
|
63 |
TopologyLocator.registerDefaultTopologyManager(DefaultTopologyManager.class); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
protected void doPostInitialize() throws LibraryException { |
|
68 |
CustomizableRule0ActionsFactory.selfRegister(); |
|
69 |
GeometryMustNotBeNullRuleFactory.selfRegister(); |
|
70 |
LineMustBeCoveredByBoundaryOfPolygonRuleFactory.selfRegister(); |
|
71 |
LineMustBeLargerThanToleranceRuleFactory.selfRegister(); |
|
72 |
PointMustBeProperlyInsidePolygonRuleFactory.selfRegister(); |
|
73 |
PolygonContainsPointRuleFactory.selfRegister(); |
|
74 |
PolygonMustBeCoveredByPolygonRuleFactory.selfRegister(); |
|
75 |
PolygonMustNotOverlapPolygonRuleFactory.selfRegister(); |
|
76 |
PolygonContainsPolygonRuleFactory.selfRegister(); |
|
77 |
PolygonContainsOnePointRuleFactory.selfRegister(); |
|
78 |
PolygonMustNotOverlapWithPolygonRuleFactory.selfRegister(); |
|
79 |
GeometryIsValidFactory.selfRegister(); |
|
80 |
} |
|
81 |
|
|
82 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyReportLine.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
29 |
import org.gvsig.topology.lib.api.TopologyReport; |
|
30 |
import org.gvsig.topology.lib.api.TopologyReportLine; |
|
31 |
import org.gvsig.topology.lib.api.TopologyRule; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author jjdelcerro |
|
36 |
*/ |
|
37 |
public class DefaultTopologyReportLine implements TopologyReportLine { |
|
38 |
|
|
39 |
private final TopologyReport report; |
|
40 |
private final TopologyRule rule; |
|
41 |
private final TopologyDataSet dataSet1; |
|
42 |
private final TopologyDataSet dataSet2; |
|
43 |
private final Geometry geometry; |
|
44 |
private final FeatureReference feature1; |
|
45 |
private final FeatureReference feature2; |
|
46 |
private final int primitive1; |
|
47 |
private final int primitive2; |
|
48 |
private boolean exception; |
|
49 |
private final String description; |
|
50 |
private final String data; |
|
51 |
private final Geometry errorGeometry; |
|
52 |
|
|
53 |
DefaultTopologyReportLine(DefaultTopologyReport report, |
|
54 |
TopologyRule rule, |
|
55 |
TopologyDataSet dataSet1, |
|
56 |
TopologyDataSet dataSet2, |
|
57 |
Geometry geometry, |
|
58 |
Geometry error, |
|
59 |
FeatureReference feature1, |
|
60 |
FeatureReference feature2, |
|
61 |
int primitive1, |
|
62 |
int primitive2, |
|
63 |
boolean exception, |
|
64 |
String description, |
|
65 |
String data |
|
66 |
) { |
|
67 |
this.report = report; |
|
68 |
this.rule = rule; |
|
69 |
this.dataSet1 = dataSet1; |
|
70 |
this.dataSet2 = dataSet2; |
|
71 |
this.geometry = geometry; |
|
72 |
this.feature1 = feature1; |
|
73 |
this.feature2 = feature2; |
|
74 |
this.primitive1 = primitive1; |
|
75 |
this.primitive2 = primitive2; |
|
76 |
this.exception = exception; |
|
77 |
this.description = description; |
|
78 |
this.errorGeometry = error; |
|
79 |
this.data = data; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public TopologyRule getRule() { |
|
84 |
return this.rule; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public TopologyDataSet getDataSet1() { |
|
89 |
return this.dataSet1; |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public TopologyDataSet getDataSet2() { |
|
94 |
return this.dataSet2; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public Geometry getGeometry() { |
|
99 |
return this.geometry; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public FeatureReference getFeature1() { |
|
104 |
return this.feature1; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public FeatureReference getFeature2() { |
|
109 |
return this.feature2; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public boolean isException() { |
|
114 |
return this.exception; |
|
115 |
} |
|
116 |
|
|
117 |
public void setException(boolean exception) { |
|
118 |
this.exception = exception; |
|
119 |
} |
|
120 |
|
|
121 |
@Override |
|
122 |
public String getDescription() { |
|
123 |
return description; |
|
124 |
} |
|
125 |
|
|
126 |
@Override |
|
127 |
public Geometry getError() { |
|
128 |
return this.errorGeometry; |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public int getPrimitiveNumber1() { |
|
133 |
return this.primitive1; |
|
134 |
} |
|
135 |
|
|
136 |
@Override |
|
137 |
public int getPrimitiveNumber2() { |
|
138 |
return this.primitive2; |
|
139 |
} |
|
140 |
|
|
141 |
@Override |
|
142 |
public String getData() { |
|
143 |
return this.data; |
|
144 |
} |
|
145 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.119/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyDataSet.java | ||
---|---|---|
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.topology.lib.impl; |
|
25 |
|
|
26 |
import java.util.Iterator; |
|
27 |
import java.util.Map; |
|
28 |
import javax.json.JsonObject; |
|
29 |
import org.apache.commons.collections.IteratorUtils; |
|
30 |
import org.apache.commons.lang3.StringUtils; |
|
31 |
import org.apache.commons.lang3.mutable.MutableObject; |
|
32 |
import org.gvsig.expressionevaluator.Expression; |
|
33 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
34 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
35 |
import org.gvsig.expressionevaluator.GeometryExpressionUtils; |
|
36 |
import org.gvsig.fmap.dal.DataStore; |
|
37 |
import org.gvsig.fmap.dal.EditingNotification; |
|
38 |
import org.gvsig.fmap.dal.EditingNotificationManager; |
|
39 |
import org.gvsig.fmap.dal.exception.DataException; |
|
40 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
41 |
import org.gvsig.fmap.dal.feature.Feature; |
|
42 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
43 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
44 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
46 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
47 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
48 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
|
49 |
import org.gvsig.fmap.geom.Geometry; |
|
50 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
51 |
import org.gvsig.fmap.geom.GeometryManager; |
|
52 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
53 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
54 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
55 |
import org.gvsig.json.Json; |
|
56 |
import org.gvsig.json.JsonObjectBuilder; |
|
57 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
58 |
import org.gvsig.tools.exception.BaseException; |
|
59 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
|
60 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
61 |
import org.gvsig.tools.visitor.Visitor; |
|
62 |
import org.gvsig.topology.lib.api.CancelOperationException; |
|
63 |
import org.gvsig.topology.lib.api.PerformOperationException; |
|
64 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
65 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
66 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
67 |
import org.gvsig.topology.lib.api.TopologyServices; |
|
68 |
import org.slf4j.Logger; |
|
69 |
import org.slf4j.LoggerFactory; |
|
70 |
|
|
71 |
/** |
|
72 |
* |
|
73 |
* @author jjdelcerro |
|
74 |
*/ |
|
75 |
@SuppressWarnings({"EqualsAndHashcode","UseSpecificCatch"}) |
|
76 |
public class DefaultTopologyDataSet implements TopologyDataSet { |
|
77 |
|
|
78 |
private final static Logger LOGGER = LoggerFactory.getLogger(DefaultTopologyDataSet.class); |
|
79 |
|
|
80 |
private TopologyServices services; |
|
81 |
private String name; |
|
82 |
private DataStore store; |
|
83 |
private boolean needFinishEditing; |
|
84 |
private String fullName; |
|
85 |
private PropertiesSupportHelper propertiesHelper; |
|
86 |
private MutableObject<SpatialIndex> spatialIndex = null; |
|
87 |
|
|
88 |
public DefaultTopologyDataSet() { |
|
89 |
this.services = null; |
|
90 |
this.name = null; |
|
91 |
this.store = null; |
|
92 |
this.needFinishEditing = false; |
|
93 |
this.fullName = null; |
|
94 |
this.propertiesHelper = new PropertiesSupportHelper(); |
|
95 |
} |
|
96 |
|
|
97 |
public DefaultTopologyDataSet(TopologyServices services, String name, DataStore store) { |
|
98 |
this.services = services; |
|
99 |
this.name = name; |
|
100 |
this.store = store; |
|
101 |
this.needFinishEditing = false; |
|
102 |
if( store!=null ) { |
|
103 |
this.fullName = store.getFullName(); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public void restart() { |
|
109 |
this.store = null; |
|
110 |
this.spatialIndex = null; |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean equals(Object obj) { |
|
115 |
if( !(obj instanceof DefaultTopologyDataSet) ) { |
|
116 |
return false; |
|
117 |
} |
|
118 |
DefaultTopologyDataSet other = (DefaultTopologyDataSet)obj; |
|
119 |
if( this.store != other.store ) { |
|
120 |
return false; |
|
121 |
} |
|
122 |
if( !StringUtils.equals(this.getName(), other.getName()) ) { |
|
123 |
return false; |
|
124 |
} |
|
125 |
return true; |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public String getName() { |
|
130 |
return this.name; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void setName(String name) { |
|
135 |
this.name = name; |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
public String toString() { |
|
140 |
try { |
|
141 |
FeatureAttributeDescriptor attr = this.getFeatureStore().getDefaultFeatureType().getDefaultGeometryAttribute(); |
|
142 |
String geomType = attr.getGeomType().getName(); |
|
143 |
return this.name + " ("+ geomType + ")"; |
|
144 |
} catch(Exception ex) { |
|
145 |
return this.name ; |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public void setStore(DataStore store) { |
|
151 |
this.store = store; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public DataStore getStore() { |
|
156 |
if (this.store == null) { |
|
157 |
this.store = this.services.getFeatureStore(this); |
|
158 |
} |
|
159 |
return this.store; |
|
160 |
} |
|
161 |
|
|
162 |
@Override |
|
163 |
public FeatureStore getFeatureStore() { |
|
164 |
if (this.store == null) { |
|
165 |
this.store = this.services.getFeatureStore(this); |
|
166 |
} |
|
167 |
return (FeatureStore) this.store; |
|
168 |
} |
|
169 |
|
|
170 |
@Override |
|
171 |
public long getSize() { |
|
172 |
try { |
|
173 |
long size = this.getFeatureStore().getFeatureCount(); |
|
174 |
return size; |
|
175 |
} catch (DataException ex) { |
|
176 |
// TODO: mensage al log |
|
177 |
return 0; |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public boolean isThisStore(FeatureStore store) { |
|
183 |
if( store == null ) { |
|
184 |
return false; |
|
185 |
} |
|
186 |
return StringUtils.equals(this.fullName, store.getFullName()); |
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
public int getGeometryType() { |
|
191 |
try { |
|
192 |
FeatureStore theStore = this.getFeatureStore(); |
|
193 |
FeatureType featureType = theStore.getDefaultFeatureType(); |
|
194 |
FeatureAttributeDescriptor attr = featureType.getDefaultGeometryAttribute(); |
|
195 |
GeometryType geomType = attr.getGeomType(); |
|
196 |
return geomType.getType(); |
|
197 |
} catch (Exception ex) { |
|
198 |
return Geometry.TYPES.GEOMETRY; |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public void accept(Visitor visitor) throws VisitCanceledException { |
|
204 |
FeatureStore st = this.getFeatureStore(); |
|
205 |
try { |
|
206 |
st.accept(visitor); |
|
207 |
} catch(VisitCanceledException ex) { |
|
208 |
throw ex; |
|
209 |
} catch(BaseException ex) { |
|
210 |
throw new RuntimeException(ex); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public void edit() throws DataException { |
|
216 |
FeatureStore theStore = this.getFeatureStore(); |
|
217 |
if (!theStore.isEditing()) { |
|
218 |
theStore.edit(); |
|
219 |
this.needFinishEditing = true; |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
@Override |
|
224 |
public void finishEditing() throws DataException { |
|
225 |
if (this.needFinishEditing) { |
|
226 |
this.getFeatureStore().finishEditing(); |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public EditableFeature createNewFeature() throws DataException { |
|
232 |
EditableFeature f = this.getFeatureStore().createNewFeature(); |
|
233 |
return f; |
|
234 |
} |
|
235 |
|
|
236 |
public void perform( |
|
237 |
String operation, |
|
238 |
Feature feature |
|
239 |
) throws DataException { |
|
240 |
this.edit(); |
|
241 |
|
|
242 |
EditingNotificationManager editingNotificationManager |
|
243 |
= DALSwingLocator.getEditingNotificationManager(); |
|
244 |
FeatureStore theStore = this.getFeatureStore(); |
|
245 |
|
|
246 |
EditingNotification notification |
|
247 |
= editingNotificationManager.notifyObservers(this, // source |
|
248 |
operation, // type |
|
249 |
null,// document |
|
250 |
null,// layer |
|
251 |
theStore,// store |
|
252 |
feature// feature |
|
253 |
); |
|
254 |
|
|
255 |
if (notification.isCanceled()) { |
|
256 |
String msg = String.format( |
|
257 |
"Can't insert feature into %1$s, canceled by some observer.", |
|
258 |
this.getName()); |
|
259 |
throw new CancelOperationException(msg); |
|
260 |
} |
|
261 |
|
|
262 |
String after = null; |
|
263 |
if( operation.equalsIgnoreCase(EditingNotification.BEFORE_REMOVE_FEATURE) ) { |
|
264 |
theStore.delete(feature); |
|
265 |
after = EditingNotification.AFTER_REMOVE_FEATURE; |
|
266 |
|
|
267 |
} else { |
|
268 |
if (notification.shouldValidateTheFeature()) { |
|
269 |
if (!editingNotificationManager.validateFeature(feature)) { |
|
270 |
String msg = String.format("%1$s is not valid", feature.toString()); |
|
271 |
throw new PerformOperationException(msg); |
|
272 |
} |
|
273 |
} |
|
274 |
switch(operation) { |
|
275 |
case EditingNotification.BEFORE_UPDATE_FEATURE: |
|
276 |
theStore.update((EditableFeature) feature); |
|
277 |
after = EditingNotification.AFTER_UPDATE_FEATURE; |
|
278 |
break; |
|
279 |
|
|
280 |
case EditingNotification.BEFORE_INSERT_FEATURE: |
|
281 |
theStore.insert((EditableFeature) feature); |
|
282 |
after = EditingNotification.AFTER_INSERT_FEATURE; |
|
283 |
break; |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
editingNotificationManager.notifyObservers(this, |
|
288 |
after, null, null, |
|
289 |
theStore, feature); |
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public void insert(final EditableFeature feature) throws DataException { |
|
295 |
perform( |
|
296 |
EditingNotification.BEFORE_INSERT_FEATURE, |
|
297 |
feature |
|
298 |
); |
|
299 |
} |
|
300 |
|
|
301 |
@Override |
|
302 |
public void update(final EditableFeature feature) throws DataException { |
|
303 |
perform( |
|
304 |
EditingNotification.BEFORE_UPDATE_FEATURE, |
|
305 |
feature |
|
306 |
); |
|
307 |
} |
|
308 |
|
|
309 |
@Override |
|
310 |
public void delete(final Feature feature) throws DataException { |
|
311 |
perform( |
|
312 |
EditingNotification.BEFORE_REMOVE_FEATURE, |
|
313 |
feature |
|
314 |
); |
|
315 |
} |
|
316 |
|
|
317 |
@Override |
|
318 |
public void delete(final FeatureReference feature) throws DataException { |
|
319 |
perform( |
|
320 |
EditingNotification.BEFORE_REMOVE_FEATURE, |
|
321 |
feature.getFeature() |
|
322 |
); |
|
323 |
} |
|
324 |
|
|
325 |
@Override |
|
326 |
public JsonObject toJson() { |
|
327 |
return this.toJsonBuilder().build(); |
|
328 |
} |
|
329 |
|
|
330 |
@Override |
|
331 |
public JsonObjectBuilder toJsonBuilder() { |
|
332 |
JsonObjectBuilder jsonDataSet = Json.createObjectBuilder(); |
Also available in: Unified diff