1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.rapiddweller.benerator.engine.parser.xml;
28
29 import com.rapiddweller.benerator.engine.Statement;
30 import com.rapiddweller.benerator.engine.statement.WhileStatement;
31 import com.rapiddweller.common.CollectionUtil;
32 import com.rapiddweller.script.Expression;
33 import org.w3c.dom.Element;
34
35 import java.util.List;
36 import java.util.Set;
37
38 import static com.rapiddweller.benerator.engine.DescriptorConstants.ATT_TEST;
39 import static com.rapiddweller.benerator.engine.DescriptorConstants.EL_IF;
40 import static com.rapiddweller.benerator.engine.DescriptorConstants.EL_SETUP;
41 import static com.rapiddweller.benerator.engine.DescriptorConstants.EL_WHILE;
42 import static com.rapiddweller.benerator.engine.parser.xml.DescriptorParserUtil.parseBooleanExpressionAttribute;
43
44
45
46
47
48
49
50
51 public class WhileParser extends AbstractBeneratorDescriptorParser {
52
53 private static final Set<String> LEGAL_PARENTS = CollectionUtil.toSet(
54 EL_SETUP, EL_IF, EL_WHILE);
55
56
57
58
59 public WhileParser() {
60 super(EL_WHILE, CollectionUtil.toSet(ATT_TEST), null);
61 }
62
63
64
65
66
67
68
69
70 public boolean supports(String elementName, String parentName) {
71 return (EL_WHILE.equals(elementName) && LEGAL_PARENTS.contains(parentName));
72 }
73
74 @Override
75 public Statementcom/rapiddweller/benerator/engine/Statement.html#Statement">Statement doParse(Element element, Statement[] parentPath, BeneratorParseContext context) {
76 Expression<Boolean> condition = parseBooleanExpressionAttribute(ATT_TEST, element);
77 WhileStatementement/WhileStatement.html#WhileStatement">WhileStatement whileStatement = new WhileStatement(condition);
78 List<Statement> subStatements = context.parseChildElementsOf(element, context.createSubPath(parentPath, whileStatement));
79 whileStatement.setSubStatements(subStatements);
80 return whileStatement;
81 }
82
83 }