View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
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   * A Configuration node.
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       * Creates a new instance of <code>Node</code> and initializes it
42       * with a name and the corresponding XML element.
43       *
44       * @param parent the node's parent.
45       * @param name the node's name.
46       * @param type The Plugin Type associated with the node.
47       */
48      public Node(Node parent, String name, 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 Map<String, String> getAttributes() {
61          return attributes;
62      }
63  
64      public List<Node> getChildren() {
65          return children;
66      }
67  
68      public boolean hasChildren() {
69          return children.size() > 0;
70      }
71  
72      public String getValue() {
73          return value;
74      }
75  
76      public void setValue(String value) {
77          this.value = value;
78      }
79  
80      public Node getParent() {
81          return parent;
82      }
83  
84      public String getName() {
85          return name;
86      }
87  
88      public boolean isRoot() {
89          return parent == null;
90      }
91  
92      public void setObject(Object obj) {
93          object = obj;
94      }
95  
96      public Object getObject() {
97          return object;
98      }
99  
100     public PluginType getType() {
101         return type;
102     }
103 
104     @Override
105     public String toString() {
106         if (object == null) {
107             return "null";
108         }
109         return type.isObjectPrintable() ? object.toString() :
110             type.getPluginClass().getName() + " with name " + name;
111     }
112 }