Revision 8122
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyServices.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.api; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author jjdelcerro |
|
31 |
*/ |
|
32 |
public interface TopologyServices { |
|
33 |
|
|
34 |
public FeatureStore getFeatureStore(TopologyDataSet dataSet); |
|
35 |
|
|
36 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyReportLine.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.api; |
|
25 |
|
|
26 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author jjdelcerro |
|
32 |
*/ |
|
33 |
public interface TopologyReportLine { |
|
34 |
|
|
35 |
public TopologyRule getRule(); |
|
36 |
|
|
37 |
public TopologyDataSet getDataSet1(); |
|
38 |
|
|
39 |
public TopologyDataSet getDataSet2(); |
|
40 |
|
|
41 |
public Geometry getGeometry(); |
|
42 |
|
|
43 |
public Geometry getError(); |
|
44 |
|
|
45 |
public FeatureReference getFeature1(); |
|
46 |
|
|
47 |
public FeatureReference getFeature2(); |
|
48 |
|
|
49 |
public int getPrimitiveNumber1(); |
|
50 |
|
|
51 |
public int getPrimitiveNumber2(); |
|
52 |
|
|
53 |
public boolean isException(); |
|
54 |
|
|
55 |
public String getDescription(); |
|
56 |
|
|
57 |
public String getData(); |
|
58 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyDataSet.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.api; |
|
25 |
|
|
26 |
import org.gvsig.expressionevaluator.Expression; |
|
27 |
import org.gvsig.fmap.dal.DataStore; |
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
|
29 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
30 |
import org.gvsig.fmap.dal.feature.Feature; |
|
31 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
33 |
import org.gvsig.fmap.geom.Geometry; |
|
34 |
import org.gvsig.fmap.geom.SpatialIndex; |
|
35 |
import org.gvsig.json.SupportJson; |
|
36 |
import org.gvsig.tools.util.PropertiesSupport; |
|
37 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
38 |
import org.gvsig.tools.visitor.Visitor; |
|
39 |
|
|
40 |
/** |
|
41 |
* |
|
42 |
* @author jjdelcerro |
|
43 |
*/ |
|
44 |
public interface TopologyDataSet extends PropertiesSupport, SupportJson { |
|
45 |
|
|
46 |
public static interface Operation { |
|
47 |
public void run() throws DataException; |
|
48 |
} |
|
49 |
|
|
50 |
public void setName(String name); |
|
51 |
|
|
52 |
public String getName(); |
|
53 |
|
|
54 |
public void setStore(DataStore store); |
|
55 |
|
|
56 |
public DataStore getStore(); |
|
57 |
|
|
58 |
public FeatureStore getFeatureStore(); |
|
59 |
|
|
60 |
public boolean isThisStore(FeatureStore featureStore); |
|
61 |
|
|
62 |
public int getGeometryType() ; |
|
63 |
|
|
64 |
public void accept(Visitor visitor) throws VisitCanceledException; |
|
65 |
|
|
66 |
public void edit() throws DataException; |
|
67 |
|
|
68 |
public void finishEditing() throws DataException; |
|
69 |
|
|
70 |
public EditableFeature createNewFeature() throws DataException; |
|
71 |
|
|
72 |
public void delete(FeatureReference feature) throws DataException; |
|
73 |
|
|
74 |
public void delete(Feature feature) throws DataException; |
|
75 |
|
|
76 |
public void insert(EditableFeature feature) throws DataException; |
|
77 |
|
|
78 |
public void update(EditableFeature feature) throws DataException; |
|
79 |
|
|
80 |
public long getSize(); |
|
81 |
|
|
82 |
public SpatialIndex getSpatialIndex(); |
|
83 |
|
|
84 |
/** |
|
85 |
* @param geom |
|
86 |
* @return |
|
87 |
* @deprecated use queryFeatures or queryReferences |
|
88 |
*/ |
|
89 |
public Iterable<FeatureReference> query(Geometry geom); |
|
90 |
|
|
91 |
public Iterable<Feature> queryFeatures(Geometry geom); |
|
92 |
|
|
93 |
public Iterable<FeatureReference> queryReferences(Geometry geom); |
|
94 |
|
|
95 |
public Feature findFirst(Expression expression); |
|
96 |
|
|
97 |
public void restart(); |
|
98 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/CancelOperationException.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.api; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.exception.DataException; |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
* @author jjdelcerro |
|
8 |
*/ |
|
9 |
public class CancelOperationException extends DataException { |
|
10 |
|
|
11 |
public CancelOperationException(String msg) { |
|
12 |
super("_CancelOperationException", msg, 0); |
|
13 |
} |
|
14 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyPlan.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.api; |
|
25 |
|
|
26 |
import java.util.Collection; |
|
27 |
import org.gvsig.fmap.dal.DataStore; |
|
28 |
import org.gvsig.json.SupportJson; |
|
29 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author jjdelcerro |
|
34 |
*/ |
|
35 |
public interface TopologyPlan extends SupportJson, TopologyDataSetResolver { |
|
36 |
|
|
37 |
|
|
38 |
public String getName(); |
|
39 |
|
|
40 |
public void setName(String name); |
|
41 |
|
|
42 |
public double getTolerance(); |
|
43 |
|
|
44 |
public void setTolerance(double tolerance); |
|
45 |
|
|
46 |
public void clear(); |
|
47 |
|
|
48 |
public void setTopologyServices(TopologyServices services); |
|
49 |
|
|
50 |
public TopologyServices getTopologyServices(); |
|
51 |
|
|
52 |
public SimpleTaskStatus getTaskStatus(); |
|
53 |
|
|
54 |
public void execute(); |
|
55 |
|
|
56 |
public TopologyDataSet addDataSet(String name, DataStore store); |
|
57 |
|
|
58 |
public TopologyDataSet addDataSet(TopologyDataSet dataSet); |
|
59 |
|
|
60 |
public void removeDataSet(TopologyDataSet dataSet); |
|
61 |
|
|
62 |
public boolean containsDataSet(String name); |
|
63 |
|
|
64 |
@Override |
|
65 |
public TopologyDataSet getDataSet(String name); |
|
66 |
|
|
67 |
public Collection<TopologyDataSet> getDataSets(); |
|
68 |
|
|
69 |
public Collection<TopologyDataSet> getSecondaryDataSets(TopologyRuleFactory ruleFactory); |
|
70 |
|
|
71 |
public TopologyRule addRule(String id, String dataSet1, String dataSet2, double tolerance); |
|
72 |
|
|
73 |
public TopologyRule addRule(TopologyRule rule); |
|
74 |
|
|
75 |
public void removeRule(TopologyRule rule); |
|
76 |
|
|
77 |
public Collection<TopologyRule> getRules(); |
|
78 |
|
|
79 |
public boolean hasRules(); |
|
80 |
|
|
81 |
public TopologyReport getReport(); |
|
82 |
|
|
83 |
public boolean canUseUI(); |
|
84 |
|
|
85 |
public void setUseUI(boolean useUI); |
|
86 |
|
|
87 |
public int getLastStatus(); |
|
88 |
|
|
89 |
public boolean getAcceptExceptions(); |
|
90 |
|
|
91 |
public void setAcceptExceptions(boolean acceptExceptions); |
|
92 |
|
|
93 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyReportLineSet.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.api; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import org.gvsig.tools.swing.api.ChangeListenerSupport; |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
* @author jjdelcerro |
|
9 |
*/ |
|
10 |
public interface TopologyReportLineSet extends ChangeListenerSupport { |
|
11 |
|
|
12 |
public List<TopologyReportLine> getLines(); |
|
13 |
|
|
14 |
public boolean isComplete(); |
|
15 |
|
|
16 |
public int size(); |
|
17 |
|
|
18 |
public TopologyReportLine get(int index); |
|
19 |
|
|
20 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyRuleFactory.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.api; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
import org.gvsig.tools.dynobject.DynObject; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author jjdelcerro |
|
32 |
*/ |
|
33 |
public interface TopologyRuleFactory { |
|
34 |
|
|
35 |
public String getId(); |
|
36 |
|
|
37 |
public String getName(); |
|
38 |
|
|
39 |
public String getDescription(); |
|
40 |
|
|
41 |
public List<Integer> getGeometryTypeDataSet1(); |
|
42 |
|
|
43 |
public List<Integer> getGeometryTypeDataSet2(); |
|
44 |
|
|
45 |
public DynObject createRuleParameters(); |
|
46 |
|
|
47 |
public TopologyRule createRule(String dataSet1, String dataSet2, double tolerance); |
|
48 |
|
|
49 |
public boolean hasRuleParameters(); |
|
50 |
|
|
51 |
public boolean hasSecondaryDataSet(); |
|
52 |
|
|
53 |
public boolean canApplyToDataSet(TopologyDataSet dataSet); |
|
54 |
|
|
55 |
public boolean canApplyToSecondaryDataSet(TopologyDataSet dataSet); |
|
56 |
|
|
57 |
|
|
58 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyLocator.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.api; |
|
25 |
|
|
26 |
import org.gvsig.tools.locator.AbstractLocator; |
|
27 |
import org.gvsig.tools.locator.Locator; |
|
28 |
import org.gvsig.tools.locator.LocatorException; |
|
29 |
|
|
30 |
@SuppressWarnings("rawtypes") |
|
31 |
public class TopologyLocator extends AbstractLocator { |
|
32 |
|
|
33 |
private static final String LOCATOR_NAME = "TopologyLocator"; |
|
34 |
|
|
35 |
public static final String TOPOLOGY_MANAGER_NAME = |
|
36 |
"org.gvsig.topology.manager"; |
|
37 |
|
|
38 |
private static final String TOPOLOGY_MANAGER_DESCRIPTION = |
|
39 |
"Topology Manager of gvSIG"; |
|
40 |
|
|
41 |
private static final TopologyLocator instance = new TopologyLocator(); |
|
42 |
|
|
43 |
private TopologyLocator() { |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* Return the singleton instance. |
|
49 |
* |
|
50 |
* @return the singleton instance |
|
51 |
*/ |
|
52 |
public static TopologyLocator getInstance() { |
|
53 |
return instance; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public String getLocatorName() { |
|
58 |
return LOCATOR_NAME; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Return a reference to TopologyManager. |
|
63 |
* |
|
64 |
* @return a reference to TopologyManager |
|
65 |
* @throws LocatorException |
|
66 |
* if there is no access to the class or the class cannot be |
|
67 |
* instantiated |
|
68 |
* @see Locator#get(String) |
|
69 |
*/ |
|
70 |
public static TopologyManager getTopologyManager() |
|
71 |
throws LocatorException { |
|
72 |
return (TopologyManager) getInstance().get(TOPOLOGY_MANAGER_NAME); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Registers the Class implementing the TopologyManager interface. |
|
77 |
* |
|
78 |
* @param clazz |
|
79 |
* implementing the TopologyManager interface |
|
80 |
*/ |
|
81 |
public static void registerTopologyManager(Class clazz) { |
|
82 |
getInstance().register(TOPOLOGY_MANAGER_NAME, |
|
83 |
TOPOLOGY_MANAGER_DESCRIPTION, clazz); |
|
84 |
} |
|
85 |
|
|
86 |
public static void registerDefaultTopologyManager(Class clazz) { |
|
87 |
getInstance().registerDefault(TOPOLOGY_MANAGER_NAME, |
|
88 |
TOPOLOGY_MANAGER_DESCRIPTION, clazz); |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyLibrary.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.api; |
|
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 |
|
|
32 |
/** |
|
33 |
* |
|
34 |
* @author jjdelcerro |
|
35 |
*/ |
|
36 |
public class TopologyLibrary extends AbstractLibrary { |
|
37 |
|
|
38 |
@Override |
|
39 |
public void doRegistration() { |
|
40 |
super.doRegistration(); |
|
41 |
registerAsAPI(TopologyLibrary.class); |
|
42 |
this.require(ToolsLibrary.class); |
|
43 |
this.require(DALLibrary.class); |
|
44 |
this.require(GeometryLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doInitialize() throws LibraryException { |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
protected void doPostInitialize() throws LibraryException { |
|
53 |
} |
|
54 |
|
|
55 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyRuleAction.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.api; |
|
25 |
|
|
26 |
import org.gvsig.tools.dynobject.DynObject; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author jjdelcerro |
|
31 |
*/ |
|
32 |
public interface TopologyRuleAction { |
|
33 |
|
|
34 |
public static final int EXECUTE_OK = 0; |
|
35 |
public static final int EXECUTE_FAIL = 1; |
|
36 |
|
|
37 |
public String getId(); |
|
38 |
|
|
39 |
public String getName(); |
|
40 |
|
|
41 |
public String getShortDescription(); |
|
42 |
|
|
43 |
public TopologyRuleFactory getRuleFactory(); |
|
44 |
|
|
45 |
public boolean hasParameters(); |
|
46 |
|
|
47 |
public DynObject createParameters(); |
|
48 |
|
|
49 |
public int execute( |
|
50 |
TopologyRule rule, |
|
51 |
TopologyReportLine line, |
|
52 |
DynObject parameters |
|
53 |
) throws ExecuteTopologyRuleActionException; |
|
54 |
|
|
55 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/ExecuteTopologyRuleActionException.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.api; |
|
25 |
|
|
26 |
|
|
27 |
public class ExecuteTopologyRuleActionException extends RuntimeException { |
|
28 |
|
|
29 |
public ExecuteTopologyRuleActionException(Exception ex) { |
|
30 |
this.initCause(ex); |
|
31 |
} |
|
32 |
|
|
33 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyDataSetResolver.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.api; |
|
2 |
|
|
3 |
/** |
|
4 |
* |
|
5 |
* @author gvSIG Team |
|
6 |
*/ |
|
7 |
public interface TopologyDataSetResolver { |
|
8 |
public TopologyDataSet getDataSet(String name); |
|
9 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyRule.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.api; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
import org.gvsig.json.SupportJson; |
|
28 |
import org.gvsig.tools.dynobject.DynObject; |
|
29 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
*/ |
|
35 |
public interface TopologyRule extends SupportJson, org.gvsig.tools.lang.Cloneable { |
|
36 |
|
|
37 |
public void execute(SimpleTaskStatus taskStatus, TopologyReport report) throws ExecuteTopologyRuleException; |
|
38 |
|
|
39 |
public String getName(); |
|
40 |
|
|
41 |
public String getId(); |
|
42 |
|
|
43 |
public TopologyPlan getPlan(); |
|
44 |
|
|
45 |
public TopologyRuleFactory getFactory(); |
|
46 |
|
|
47 |
public TopologyDataSet getDataSet1(); |
|
48 |
|
|
49 |
public TopologyDataSet getDataSet2(); |
|
50 |
|
|
51 |
public double getTolerance(); |
|
52 |
|
|
53 |
public List<TopologyRuleAction> getActions(); |
|
54 |
|
|
55 |
public TopologyRuleAction getAction(String name); |
|
56 |
|
|
57 |
public long getSteps(); |
|
58 |
|
|
59 |
public void setParameters(DynObject parameters); |
|
60 |
|
|
61 |
public DynObject getParameters(); |
|
62 |
|
|
63 |
@Override |
|
64 |
public TopologyRule clone() throws CloneNotSupportedException; |
|
65 |
|
|
66 |
public void setDataSetResolver(TopologyDataSetResolver resolver); |
|
67 |
|
|
68 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/ExecuteTopologyRuleException.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.topology.lib.api; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
public class ExecuteTopologyRuleException extends RuntimeException { |
|
13 |
public ExecuteTopologyRuleException(Exception ex) { |
|
14 |
this.initCause(ex); |
|
15 |
} |
|
16 |
|
|
17 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyManager.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.api; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
import org.gvsig.fmap.dal.DataStore; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author jjdelcerro |
|
32 |
*/ |
|
33 |
public interface TopologyManager { |
|
34 |
|
|
35 |
public static int TOPOLOGY_PLAN_STATUS_NOT_EXECUTED = -1; |
|
36 |
public static int TOPOLOGY_PLAN_STATUS_PASSED = 0; |
|
37 |
public static int TOPOLOGY_PLAN_STATUS_NOT_PASSED = 1; |
|
38 |
|
|
39 |
public TopologyPlan createTopologyPlan(); |
|
40 |
|
|
41 |
public List<TopologyRuleFactory> getRuleFactories(); |
|
42 |
|
|
43 |
public TopologyRuleFactory getRulefactory(String id); |
|
44 |
|
|
45 |
public List<TopologyRuleFactory> getRuleFactories(TopologyDataSet dataSet); |
|
46 |
|
|
47 |
public void addRuleFactories(TopologyRuleFactory factory); |
|
48 |
|
|
49 |
public TopologyDataSet createDataSet(String name, DataStore store); |
|
50 |
|
|
51 |
public void setDefaultServices(TopologyServices services); |
|
52 |
|
|
53 |
public TopologyServices getDefaultServices(); |
|
54 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/TopologyReport.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.api; |
|
25 |
|
|
26 |
import java.util.List; |
|
27 |
import org.gvsig.fmap.dal.feature.Feature; |
|
28 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author jjdelcerro |
|
34 |
*/ |
|
35 |
public interface TopologyReport extends TopologyReportLineSet { |
|
36 |
|
|
37 |
public static String RULE_ID = "RULE_ID"; |
|
38 |
public static String IS_ERROR = "IS_ERROR"; |
|
39 |
public static String IS_EXCEPTION = "IS_EXCEPTION"; |
|
40 |
public static String GEOMETRY = "GEOMETRY"; |
|
41 |
|
|
42 |
|
|
43 |
public TopologyReportLine addLine( |
|
44 |
TopologyRule rule, |
|
45 |
TopologyDataSet dataSet1, |
|
46 |
TopologyDataSet dataSet2, |
|
47 |
Geometry geometry, |
|
48 |
Geometry error, |
|
49 |
FeatureReference feature1, |
|
50 |
FeatureReference feature2, |
|
51 |
boolean exception, |
|
52 |
String description |
|
53 |
); |
|
54 |
|
|
55 |
public TopologyReportLine addLine( |
|
56 |
TopologyRule rule, |
|
57 |
TopologyDataSet dataSet1, |
|
58 |
TopologyDataSet dataSet2, |
|
59 |
Geometry geometry, |
|
60 |
Geometry error, |
|
61 |
FeatureReference feature1, |
|
62 |
FeatureReference feature2, |
|
63 |
int primitive1, |
|
64 |
int primitive2, |
|
65 |
boolean exception, |
|
66 |
String description, |
|
67 |
String data |
|
68 |
); |
|
69 |
|
|
70 |
public void removeAllLines(); |
|
71 |
|
|
72 |
@Override |
|
73 |
public List<TopologyReportLine> getLines(); |
|
74 |
|
|
75 |
public List<TopologyReportLine> getLines(String filter); |
|
76 |
|
|
77 |
public TopologyReportLineSet getLineSet(String filter); |
|
78 |
|
|
79 |
public int getStatus(); |
|
80 |
|
|
81 |
public TopologyReportLine addCodeException( |
|
82 |
TopologyRule rule, |
|
83 |
TopologyDataSet dataSet1, |
|
84 |
Feature feature1, |
|
85 |
Throwable exception |
|
86 |
); |
|
87 |
|
|
88 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/api/PerformOperationException.java | ||
---|---|---|
1 |
package org.gvsig.topology.lib.api; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.exception.DataException; |
|
4 |
|
|
5 |
/** |
|
6 |
* |
|
7 |
* @author jjdelcerro |
|
8 |
*/ |
|
9 |
public class PerformOperationException extends DataException { |
|
10 |
|
|
11 |
public PerformOperationException(String msg) { |
|
12 |
super("_CancelOperationException", msg, 0); |
|
13 |
} |
|
14 |
|
|
15 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRuleAction.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.spi; |
|
25 |
|
|
26 |
import java.net.URL; |
|
27 |
import org.gvsig.tools.dynobject.DynObject; |
|
28 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
29 |
import org.gvsig.topology.lib.api.TopologyRuleAction; |
|
30 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
|
31 |
import org.json.JSONObject; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author jjdelcerro |
|
36 |
*/ |
|
37 |
public abstract class AbstractTopologyRuleAction implements TopologyRuleAction { |
|
38 |
|
|
39 |
protected String idRule; |
|
40 |
protected String idAction; |
|
41 |
protected String name; |
|
42 |
protected String shortDescription; |
|
43 |
|
|
44 |
protected AbstractTopologyRuleAction( |
|
45 |
String idRule |
|
46 |
) { |
|
47 |
this.idRule = idRule; |
|
48 |
this.idAction = null; |
|
49 |
this.name = null; |
|
50 |
this.shortDescription = null; |
|
51 |
} |
|
52 |
|
|
53 |
protected AbstractTopologyRuleAction( |
|
54 |
String idRule, |
|
55 |
String idAction, |
|
56 |
String name, |
|
57 |
String shortDescription |
|
58 |
) { |
|
59 |
this.idRule = idRule; |
|
60 |
this.idAction = idAction; |
|
61 |
this.name = name; |
|
62 |
this.shortDescription = shortDescription; |
|
63 |
this.load_from_resource(); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public String getId() { |
|
68 |
return this.idAction; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public String getName() { |
|
73 |
return this.name; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public String getShortDescription() { |
|
78 |
return this.shortDescription; |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public TopologyRuleFactory getRuleFactory() { |
|
83 |
TopologyRuleFactory f = TopologyLocator.getTopologyManager().getRulefactory(this.idRule); |
|
84 |
return f; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public boolean hasParameters() { |
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public DynObject createParameters() { |
|
94 |
return null; |
|
95 |
} |
|
96 |
|
|
97 |
private void load_from_resource() { |
|
98 |
URL url = RuleResourceLoaderUtils.getRuleURL(this.idRule); |
|
99 |
JSONObject rule = RuleResourceLoaderUtils.getRule(url); |
|
100 |
load_from_resource(url, rule); |
|
101 |
} |
|
102 |
|
|
103 |
protected void load_from_resource(URL jsonUrl, JSONObject rule) { |
|
104 |
if( rule == null ) { |
|
105 |
return; |
|
106 |
} |
|
107 |
JSONObject action = RuleResourceLoaderUtils.getAction(rule, this.idAction); |
|
108 |
if( action.has("name") ) { |
|
109 |
this.name = action.getString("name"); |
|
110 |
} |
|
111 |
if( action.has("description") ) { |
|
112 |
this.shortDescription = RuleResourceLoaderUtils.getDescription(jsonUrl, action); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/RuleResourceLoaderUtils.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package org.gvsig.topology.lib.spi; |
|
7 |
|
|
8 |
import java.io.File; |
|
9 |
import java.io.InputStream; |
|
10 |
import java.net.MalformedURLException; |
|
11 |
import java.net.URL; |
|
12 |
import java.nio.charset.StandardCharsets; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Locale; |
|
15 |
import org.apache.commons.io.Charsets; |
|
16 |
import org.apache.commons.io.FilenameUtils; |
|
17 |
import org.apache.commons.io.IOUtils; |
|
18 |
import org.apache.commons.lang3.StringUtils; |
|
19 |
import org.json.JSONArray; |
|
20 |
import org.json.JSONObject; |
|
21 |
import org.slf4j.Logger; |
|
22 |
import org.slf4j.LoggerFactory; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author jjdelcerro |
|
27 |
*/ |
|
28 |
@SuppressWarnings("UseSpecificCatch") |
|
29 |
public class RuleResourceLoaderUtils { |
|
30 |
|
|
31 |
private static Logger LOGGER = LoggerFactory.getLogger(RuleResourceLoaderUtils.class); |
|
32 |
|
|
33 |
public static URL getRuleURL(String idRule) { |
|
34 |
String lang = Locale.getDefault().getLanguage(); |
|
35 |
URL url = RuleResourceLoaderUtils.class.getResource("/org/gvsig/topology/rules/"+lang+"/"+idRule+".json"); |
|
36 |
if( url == null ) { |
|
37 |
url = RuleResourceLoaderUtils.class.getResource("/org/gvsig/topology/rules/en/"+idRule+".json"); |
|
38 |
if( url == null ) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
} |
|
42 |
return url; |
|
43 |
} |
|
44 |
|
|
45 |
public static JSONObject getRule(URL url) { |
|
46 |
if( url == null ) { |
|
47 |
return null; |
|
48 |
} |
|
49 |
InputStream is = null; |
|
50 |
JSONObject json; |
|
51 |
try { |
|
52 |
is = url.openStream(); |
|
53 |
List<String> lines = IOUtils.readLines(is, StandardCharsets.UTF_8); |
|
54 |
json = new JSONObject(StringUtils.join(lines, "\n")); |
|
55 |
} catch (Exception ex) { |
|
56 |
LOGGER.warn("Can't load resource from json file '"+url.toString()+"'.", ex); |
|
57 |
return null; |
|
58 |
} finally { |
|
59 |
IOUtils.closeQuietly(is); |
|
60 |
} |
|
61 |
return json; |
|
62 |
} |
|
63 |
|
|
64 |
public static JSONObject getRule(String idRuleOrPathname) { |
|
65 |
if( idRuleOrPathname==null ) { |
|
66 |
return null; |
|
67 |
} |
|
68 |
if( idRuleOrPathname.endsWith(".json") ) { |
|
69 |
// Asumimos que es una ruta al fichero json. |
|
70 |
return getRule(new File(idRuleOrPathname)); |
|
71 |
} |
|
72 |
// Asumimos que es un ID de regla |
|
73 |
URL url = getRuleURL(idRuleOrPathname); |
|
74 |
if( url == null ) { |
|
75 |
return null; |
|
76 |
} |
|
77 |
return getRule(url); |
|
78 |
} |
|
79 |
|
|
80 |
public static JSONObject getRule(File jsonfile) { |
|
81 |
if( jsonfile == null || !jsonfile.exists() ) { |
|
82 |
return null; |
|
83 |
} |
|
84 |
try { |
|
85 |
return getRule(jsonfile.toURI().toURL()); |
|
86 |
} catch (MalformedURLException ex) { |
|
87 |
LOGGER.warn("Can't load resource from json file '"+jsonfile.toString()+"'.", ex); |
|
88 |
return null; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public static String getDescription(URL jsonUrl, JSONObject json) { |
|
93 |
String description = null; |
|
94 |
|
|
95 |
if( json.has("description") ) { |
|
96 |
Object x = json.get("description"); |
|
97 |
if( x instanceof String ) { |
|
98 |
description = (String) x; |
|
99 |
} else if( x instanceof JSONArray ) { |
|
100 |
StringBuilder builder = new StringBuilder(); |
|
101 |
for (int i = 0; i < ((JSONArray)x).length(); i++) { |
|
102 |
if( i>0 ) { |
|
103 |
builder.append(" "); |
|
104 |
} |
|
105 |
builder.append(((JSONArray)x).getString(i)); |
|
106 |
} |
|
107 |
description = builder.toString(); |
|
108 |
} else { |
|
109 |
description = x.toString(); |
|
110 |
} |
|
111 |
if( description.contains("@@@") ) { |
|
112 |
description = StringUtils.replace( |
|
113 |
description, |
|
114 |
"@@@", |
|
115 |
FilenameUtils.removeExtension(jsonUrl.toString()) |
|
116 |
); |
|
117 |
} |
|
118 |
} |
|
119 |
return description; |
|
120 |
} |
|
121 |
|
|
122 |
public static JSONObject getAction(JSONObject rule, String idAction) { |
|
123 |
if( !rule.has("actions") ) { |
|
124 |
return null; |
|
125 |
} |
|
126 |
if( !rule.getJSONObject("actions").has(idAction) ) { |
|
127 |
return null; |
|
128 |
} |
|
129 |
JSONObject action = rule.getJSONObject("actions").getJSONObject(idAction); |
|
130 |
return action; |
|
131 |
} |
|
132 |
|
|
133 |
} |
org.gvsig.topology/tags/org.gvsig.topology-1.0.140/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/AbstractTopologyRule.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.spi; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.List; |
|
29 |
import java.util.Objects; |
|
30 |
import javax.json.JsonObject; |
|
31 |
import org.apache.commons.lang3.StringUtils; |
|
32 |
import org.gvsig.fmap.dal.exception.DataException; |
|
33 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
36 |
import org.gvsig.fmap.geom.Geometry; |
|
37 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
39 |
import org.gvsig.json.Json; |
|
40 |
import org.gvsig.json.JsonObjectBuilder; |
|
41 |
import org.gvsig.tools.dynobject.DynClass; |
|
42 |
import org.gvsig.tools.dynobject.DynField; |
|
43 |
import org.gvsig.tools.dynobject.DynObject; |
|
44 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
45 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
46 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
|
47 |
import org.gvsig.topology.lib.api.TopologyDataSetResolver; |
|
48 |
import org.gvsig.topology.lib.api.TopologyLocator; |
|
49 |
import org.gvsig.topology.lib.api.TopologyManager; |
|
50 |
import org.gvsig.topology.lib.api.TopologyPlan; |
|
51 |
import org.gvsig.topology.lib.api.TopologyReport; |
|
52 |
import org.gvsig.topology.lib.api.TopologyRule; |
|
53 |
import org.gvsig.topology.lib.api.TopologyRuleAction; |
|
54 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
|
55 |
import org.slf4j.Logger; |
|
56 |
import org.slf4j.LoggerFactory; |
|
57 |
|
|
58 |
/** |
|
59 |
* |
|
60 |
* @author jjdelcerro |
|
61 |
*/ |
|
62 |
public abstract class AbstractTopologyRule implements TopologyRule { |
|
63 |
|
|
64 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTopologyRule.class); |
|
65 |
|
|
66 |
private TopologyPlan plan; |
|
67 |
private TopologyDataSetResolver datasetResolver; |
|
68 |
private TopologyRuleFactory factory; |
|
69 |
private double tolerance; |
|
70 |
public String dataSet1; |
|
71 |
private String dataSet2; |
|
72 |
|
|
73 |
protected List<TopologyRuleAction> actions; |
|
74 |
private DynObject parameters; |
|
75 |
private int codeExceptionCount; |
|
76 |
|
|
77 |
protected AbstractTopologyRule() { |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
protected AbstractTopologyRule( |
|
82 |
TopologyRuleFactory factory, |
|
83 |
double tolerance, |
|
84 |
String dataSet1, |
|
85 |
String dataSet2 |
|
86 |
) { |
|
87 |
this.factory = factory; |
|
88 |
this.tolerance = tolerance; |
|
89 |
this.dataSet1 = dataSet1; |
|
90 |
this.dataSet2 = dataSet2; |
|
91 |
this.actions = new ArrayList<>(); |
|
92 |
} |
|
93 |
|
|
94 |
protected AbstractTopologyRule( |
|
95 |
TopologyRuleFactory factory, |
|
96 |
double tolerance, |
|
97 |
String dataSet1 |
|
98 |
) { |
|
99 |
this(factory, tolerance, dataSet1, null); |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public TopologyRule clone() throws CloneNotSupportedException { |
|
104 |
AbstractTopologyRule other = (AbstractTopologyRule) super.clone(); |
|
105 |
if( this.actions!=null ) { |
|
106 |
other.actions = new ArrayList<>(); |
|
107 |
other.actions.addAll(this.actions); |
|
108 |
} |
|
109 |
if( this.parameters!=null ) { |
|
110 |
other.parameters = DynObject.clone(this.parameters); |
|
111 |
} |
|
112 |
return other; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public TopologyPlan getPlan() { |
|
117 |
return this.plan; |
|
118 |
} |
|
119 |
|
|
120 |
public void setPlan(TopologyPlan plan) { |
|
121 |
this.plan = plan; |
|
122 |
} |
|
123 |
|
|
124 |
public void setDataSetResolver(TopologyDataSetResolver resolver) { |
|
125 |
this.datasetResolver = resolver; |
|
126 |
} |
|
127 |
|
|
128 |
private TopologyDataSetResolver getDataSetResolver() { |
|
129 |
if( this.plan != null ) { |
|
130 |
return this.plan; |
|
131 |
} |
|
132 |
return this.datasetResolver; |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public TopologyRuleFactory getFactory() { |
|
137 |
return this.factory; |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public String getName() { |
|
142 |
return this.getFactory().getName(); |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public String getId() { |
|
147 |
return this.getFactory().getId(); |
|
148 |
} |
|
149 |
|
|
150 |
public final void addAction(TopologyRuleAction action) { |
|
151 |
this.actions.add(action); |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public boolean equals(Object obj) { |
|
156 |
if( !(obj instanceof TopologyRule) ) { |
|
157 |
return false; |
|
158 |
} |
|
159 |
AbstractTopologyRule other = (AbstractTopologyRule)obj; |
|
160 |
if( !StringUtils.equals(this.getName(), other.getName()) ) { |
|
161 |
return false; |
|
162 |
} |
|
163 |
if( !StringUtils.equals(this.dataSet1, other.dataSet1) ) { |
|
164 |
return false; |
|
165 |
} |
|
166 |
if( !StringUtils.equals(this.dataSet2, other.dataSet2) ) { |
|
167 |
return false; |
|
168 |
} |
|
169 |
// Ojo con la comparacion de doubles |
|
170 |
// if( this.tolerance != other.tolerance ) { |
|
171 |
// return false; |
|
172 |
// } |
|
173 |
return true; |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
public int hashCode() { |
|
178 |
int hash = 7; |
|
179 |
hash = 71 * hash + Objects.hashCode(this.factory); |
|
180 |
hash = 71 * hash + (int) (Double.doubleToLongBits(this.tolerance) ^ (Double.doubleToLongBits(this.tolerance) >>> 32)); |
|
181 |
hash = 71 * hash + Objects.hashCode(this.dataSet1); |
|
182 |
hash = 71 * hash + Objects.hashCode(this.dataSet2); |
|
183 |
return hash; |
|
184 |
} |
|
185 |
|
|
186 |
@Override |
|
187 |
public String toString() { |
|
188 |
return this.getName(); |
|
189 |
} |
|
190 |
|
|
191 |
@Override |
|
192 |
public TopologyDataSet getDataSet1() { |
|
193 |
return this.getDataSetResolver().getDataSet(dataSet1); |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public TopologyDataSet getDataSet2() { |
|
198 |
return this.getDataSetResolver().getDataSet(dataSet2); |
|
199 |
} |
|
200 |
|
|
201 |
@Override |
|
202 |
public double getTolerance() { |
|
203 |
return this.tolerance; |
|
204 |
} |
|
205 |
|
|
206 |
@Override |
|
207 |
public List<TopologyRuleAction> getActions() { |
|
208 |
if( this.actions == null ) { |
|
209 |
return null; |
|
210 |
} |
|
211 |
return Collections.unmodifiableList(actions); |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public TopologyRuleAction getAction(String id) { |
|
216 |
for (TopologyRuleAction action : actions) { |
|
217 |
if (StringUtils.equalsIgnoreCase(id, action.getId())) { |
|
218 |
return action; |
|
219 |
} |
|
220 |
} |
|
221 |
return null; |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public long getSteps() { |
|
226 |
return this.getDataSet1().getSize(); |
|
227 |
} |
|
228 |
|
|
229 |
@Override |
|
230 |
public void execute(final SimpleTaskStatus taskStatus, final TopologyReport report) { |
|
231 |
try { |
|
232 |
this.codeExceptionCount = 0; |
|
233 |
this.getDataSet1().accept((final Object o1) -> { |
|
234 |
if( taskStatus.isCancellationRequested() ) { |
|
235 |
throw new VisitCanceledException(); |
|
236 |
} |
|
237 |
taskStatus.incrementCurrentValue(); |
|
238 |
try { |
|
239 |
check(taskStatus, report, (Feature) o1); |
|
240 |
} catch (Exception ex) { |
|
241 |
addCodeException(report, (Feature)o1, ex); |
|
242 |
} |
|
243 |
}); |
|
244 |
} catch(VisitCanceledException ex) { |
|
245 |
report.addLine(this, null, null, null, null, null, null, true, ""); |
|
246 |
// return; |
|
247 |
} |
|
248 |
} |
|
249 |
|
|
250 |
protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature) throws Exception { |
|
251 |
|
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public JsonObject toJson() { |
|
256 |
return this.toJsonBuilder().build(); |
|
257 |
} |
|
258 |
|
|
259 |
@Override |
|
260 |
public JsonObjectBuilder toJsonBuilder() { |
|
261 |
JsonObjectBuilder me = Json.createObjectBuilder(); |
|
262 |
me.add_class(this); |
|
263 |
me.add("ruleid", this.getId()); |
|
264 |
me.add("tolerance", this.tolerance); |
|
265 |
me.add("dataSet1", this.dataSet1); |
|
266 |
me.add("dataSet2", this.dataSet2); |
|
267 |
|
|
268 |
DynObject params = this.getParameters(); |
|
269 |
if(params!= null) { |
|
270 |
JsonObjectBuilder jsonParams = Json.createObjectBuilder(); |
|
271 |
DynClass parametersDefinition = params.getDynClass(); |
|
272 |
for (DynField dynField : parametersDefinition.getDynFields()) { |
|
273 |
jsonParams.add(dynField.getName(), params.getDynValue(dynField.getName())); |
|
274 |
} |
|
275 |
me.add("params", jsonParams); |
|
276 |
} |
|
277 |
return me; |
|
278 |
} |
|
279 |
|
|
280 |
@Override |
|
281 |
public void fromJson(JsonObject json) { |
|
282 |
TopologyManager manager = TopologyLocator.getTopologyManager(); |
|
283 |
|
|
284 |
String ruleid = json.getString("ruleid", null); |
|
285 |
this.factory = manager.getRulefactory(ruleid); |
|
286 |
|
|
287 |
if( json.containsKey("tolerance") ) { |
|
288 |
this.tolerance = json.getJsonNumber("tolerance").doubleValue(); |
|
289 |
} |
Also available in: Unified diff