Revision 886
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRuleAction.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.topology.lib.spi; |
25 | 25 |
|
26 |
import java.net.URL; |
|
26 | 27 |
import org.gvsig.tools.dynobject.DynObject; |
27 | 28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
28 | 29 |
import org.gvsig.topology.lib.api.TopologyRuleAction; |
... | ... | |
85 | 86 |
} |
86 | 87 |
|
87 | 88 |
private void load_from_resource() { |
88 |
JSONObject rule = RuleResourceLoaderUtils.getRule(this.idRule); |
|
89 |
URL url = RuleResourceLoaderUtils.getRuleURL(this.idRule); |
|
90 |
JSONObject rule = RuleResourceLoaderUtils.getRule(url); |
|
91 |
load_from_resource(url, rule); |
|
92 |
} |
|
93 |
|
|
94 |
protected void load_from_resource(URL jsonUrl, JSONObject rule) { |
|
89 | 95 |
if( rule == null ) { |
90 | 96 |
return; |
91 | 97 |
} |
... | ... | |
94 | 100 |
this.name = action.getString("name"); |
95 | 101 |
} |
96 | 102 |
if( action.has("description") ) { |
97 |
this.shortDescription = RuleResourceLoaderUtils.getDescription(this.idRule, action);
|
|
103 |
this.shortDescription = RuleResourceLoaderUtils.getDescription(jsonUrl, action);
|
|
98 | 104 |
} |
99 | 105 |
} |
100 | 106 |
|
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/RuleResourceLoaderUtils.java | ||
---|---|---|
11 | 11 |
import java.net.URL; |
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Locale; |
14 |
import java.util.logging.Level;
|
|
14 |
import org.apache.commons.io.FilenameUtils;
|
|
15 | 15 |
import org.apache.commons.io.IOUtils; |
16 | 16 |
import org.apache.commons.lang3.StringUtils; |
17 | 17 |
import org.json.JSONArray; |
... | ... | |
87 | 87 |
} |
88 | 88 |
} |
89 | 89 |
|
90 |
public static String getDescription(String idRule, JSONObject json) {
|
|
90 |
public static String getDescription(URL jsonUrl, JSONObject json) {
|
|
91 | 91 |
String description = null; |
92 | 92 |
|
93 | 93 |
if( json.has("description") ) { |
... | ... | |
110 | 110 |
description = StringUtils.replace( |
111 | 111 |
description, |
112 | 112 |
"@@@", |
113 |
getRuleURL(idRule).toString()
|
|
113 |
FilenameUtils.removeExtension(jsonUrl.toString())
|
|
114 | 114 |
); |
115 | 115 |
} |
116 | 116 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRuleFactory.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.topology.lib.spi; |
25 | 25 |
|
26 |
import java.net.URL; |
|
26 | 27 |
import java.util.List; |
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 | 28 |
import org.gvsig.fmap.geom.GeometryLocator; |
29 | 29 |
import org.gvsig.fmap.geom.GeometryManager; |
30 |
import org.gvsig.tools.util.ListBuilder; |
|
31 | 30 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
32 | 31 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
33 | 32 |
import org.json.JSONObject; |
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
34 | 35 |
|
35 | 36 |
/** |
36 | 37 |
* |
37 | 38 |
* @author jjdelcerro |
38 | 39 |
*/ |
39 | 40 |
public abstract class AbstractTopologyRuleFactory implements TopologyRuleFactory { |
41 |
|
|
42 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTopologyRuleFactory.class); |
|
43 |
|
|
40 | 44 |
private final String id; |
41 |
private String name;
|
|
42 |
private String description;
|
|
45 |
protected String name;
|
|
46 |
protected String description;
|
|
43 | 47 |
private final List<Integer> geometryTypeDataSet1; |
44 | 48 |
private final List<Integer> geometryTypeDataSet2; |
45 | 49 |
|
... | ... | |
128 | 132 |
} |
129 | 133 |
return false; |
130 | 134 |
} |
131 |
|
|
135 |
|
|
132 | 136 |
private void load_from_resource() { |
133 |
JSONObject json = RuleResourceLoaderUtils.getRule(this.id); |
|
137 |
URL url = RuleResourceLoaderUtils.getRuleURL(this.id); |
|
138 |
JSONObject json = RuleResourceLoaderUtils.getRule(url); |
|
139 |
load_from_resource(url, json); |
|
140 |
} |
|
141 |
|
|
142 |
protected void load_from_resource(URL jsonUrl, JSONObject json) { |
|
134 | 143 |
if( json == null ) { |
135 | 144 |
return; |
136 | 145 |
} |
... | ... | |
138 | 147 |
this.name = json.getString("name"); |
139 | 148 |
} |
140 | 149 |
if( json.has("description") ) { |
141 |
this.description = RuleResourceLoaderUtils.getDescription(this.id, json);
|
|
150 |
this.description = RuleResourceLoaderUtils.getDescription(jsonUrl, json);
|
|
142 | 151 |
} |
143 | 152 |
} |
144 | 153 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/DefaultTopologyManager.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.util.ArrayList; |
27 | 27 |
import java.util.Collections; |
28 |
import java.util.HashMap; |
|
28 | 29 |
import java.util.List; |
29 |
import org.apache.commons.lang3.StringUtils;
|
|
30 |
import java.util.Map;
|
|
30 | 31 |
import org.gvsig.fmap.dal.DataStore; |
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
32 | 32 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
33 | 33 |
import org.gvsig.topology.lib.api.TopologyManager; |
34 | 34 |
import org.gvsig.topology.lib.api.TopologyPlan; |
... | ... | |
41 | 41 |
*/ |
42 | 42 |
public class DefaultTopologyManager implements TopologyManager { |
43 | 43 |
|
44 |
private final List<TopologyRuleFactory> factories;
|
|
44 |
private final Map<String,TopologyRuleFactory> factories;
|
|
45 | 45 |
private TopologyServices services; |
46 | 46 |
|
47 | 47 |
public DefaultTopologyManager() { |
48 |
this.factories = new ArrayList<>();
|
|
48 |
this.factories = new HashMap<>();
|
|
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
@Override |
... | ... | |
56 | 56 |
|
57 | 57 |
@Override |
58 | 58 |
public List<TopologyRuleFactory> getRuleFactories() { |
59 |
return Collections.unmodifiableList(this.factories); |
|
59 |
List<TopologyRuleFactory> l = new ArrayList<>(this.factories.values()); |
|
60 |
return Collections.unmodifiableList(l); |
|
60 | 61 |
} |
61 | 62 |
|
62 | 63 |
@Override |
63 | 64 |
public List<TopologyRuleFactory> getRuleFactories(TopologyDataSet dataSet) { |
64 | 65 |
List<TopologyRuleFactory> f = new ArrayList<>(); |
65 |
for (TopologyRuleFactory factory : this.factories) { |
|
66 |
for (TopologyRuleFactory factory : this.factories.values()) {
|
|
66 | 67 |
if( factory.canApplyToDataSet(dataSet) ) { |
67 | 68 |
f.add(factory); |
68 | 69 |
} |
... | ... | |
72 | 73 |
|
73 | 74 |
@Override |
74 | 75 |
public TopologyRuleFactory getRulefactory(String id) { |
75 |
for (TopologyRuleFactory factory : this.factories) { |
|
76 |
if( StringUtils.equalsIgnoreCase(id, factory.getId()) ) { |
|
77 |
return factory; |
|
78 |
} |
|
76 |
if( id==null ) { |
|
77 |
return null; |
|
79 | 78 |
} |
80 |
return null; |
|
79 |
TopologyRuleFactory factory = this.factories.get(id.toLowerCase()); |
|
80 |
return factory; |
|
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
@Override |
84 | 84 |
public void addRuleFactories(TopologyRuleFactory factory) { |
85 |
this.factories.add(factory); |
|
85 |
if( factory==null ) { |
|
86 |
throw new IllegalArgumentException("Invalid null value."); |
|
87 |
} |
|
88 |
this.factories.put(factory.getId().toLowerCase(), factory); |
|
86 | 89 |
} |
87 | 90 |
|
88 | 91 |
@Override |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/lib/impl/TopologyImplLibrary.java | ||
---|---|---|
59 | 59 |
|
60 | 60 |
@Override |
61 | 61 |
protected void doPostInitialize() throws LibraryException { |
62 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
63 |
manager.addRuleFactories(new ContainsNullRuleFactory()); |
|
64 |
manager.addRuleFactories(new ContainsPointRuleFactory()); |
|
65 |
manager.addRuleFactories(new MustBeLargerThanToleranceLineRuleFactory()); |
|
66 |
manager.addRuleFactories(new MustNotOverlapPolygonRuleFactory()); |
|
67 |
manager.addRuleFactories(new PointMustBeProperlyInsidePolygonRuleFactory()); |
|
62 |
ContainsNullRuleFactory.selfRegister(); |
|
63 |
ContainsPointRuleFactory.selfRegister(); |
|
64 |
MustBeLargerThanToleranceLineRuleFactory.selfRegister(); |
|
65 |
MustNotOverlapPolygonRuleFactory.selfRegister(); |
|
66 |
PointMustBeProperlyInsidePolygonRuleFactory.selfRegister(); |
|
68 | 67 |
} |
69 | 68 |
|
70 | 69 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsPointRuleFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.tools.util.ListBuilder; |
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
28 | 30 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory; |
29 | 31 |
import org.gvsig.topology.lib.api.TopologyPlan; |
30 | 32 |
import org.gvsig.topology.lib.api.TopologyRule; |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @author jjdelcerro |
35 | 37 |
*/ |
38 |
@SuppressWarnings("UseSpecificCatch") |
|
36 | 39 |
public class ContainsPointRuleFactory extends AbstractTopologyRuleFactory { |
37 | 40 |
|
38 | 41 |
public static final String NAME = "ContainsPoint"; |
... | ... | |
58 | 61 |
return rule; |
59 | 62 |
} |
60 | 63 |
|
64 |
public static void selfRegister() { |
|
65 |
try { |
|
66 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
67 |
manager.addRuleFactories(new ContainsPointRuleFactory()); |
|
68 |
} catch(Exception ex) { |
|
69 |
LOGGER.warn("Can't register topology rule from ContainsPointRuleFactory.", ex); |
|
70 |
} |
|
71 |
} |
|
61 | 72 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/ContainsNullRuleFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.tools.util.ListBuilder; |
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
28 | 30 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory; |
29 | 31 |
import org.gvsig.topology.lib.api.TopologyPlan; |
30 | 32 |
import org.gvsig.topology.lib.api.TopologyRule; |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @author jjdelcerro |
35 | 37 |
*/ |
38 |
@SuppressWarnings("UseSpecificCatch") |
|
36 | 39 |
public class ContainsNullRuleFactory extends AbstractTopologyRuleFactory { |
37 | 40 |
|
38 | 41 |
public static final String NAME = "ContainsNull"; |
... | ... | |
55 | 58 |
return rule; |
56 | 59 |
} |
57 | 60 |
|
61 |
|
|
62 |
public static void selfRegister() { |
|
63 |
try { |
|
64 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
65 |
manager.addRuleFactories(new ContainsNullRuleFactory()); |
|
66 |
} catch(Exception ex) { |
|
67 |
LOGGER.warn("Can't register topology rule from ContainsNullRuleFactory.", ex); |
|
68 |
} |
|
69 |
} |
|
58 | 70 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustNotOverlapPolygonRuleFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.tools.util.ListBuilder; |
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
28 | 30 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory; |
29 | 31 |
import org.gvsig.topology.lib.api.TopologyPlan; |
30 | 32 |
import org.gvsig.topology.lib.api.TopologyRule; |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @author jjdelcerro |
35 | 37 |
*/ |
38 |
@SuppressWarnings("UseSpecificCatch") |
|
36 | 39 |
public class MustNotOverlapPolygonRuleFactory extends AbstractTopologyRuleFactory { |
37 | 40 |
|
38 | 41 |
public static final String NAME = "MustNotOverlapPolygon"; |
... | ... | |
56 | 59 |
return rule; |
57 | 60 |
} |
58 | 61 |
|
62 |
public static void selfRegister() { |
|
63 |
try { |
|
64 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
65 |
manager.addRuleFactories(new MustNotOverlapPolygonRuleFactory()); |
|
66 |
} catch(Exception ex) { |
|
67 |
LOGGER.warn("Can't register topology rule from MustNotOverlapPolygonRuleFactory.", ex); |
|
68 |
} |
|
69 |
} |
|
59 | 70 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/PointMustBeProperlyInsidePolygonRuleFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.tools.util.ListBuilder; |
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
28 | 30 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory; |
29 | 31 |
import org.gvsig.topology.lib.api.TopologyPlan; |
30 | 32 |
import org.gvsig.topology.lib.api.TopologyRule; |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @author jjdelcerro |
35 | 37 |
*/ |
38 |
@SuppressWarnings("UseSpecificCatch") |
|
36 | 39 |
public class PointMustBeProperlyInsidePolygonRuleFactory extends AbstractTopologyRuleFactory { |
37 | 40 |
|
38 | 41 |
public static final String NAME = "PointMustBeProperlyInsidePolygon"; |
... | ... | |
58 | 61 |
return rule; |
59 | 62 |
} |
60 | 63 |
|
64 |
public static void selfRegister() { |
|
65 |
try { |
|
66 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
67 |
manager.addRuleFactories(new PointMustBeProperlyInsidePolygonRuleFactory()); |
|
68 |
} catch(Exception ex) { |
|
69 |
LOGGER.warn("Can't register topology rule from PointMustBeProperlyInsidePolygonRuleFactory.", ex); |
|
70 |
} |
|
71 |
} |
|
61 | 72 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/java/org/gvsig/topology/rule/MustBeLargerThanToleranceLineRuleFactory.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.fmap.geom.Geometry; |
27 | 27 |
import org.gvsig.tools.util.ListBuilder; |
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
28 | 30 |
import org.gvsig.topology.lib.spi.AbstractTopologyRuleFactory; |
29 | 31 |
import org.gvsig.topology.lib.api.TopologyPlan; |
30 | 32 |
import org.gvsig.topology.lib.api.TopologyRule; |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @author jjdelcerro |
35 | 37 |
*/ |
38 |
@SuppressWarnings("UseSpecificCatch") |
|
36 | 39 |
public class MustBeLargerThanToleranceLineRuleFactory extends AbstractTopologyRuleFactory { |
37 | 40 |
|
38 | 41 |
public static final String NAME = "MustBeLargerThanToleranceLine"; |
... | ... | |
54 | 57 |
return rule; |
55 | 58 |
} |
56 | 59 |
|
60 |
public static void selfRegister() { |
|
61 |
try { |
|
62 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
63 |
manager.addRuleFactories(new MustBeLargerThanToleranceLineRuleFactory()); |
|
64 |
} catch(Exception ex) { |
|
65 |
LOGGER.warn("Can't register topology rule from MustBeLargerThanToleranceLineRuleFactory.", ex); |
|
66 |
} |
|
67 |
} |
|
57 | 68 |
} |
org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.impl/src/main/resources/org/gvsig/topology/rules/en/ContainsPoint.json | ||
---|---|---|
8 | 8 |
"point from the secondary dataset.\n", |
9 | 9 |
"Points must be within the polygon, not on the boundary.\n", |
10 | 10 |
"This is useful when every polygon should have at least one associated", |
11 |
"point, such as when parcels must have an address point. |
|
11 |
"point, such as when parcels must have an address point."
|
|
12 | 12 |
], |
13 | 13 |
"actions" : { |
14 | 14 |
"CreateFeature": { |
Also available in: Unified diff