1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.config;
18
19 import org.apache.logging.log4j.core.config.plugins.PluginType;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26
27
28
29 public class Node {
30
31 private final Node parent;
32 private final String name;
33 private String value;
34 private final PluginType type;
35 private final Map<String, String> attributes = new HashMap<String, String>();
36 private final List<Node> children = new ArrayList<Node>();
37 private Object object;
38
39
40
41
42
43
44
45
46
47
48 public Node(final Node parent, final String name, final PluginType type) {
49 this.parent = parent;
50 this.name = name;
51 this.type = type;
52 }
53
54 public Node() {
55 this.parent = null;
56 this.name = null;
57 this.type = null;
58 }
59
60 public Node(final Node node) {
61 this.parent = node.parent;
62 this.name = node.name;
63 this.type = node.type;
64 this.attributes.putAll(node.getAttributes());
65 this.value = node.getValue();
66 for (final Node child : node.getChildren()) {
67 this.children.add(new Node(child));
68 }
69 this.object = node.object;
70 }
71
72 public Map<String, String> getAttributes() {
73 return attributes;
74 }
75
76 public List<Node> getChildren() {
77 return children;
78 }
79
80 public boolean hasChildren() {
81 return children.size() > 0;
82 }
83
84 public String getValue() {
85 return value;
86 }
87
88 public void setValue(final String value) {
89 this.value = value;
90 }
91
92 public Node getParent() {
93 return parent;
94 }
95
96 public String getName() {
97 return name;
98 }
99
100 public boolean isRoot() {
101 return parent == null;
102 }
103
104 public void setObject(final Object obj) {
105 object = obj;
106 }
107
108 public Object getObject() {
109 return object;
110 }
111
112 public PluginType getType() {
113 return type;
114 }
115
116 @Override
117 public String toString() {
118 if (object == null) {
119 return "null";
120 }
121 return type.isObjectPrintable() ? object.toString() :
122 type.getPluginClass().getName() + " with name " + name;
123 }
124 }