|
1 |
| package org.jconfig.parser; |
|
2 |
| |
|
3 |
| import org.jconfig.Category; |
|
4 |
| import org.jconfig.Configuration; |
|
5 |
| import org.jconfig.DefaultCategory; |
|
6 |
| import org.jconfig.ExtensibleConfiguration; |
|
7 |
| import org.w3c.dom.Document; |
|
8 |
| import org.w3c.dom.NamedNodeMap; |
|
9 |
| import org.w3c.dom.Node; |
|
10 |
| import org.w3c.dom.NodeList; |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| public class CDataConfigParser extends AbstractConfigParser { |
|
33 |
| |
|
34 |
2
| public CDataConfigParser() {
|
|
35 |
| } |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
1
| public Configuration parse(Document doc,String configName) {
|
|
43 |
1
| ExtensibleConfiguration configuration = new ExtensibleConfiguration(configName);
|
|
44 |
1
| String currentCategory;
|
|
45 |
1
| getVariables(doc,configuration);
|
|
46 |
1
| getIncludeProperties(doc, configuration);
|
|
47 |
1
| getBaseConfigName(doc, configuration);
|
|
48 |
| |
|
49 |
1
| NodeList nl = doc.getElementsByTagName("category");
|
|
50 |
1
| for (int i = 0; i < nl.getLength(); i++) {
|
|
51 |
| |
|
52 |
2
| Node n = nl.item(i);
|
|
53 |
| |
|
54 |
2
| NamedNodeMap curAtt = n.getAttributes();
|
|
55 |
2
| Node curNode = curAtt.getNamedItem("name");
|
|
56 |
2
| currentCategory = curNode.getNodeValue();
|
|
57 |
2
| Category ec = new DefaultCategory(currentCategory);
|
|
58 |
2
| configuration.setCategory(ec);
|
|
59 |
2
| curNode = curAtt.getNamedItem("extends");
|
|
60 |
2
| if ( curNode != null ) {
|
|
61 |
1
| ec.setExtendsCategory(curNode.getNodeValue());
|
|
62 |
| } |
|
63 |
| |
|
64 |
2
| for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
|
|
65 |
| |
|
66 |
12
| if ( child.getNodeType() == 1 && child.getFirstChild() != null ) {
|
|
67 |
5
| String name = child.getNodeName();
|
|
68 |
5
| String value = child.getFirstChild().getNodeValue();
|
|
69 |
5
| if (name != null && value != null) {
|
|
70 |
| |
|
71 |
| |
|
72 |
5
| configuration.setProperty(name,value,currentCategory);
|
|
73 |
| } |
|
74 |
| } |
|
75 |
| } |
|
76 |
| } |
|
77 |
1
| return configuration;
|
|
78 |
| } |
|
79 |
| |
|
80 |
| } |