Class Node

java.lang.Object
org.apache.logging.log4j.plugins.Node

public class Node extends Object
Configurations are represented as a tree of Node instances. Each Node may have attributes, children nodes, an optional value (which is a special kind of attribute for certain configuration file formats which support the concept), and a name which corresponds to a Plugin class in the Core namespace and is specified via an element name or the type attribute. Configuration factories parse a configuration resource into a tree of Nodes with a single root Node.
  • Field Details

    • CORE_NAMESPACE

      public static final String CORE_NAMESPACE
      Main plugin namespace for plugins which are represented as a configuration node. Such plugins tend to be available as XML elements in a configuration file.
      Since:
      2.1
      See Also:
    • CURRENT_NODE

      public static final Key<Node> CURRENT_NODE
      Key describing the current node being configured.
  • Constructor Details

    • Node

      public Node(Node parent, String name, PluginType<?> type)
      Creates a new instance of Node and initializes it with a name and the corresponding XML element.
      Parameters:
      parent - the node's parent.
      name - the node's name.
      type - The Plugin Type associated with the node.
    • Node

      public Node()
      Constructs a root node. Root nodes have no defined type, name, or parent node.
    • Node

      public Node(Node node)
      Constructs a fresh copy of the provided Node.
      Parameters:
      node - original node to copy
  • Method Details

    • setParent

      public void setParent(Node parent)
    • getAttributes

      public Map<String,String> getAttributes()
    • getChildren

      public List<Node> getChildren()
    • addChild

      public void addChild(Node child)
    • hasChildren

      public boolean hasChildren()
    • getValue

      public String getValue()
    • setValue

      public void setValue(String value)
    • getParent

      public Node getParent()
    • getName

      public String getName()
    • isRoot

      public boolean isRoot()
    • setObject

      public void setObject(Object obj)
    • getObject

      public <T> T getObject()
    • getObject

      public <T> T getObject(Class<T> clazz)
      Returns this node's object cast to the given class.
      Type Parameters:
      T - the type to cast to.
      Parameters:
      clazz - the class to cast this node's object to.
      Returns:
      this node's object.
      Since:
      2.1
    • isInstanceOf

      public boolean isInstanceOf(Class<?> clazz)
      Determines if this node's object is an instance of the given class.
      Parameters:
      clazz - the class to check.
      Returns:
      true if this node's object is an instance of the given class.
      Since:
      2.1
    • getType

      public PluginType<?> getType()
    • removeMatchingAttribute

      public Optional<String> removeMatchingAttribute(String name, Collection<String> aliases)
      Finds and removes the attribute with a name equaling ignoring case either the provided name or one of the provided aliases.
      Parameters:
      name - name of attribute to find
      aliases - aliases of attribute to find
      Returns:
      the removed attribute value if found or empty if no attributes match
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • newBuilder

      public static Node.Builder newBuilder()