svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / DefaultGrammar.java @ 46517
History | View | Annotate | Download (2.22 KB)
1 |
package org.gvsig.expressionevaluator.impl; |
---|---|
2 |
|
3 |
import org.gvsig.expressionevaluator.Grammar; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Collections; |
6 |
import java.util.HashSet; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
import java.util.Set; |
10 |
import org.apache.commons.lang3.StringUtils; |
11 |
import org.gvsig.expressionevaluator.Statement; |
12 |
import org.gvsig.expressionevaluator.Statement.StatementContext; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author jjdelcerro
|
17 |
*/
|
18 |
public class DefaultGrammar implements Grammar { |
19 |
|
20 |
private final String name; |
21 |
private final List<Statement> statements; |
22 |
private final Set<String> reservedWords; |
23 |
|
24 |
public DefaultGrammar(String name) { |
25 |
this.name = name;
|
26 |
this.statements = new ArrayList<>(); |
27 |
this.reservedWords = new HashSet<>(); |
28 |
} |
29 |
|
30 |
@Override
|
31 |
public String getName() { |
32 |
return this.name; |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public List<Statement> getStatements() { |
37 |
return Collections.unmodifiableList(this.statements); |
38 |
} |
39 |
|
40 |
@Override
|
41 |
public Statement createStatement(String name) { |
42 |
DefaultStatement stmt = new DefaultStatement(name);
|
43 |
return stmt;
|
44 |
} |
45 |
|
46 |
@Override
|
47 |
public void addStatement(Statement statement) { |
48 |
this.statements.add(statement);
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public Statement getApplicableStatement(StatementContext context) { |
53 |
context.trace(this.getName()+".getApplicableStatement"); |
54 |
for (Statement statement : statements) { |
55 |
if( statement.isApplicable(context) ) {
|
56 |
context.trace(this.getName()+".getApplicableStatement return "+statement); |
57 |
return statement;
|
58 |
} |
59 |
} |
60 |
return null; |
61 |
} |
62 |
|
63 |
@Override
|
64 |
public String toString() { |
65 |
return this.getName(); |
66 |
} |
67 |
|
68 |
@Override
|
69 |
public void addReservedWord(String id) { |
70 |
if( StringUtils.isBlank(id) ) {
|
71 |
return;
|
72 |
} |
73 |
this.reservedWords.add(id.toUpperCase());
|
74 |
} |
75 |
|
76 |
@Override
|
77 |
public boolean isReservedWord(String id) { |
78 |
if( StringUtils.isBlank(id) ) {
|
79 |
return false; |
80 |
} |
81 |
return this.reservedWords.contains(id.toUpperCase()); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public Iterator<Statement> iterator() { |
86 |
return this.statements.iterator(); |
87 |
} |
88 |
|
89 |
} |