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 / AbstractTopologyRuleAction.java @ 886
History | View | Annotate | Download (3.08 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.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 |
private final String idAction; |
40 |
private final String idRule; |
41 |
private String name; |
42 |
private String shortDescription; |
43 |
|
44 |
protected AbstractTopologyRuleAction(
|
45 |
String idRule,
|
46 |
String idAction,
|
47 |
String name,
|
48 |
String shortDescription
|
49 |
) { |
50 |
this.idRule = idRule;
|
51 |
this.idAction = idAction;
|
52 |
this.name = name;
|
53 |
this.shortDescription = shortDescription;
|
54 |
this.load_from_resource();
|
55 |
} |
56 |
|
57 |
@Override
|
58 |
public String getId() { |
59 |
return this.idAction; |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public String getName() { |
64 |
return this.name; |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public String getShortDescription() { |
69 |
return this.shortDescription; |
70 |
} |
71 |
|
72 |
@Override
|
73 |
public TopologyRuleFactory getRuleFactory() {
|
74 |
TopologyRuleFactory f = TopologyLocator.getTopologyManager().getRulefactory(this.idRule);
|
75 |
return f;
|
76 |
} |
77 |
|
78 |
@Override
|
79 |
public boolean hasParameters() { |
80 |
return false; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public DynObject createParameters() {
|
85 |
return null; |
86 |
} |
87 |
|
88 |
private void load_from_resource() { |
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) { |
95 |
if( rule == null ) { |
96 |
return;
|
97 |
} |
98 |
JSONObject action = RuleResourceLoaderUtils.getAction(rule, this.idAction);
|
99 |
if( action.has("name") ) { |
100 |
this.name = action.getString("name"); |
101 |
} |
102 |
if( action.has("description") ) { |
103 |
this.shortDescription = RuleResourceLoaderUtils.getDescription(jsonUrl, action);
|
104 |
} |
105 |
} |
106 |
|
107 |
} |