gvsig-projects-pool / 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 @ 712
History | View | Annotate | Download (4.32 KB)
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.List; |
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryLocator; |
29 |
import org.gvsig.fmap.geom.GeometryManager; |
30 |
import org.gvsig.tools.util.ListBuilder; |
31 |
import org.gvsig.topology.lib.api.TopologyDataSet; |
32 |
import org.gvsig.topology.lib.api.TopologyRuleFactory; |
33 |
import org.json.JSONObject; |
34 |
|
35 |
/**
|
36 |
*
|
37 |
* @author jjdelcerro
|
38 |
*/
|
39 |
public abstract class AbstractTopologyRuleFactory implements TopologyRuleFactory { |
40 |
private final String id; |
41 |
private String name; |
42 |
private String description; |
43 |
private final List<Integer> geometryTypeDataSet1; |
44 |
private final List<Integer> geometryTypeDataSet2; |
45 |
|
46 |
protected AbstractTopologyRuleFactory(
|
47 |
String id,
|
48 |
String name,
|
49 |
String description,
|
50 |
List<Integer> geometryTypeDataSet1, |
51 |
List<Integer> geometryTypeDataSet2 |
52 |
) { |
53 |
this.id = id;
|
54 |
this.name = name;
|
55 |
this.description = description;
|
56 |
this.geometryTypeDataSet1 = geometryTypeDataSet1;
|
57 |
this.geometryTypeDataSet2 = geometryTypeDataSet2;
|
58 |
this.load_from_resource();
|
59 |
} |
60 |
|
61 |
protected AbstractTopologyRuleFactory(
|
62 |
String id,
|
63 |
String name,
|
64 |
String description,
|
65 |
List<Integer> geometryTypeDataSet1 |
66 |
) { |
67 |
this(id, name, description, geometryTypeDataSet1, null); |
68 |
} |
69 |
|
70 |
@Override
|
71 |
public String toString() { |
72 |
return this.name; |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public String getId() { |
77 |
return this.id; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public String getName() { |
82 |
return this.name; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public String getDescription() { |
87 |
return this.description; |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public List<Integer> getGeometryTypeDataSet1() { |
92 |
return this.geometryTypeDataSet1; |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public List<Integer> getGeometryTypeDataSet2() { |
97 |
return this.geometryTypeDataSet2; |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public boolean hasSecondaryDataSet() { |
102 |
return this.geometryTypeDataSet2 != null && !this.geometryTypeDataSet2.isEmpty(); |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public boolean canApplyToDataSet(TopologyDataSet dataSet) { |
107 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
108 |
for (Integer geometryType : geometryTypeDataSet1) { |
109 |
boolean canApply = geomManager.isSubtype(geometryType, dataSet.getGeometryType());
|
110 |
if( canApply ) {
|
111 |
return true; |
112 |
} |
113 |
} |
114 |
return false; |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public boolean canApplyToSecondaryDataSet(TopologyDataSet dataSet) { |
119 |
if( !this.hasSecondaryDataSet() ) { |
120 |
return false; |
121 |
} |
122 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
123 |
for (Integer geometryType : geometryTypeDataSet2) { |
124 |
boolean canApply = geomManager.isSubtype(geometryType, dataSet.getGeometryType() );
|
125 |
if( canApply ) {
|
126 |
return true; |
127 |
} |
128 |
} |
129 |
return false; |
130 |
} |
131 |
|
132 |
private void load_from_resource() { |
133 |
JSONObject json = RuleResourceLoaderUtils.getRule(this.id);
|
134 |
if( json == null ) { |
135 |
return;
|
136 |
} |
137 |
if( json.has("name") ) { |
138 |
this.name = json.getString("name"); |
139 |
} |
140 |
if( json.has("description") ) { |
141 |
this.description = RuleResourceLoaderUtils.getDescription(this.id, json); |
142 |
} |
143 |
} |
144 |
} |