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.BeneratorRootStatement;
30 import com.rapiddweller.benerator.engine.Statement;
31 import com.rapiddweller.benerator.engine.statement.DefineDOMTreeStatement;
32 import com.rapiddweller.benerator.engine.statement.IfStatement;
33 import com.rapiddweller.common.CollectionUtil;
34 import com.rapiddweller.common.ConfigurationError;
35 import com.rapiddweller.common.ConversionException;
36 import com.rapiddweller.script.Expression;
37 import org.w3c.dom.Element;
38
39 import java.util.Set;
40
41 import static com.rapiddweller.benerator.engine.DescriptorConstants.ATT_ID;
42 import static com.rapiddweller.benerator.engine.DescriptorConstants.ATT_INPUT_URI;
43 import static com.rapiddweller.benerator.engine.DescriptorConstants.ATT_NAMESPACE_AWARE;
44 import static com.rapiddweller.benerator.engine.DescriptorConstants.ATT_OUTPUT_URI;
45 import static com.rapiddweller.benerator.engine.DescriptorConstants.EL_DOMTREE;
46 import static com.rapiddweller.benerator.engine.parser.xml.DescriptorParserUtil.parseAttribute;
47 import static com.rapiddweller.benerator.engine.parser.xml.DescriptorParserUtil.parseBooleanExpressionAttribute;
48 import static com.rapiddweller.benerator.engine.parser.xml.DescriptorParserUtil.parseScriptableStringAttribute;
49
50
51
52
53
54
55
56
57 public class DOMTreeParser extends AbstractBeneratorDescriptorParser {
58
59 private static final Set<String> REQUIRED_ATTRIBUTES = CollectionUtil.toSet(ATT_ID, ATT_INPUT_URI);
60
61 private static final Set<String> OPTIONAL_ATTRIBUTES = CollectionUtil.toSet(ATT_OUTPUT_URI, ATT_NAMESPACE_AWARE);
62
63
64
65
66
67 public DOMTreeParser() {
68 super(EL_DOMTREE, REQUIRED_ATTRIBUTES, OPTIONAL_ATTRIBUTES, BeneratorRootStatement.class, IfStatement.class);
69 }
70
71 @Override
72 public DefineDOMTreeStatement doParse(Element element, Statement[] parentPath, BeneratorParseContext context) {
73 try {
74 Expression<String> id = parseAttribute(ATT_ID, element);
75 Expression<String> inputUri = parseScriptableStringAttribute(ATT_INPUT_URI, element);
76 Expression<String> outputUri = parseScriptableStringAttribute(ATT_OUTPUT_URI, element);
77 Expression<Boolean> namespaceAware = parseBooleanExpressionAttribute(ATT_NAMESPACE_AWARE, element);
78 return new DefineDOMTreeStatement(id, inputUri, outputUri, namespaceAware, context.getResourceManager());
79 } catch (ConversionException e) {
80 throw new ConfigurationError(e);
81 }
82 }
83
84 }