001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 package org.apache.logging.log4j.core.config; 018 019 import org.apache.logging.log4j.core.config.plugins.PluginType; 020 021 import java.util.ArrayList; 022 import java.util.HashMap; 023 import java.util.List; 024 import java.util.Map; 025 026 /** 027 * A Configuration node. 028 */ 029 public class Node { 030 031 private final Node parent; 032 private final String name; 033 private String value; 034 private final PluginType type; 035 private final Map<String, String> attributes = new HashMap<String, String>(); 036 private final List<Node> children = new ArrayList<Node>(); 037 private Object object; 038 039 040 /** 041 * Creates a new instance of <code>Node</code> and initializes it 042 * with a name and the corresponding XML element. 043 * 044 * @param parent the node's parent. 045 * @param name the node's name. 046 * @param type The Plugin Type associated with the node. 047 */ 048 public Node(Node parent, String name, PluginType type) { 049 this.parent = parent; 050 this.name = name; 051 this.type = type; 052 } 053 054 public Node() { 055 this.parent = null; 056 this.name = null; 057 this.type = null; 058 } 059 060 public Map<String, String> getAttributes() { 061 return attributes; 062 } 063 064 public List<Node> getChildren() { 065 return children; 066 } 067 068 public boolean hasChildren() { 069 return children.size() > 0; 070 } 071 072 public String getValue() { 073 return value; 074 } 075 076 public void setValue(String value) { 077 this.value = value; 078 } 079 080 public Node getParent() { 081 return parent; 082 } 083 084 public String getName() { 085 return name; 086 } 087 088 public boolean isRoot() { 089 return parent == null; 090 } 091 092 public void setObject(Object obj) { 093 object = obj; 094 } 095 096 public Object getObject() { 097 return object; 098 } 099 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 }