1 package de.unixwork.uwproj; |
1 package de.unixwork.uwproj; |
2 |
2 |
3 import org.w3c.dom.Element; |
3 import org.w3c.dom.Element; |
4 import org.w3c.dom.Node; |
|
5 import org.w3c.dom.NodeList; |
|
6 |
4 |
7 import java.util.LinkedList; |
5 import java.util.LinkedList; |
8 import java.util.List; |
6 import java.util.List; |
9 import java.util.stream.Collectors; |
7 import java.util.stream.Collectors; |
10 |
8 |
11 import static de.unixwork.uwproj.Util.shId; |
9 import static de.unixwork.uwproj.Util.shId; |
12 |
10 |
13 public class Option { |
11 public final class Option { |
14 private String arg; |
12 private final String arg; |
15 |
13 |
16 private final LinkedList<OptionValue> values = new LinkedList<>(); |
14 private final LinkedList<OptionValue> values = new LinkedList<>(); |
17 private final LinkedList<OptionDefault> defaults = new LinkedList<>(); |
15 private final LinkedList<OptionDefault> defaults = new LinkedList<>(); |
18 |
16 |
19 public static Option parse(Element element) throws Exception { |
17 public Option(Element element) { |
20 var opt = new Option(); |
18 arg = element.getAttribute("arg"); |
21 String arg = element.getAttribute("arg"); |
19 Util.getChildElements(element).forEach(elm -> { |
22 if (arg.isBlank()) { |
20 switch (elm.getNodeName()) { |
23 throw new Exception("Option has no argument string"); |
21 case "value" -> values.add(new OptionValue(this, |
24 } |
22 elm.getAttribute("str"), |
25 opt.setArgument(arg); |
23 new TargetData(elm))); |
26 |
24 case "default" -> defaults.add(new OptionDefault(this, |
27 NodeList nodes = element.getChildNodes(); |
25 elm.getAttribute("value"), |
28 for (int i = 0; i < nodes.getLength(); i++) { |
26 elm.getAttribute("platform"))); |
29 Node node = nodes.item(i); |
|
30 if (node.getNodeType() == Node.ELEMENT_NODE) { |
|
31 Element elm = (Element) node; |
|
32 String n = elm.getNodeName(); |
|
33 if (n.equals("value")) { |
|
34 opt.values.add(new OptionValue(opt, |
|
35 elm.getAttribute("str"), |
|
36 TargetData.parse(elm) |
|
37 )); |
|
38 } else if (n.equals("default")) { |
|
39 var def = new OptionDefault(opt); |
|
40 def.setValueName(elm.getAttribute("value")); |
|
41 String defPlatform = elm.getAttribute(("platform")); |
|
42 if (!defPlatform.isBlank()) { |
|
43 def.setPlatform(defPlatform); |
|
44 } |
|
45 opt.defaults.add(def); |
|
46 } |
|
47 } |
27 } |
48 } |
28 }); |
49 |
|
50 return opt; |
|
51 } |
29 } |
52 |
30 |
53 public String getArgument() { |
31 public String getArgument() { |
54 return arg; |
32 return arg; |
55 } |
|
56 |
|
57 public void setArgument(String arg) { |
|
58 this.arg = arg; |
|
59 } |
33 } |
60 |
34 |
61 public String getVarName() { |
35 public String getVarName() { |
62 return shId("OPT_" + arg.toUpperCase()); |
36 return shId("OPT_" + arg.toUpperCase()); |
63 } |
37 } |