1
|
package eu.dnetlib.data.collective.transformation.rulelanguage;
|
2
|
|
3
|
import java.util.Properties;
|
4
|
|
5
|
import eu.dnetlib.data.collective.transformation.core.schema.SchemaElement;
|
6
|
import eu.dnetlib.data.collective.transformation.rulelanguage.util.FunctionCall;
|
7
|
|
8
|
/**
|
9
|
* @author jochen
|
10
|
*
|
11
|
*/
|
12
|
public class Rules implements Comparable<Rules>, IRule{
|
13
|
|
14
|
public static final String staticRule = "static";
|
15
|
private String attribute = "";
|
16
|
private String targetField = "";
|
17
|
private String ruleDeclaration = "";
|
18
|
private String xpath = "";
|
19
|
private String constant = "";
|
20
|
private String namespace = "";
|
21
|
private String variable = "";
|
22
|
private String template = "";
|
23
|
private String templateMatch = "";
|
24
|
private FunctionCall funcCall;
|
25
|
private Condition condition;
|
26
|
private boolean isEmpty = false;
|
27
|
private boolean isSkip = false;
|
28
|
private SchemaElement targetSchemaElement;
|
29
|
private String assignmentVariable = "";
|
30
|
private RulesSet rulesSet;
|
31
|
private Properties properties = new Properties();
|
32
|
|
33
|
public Rules() {
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* indicates if the rule is declared as static
|
38
|
* @return true if static, false otherwise
|
39
|
*/
|
40
|
public boolean isStatic(){
|
41
|
if (ruleDeclaration.equals(staticRule)){
|
42
|
return true;
|
43
|
}
|
44
|
return false;
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* indicates if the rule defines a variable
|
49
|
* @return true if variable is defined, false otherwise
|
50
|
* @see eu.dnetlib.data.collective.transformation.rulelanguage.IRule#definesVariable()
|
51
|
*/
|
52
|
public boolean definesVariable(){
|
53
|
if (variable.length() > 0) return true;
|
54
|
return false;
|
55
|
}
|
56
|
|
57
|
public boolean definesTargetField(){
|
58
|
if (targetField.length() > 0) return true;
|
59
|
return false;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* checks if this rule defines an attribute
|
64
|
* @return true if defines attribute else false
|
65
|
*/
|
66
|
public boolean definesAttribute(){
|
67
|
if (attribute.length() > 0) return true;
|
68
|
return false;
|
69
|
}
|
70
|
|
71
|
public boolean definesTemplate(){
|
72
|
if (template.length() > 0) return true;
|
73
|
return false;
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public boolean definesTemplateMatch() {
|
78
|
if (templateMatch.length() > 0) return true;
|
79
|
return false;
|
80
|
}
|
81
|
|
82
|
public void setXpath(String xpath) {
|
83
|
this.xpath = xpath;
|
84
|
}
|
85
|
public String getXpath() {
|
86
|
return xpath;
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* sets the argument aVariable as the value of the rule
|
91
|
* @param aVariable the variable as a reference to the value
|
92
|
*/
|
93
|
public void setAssignmentVariable(String aVariable){
|
94
|
this.assignmentVariable = aVariable;
|
95
|
}
|
96
|
|
97
|
public String getAssignmentVariable(){
|
98
|
return this.assignmentVariable;
|
99
|
}
|
100
|
|
101
|
public void setNamespace(String namespace) {
|
102
|
this.namespace = namespace;
|
103
|
}
|
104
|
|
105
|
public String getNamespace() {
|
106
|
return namespace;
|
107
|
}
|
108
|
|
109
|
public void setConstant(String constant) {
|
110
|
this.constant = constant;
|
111
|
}
|
112
|
|
113
|
public String getConstant() {
|
114
|
return constant;
|
115
|
}
|
116
|
|
117
|
@Deprecated
|
118
|
public void setTargetField(String targetField) {
|
119
|
if (this.variable.length() > 0){
|
120
|
throw new IllegalStateException("Invalid rule definition: a rule is either defined as an output element or as a variable");
|
121
|
}
|
122
|
this.targetField = targetField;
|
123
|
}
|
124
|
|
125
|
/*
|
126
|
* @deprecated replaced by {@Link #getUniqueName()}
|
127
|
*/
|
128
|
@Deprecated
|
129
|
public String getTargetField() {
|
130
|
return targetField;
|
131
|
}
|
132
|
|
133
|
public void setRuleDeclaration(String ruleDeclaration) {
|
134
|
this.ruleDeclaration = ruleDeclaration;
|
135
|
}
|
136
|
|
137
|
public String getRuleDeclaration() {
|
138
|
return ruleDeclaration;
|
139
|
}
|
140
|
|
141
|
/*
|
142
|
* compares two rules objects based on their xpath, function and namespace names
|
143
|
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
144
|
*/
|
145
|
public int compareTo(Rules o) {
|
146
|
if (
|
147
|
o.targetField.equals(this.targetField) &&
|
148
|
o.variable.equals(this.variable) &&
|
149
|
o.template.equals(this.template) &&
|
150
|
o.templateMatch.equals(this.templateMatch) &&
|
151
|
o.ruleDeclaration.equals(this.ruleDeclaration) &&
|
152
|
o.namespace.equals(this.namespace) &&
|
153
|
o.constant.equals(this.constant) &&
|
154
|
o.xpath.equals(this.xpath)){
|
155
|
return 0;
|
156
|
}else{
|
157
|
return -1;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
public void setFunctionCall(FunctionCall funcCall) {
|
162
|
this.funcCall = funcCall;
|
163
|
}
|
164
|
|
165
|
public FunctionCall getFunctionCall() {
|
166
|
return funcCall;
|
167
|
}
|
168
|
|
169
|
@Override
|
170
|
public String getUniqueName() {
|
171
|
if (this.definesVariable()) return this.variable;
|
172
|
else if (this.definesTemplate()) return this.template;
|
173
|
return this.targetField;
|
174
|
}
|
175
|
|
176
|
@Override
|
177
|
public boolean hasCondition() {
|
178
|
if (condition != null) return true;
|
179
|
return false;
|
180
|
}
|
181
|
|
182
|
/**
|
183
|
* @return the condition
|
184
|
*/
|
185
|
public Condition getCondition() {
|
186
|
return condition;
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* @param condition the condition to set
|
191
|
*/
|
192
|
public void setCondition(Condition condition) {
|
193
|
this.condition = condition;
|
194
|
}
|
195
|
|
196
|
/**
|
197
|
* @param variable the variable to set
|
198
|
*/
|
199
|
public void setVariable(String variable) {
|
200
|
if (this.targetField.length() > 0){
|
201
|
throw new IllegalStateException("Invalid rule definition: a rule is either defined as an output element or as a variable");
|
202
|
}
|
203
|
this.variable = variable;
|
204
|
}
|
205
|
|
206
|
/**
|
207
|
* @return the variable
|
208
|
*/
|
209
|
public String getVariable() {
|
210
|
return variable;
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* @param isEmpty the isEmpty to set
|
215
|
*/
|
216
|
public void setEmpty(boolean isEmpty) {
|
217
|
this.isEmpty = isEmpty;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* @return the isEmpty
|
222
|
*/
|
223
|
public boolean isEmpty() {
|
224
|
return isEmpty;
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* @param targetSchemaElement the targetSchemaElement to set
|
229
|
*/
|
230
|
public void setTargetSchemaElement(SchemaElement targetSchemaElement) {
|
231
|
this.targetSchemaElement = targetSchemaElement;
|
232
|
}
|
233
|
|
234
|
/**
|
235
|
* @return the targetSchemaElement
|
236
|
*/
|
237
|
public SchemaElement getTargetSchemaElement() {
|
238
|
return targetSchemaElement;
|
239
|
}
|
240
|
|
241
|
/**
|
242
|
* @return the template
|
243
|
*/
|
244
|
public String getTemplate() {
|
245
|
return template;
|
246
|
}
|
247
|
|
248
|
/**
|
249
|
* @param template the template to set
|
250
|
*/
|
251
|
public void setTemplate(String template) {
|
252
|
this.template = template;
|
253
|
}
|
254
|
|
255
|
/**
|
256
|
* @return the attribute
|
257
|
*/
|
258
|
public String getAttribute() {
|
259
|
return attribute;
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* @param attribute the attribute to set
|
264
|
*/
|
265
|
public void setAttribute(String attribute) {
|
266
|
this.attribute = attribute;
|
267
|
}
|
268
|
|
269
|
/**
|
270
|
* @return the rulesSet
|
271
|
*/
|
272
|
public RulesSet getRulesSet() {
|
273
|
return rulesSet;
|
274
|
}
|
275
|
|
276
|
/**
|
277
|
* @param rulesSet the rulesSet to set
|
278
|
*/
|
279
|
public void setRulesSet(RulesSet rulesSet) {
|
280
|
this.rulesSet = rulesSet;
|
281
|
}
|
282
|
|
283
|
/* (non-Javadoc)
|
284
|
* @see eu.dnetlib.data.collective.transformation.rulelanguage.IRule#hasSet()
|
285
|
*/
|
286
|
@Override
|
287
|
public boolean hasSet() {
|
288
|
if (rulesSet != null) return true;
|
289
|
return false;
|
290
|
}
|
291
|
|
292
|
public String getTemplateMatch() {
|
293
|
return templateMatch;
|
294
|
}
|
295
|
|
296
|
public void setTemplateMatch(String templateMatch) {
|
297
|
this.templateMatch = templateMatch;
|
298
|
}
|
299
|
|
300
|
public Properties getProperties() {
|
301
|
return properties;
|
302
|
}
|
303
|
|
304
|
public void setProperties(Properties properties) {
|
305
|
this.properties = properties;
|
306
|
}
|
307
|
|
308
|
public boolean isSkip() {
|
309
|
return isSkip;
|
310
|
}
|
311
|
|
312
|
public void setSkip(boolean isSkip) {
|
313
|
this.isSkip = isSkip;
|
314
|
}
|
315
|
|
316
|
}
|