EOS 2  1.1.0
Einfache Objektbasierte Sprache
ConfigLoader.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.config;
2 
3 import java.io.File;
4 import java.util.LinkedList;
5 import javax.xml.parsers.DocumentBuilder;
6 import javax.xml.parsers.DocumentBuilderFactory;
7 
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Node;
10 import org.w3c.dom.NodeList;
11 
12 public class ConfigLoader {
13  private static ConfigLoader singleton = new ConfigLoader();
14  private LinkedList<Document> docs = new LinkedList<>();
15 
16  private ConfigLoader() {
17  }
18 
20  return singleton;
21  }
22 
23  public void load(File base) throws Exception {
24  File[] configs = base.listFiles((File f) -> {
25  return f.getName().endsWith(".xml");
26  });
27  for (File f : configs) {
28  if (f.exists() && f.isFile()) {
29  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
30  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
31  Document doc = dBuilder.parse(f);
32  docs.add(doc);
33  }
34  }
35  }
36 
37  public void apply() {
38  for (Document doc : docs) {
39  apply(doc);
40  }
41  }
42 
43  private void apply(Document doc) {
44  NodeList n = doc.getChildNodes();
45  for (int i = 0; i < n.getLength(); i++) {
46  switch (n.item(i).getNodeName()) {
47  case "types":
48  applyTypes(n.item(i));
49  break;
50  default:
51  // ignore wrong types
52  }
53  }
54  }
55 
56  private void applyTypes(Node e) {
57  NodeList n = e.getChildNodes();
58  for (int i = 0; i < n.getLength(); i++) {
59  switch (n.item(i).getNodeName()) {
60  case "class":
61  applyClass(n.item(i));
62  break;
63  default:
64  // ignore wrong types
65  }
66  }
67  }
68 
69  private void applyClass(Node e) {
70  var attributes = e.getAttributes();
71  attributes.getNamedItem("class").getNodeValue();
72  attributes.getNamedItem("class").getNodeValue();
73  NodeList n = e.getChildNodes();
74  for (int i = 0; i < n.getLength(); i++) {
75  switch (n.item(i).getNodeName()) {
76  case "method":
77  break;
78  case "property":
79  break;
80  case "function":
81  break;
82  default:
83  // ignore wrong types
84  }
85  }
86  }
87 }
Impressum