Class ParsedNode

java.lang.Object
liquibase.parser.core.ParsedNode

public class ParsedNode extends Object
Acts as a standard abstract syntax layer for changelogs defined in different formats. ChangeLogParser implementations and other classes that work with multiple formats can create objects directs or create instances of this class which can then be passed to the load() method of the object they want to configure. For example, LiquibaseSerializable.load(ParsedNode, liquibase.resource.ResourceAccessor).

ParsedNodes are a simple key/value structure with the following characteristics:

  • Keys include a namespace as well as the node name
  • There can be multiple children nodes with the same node namespace+name
  • There is an unkeyed "value" object in addition to the children nodes
  • The value node cannot be a ParsedNode. If you attempt to set value to be or contain a ParsedNode it will actually be set as a child
  • Constructor Details

    • ParsedNode

      public ParsedNode(String namespace, String name)
  • Method Details

    • getNamespace

      public String getNamespace()
      Each node key contains both a namespace and a name which together identifies the node.
    • getName

      public String getName()
      Each node key contains both a namespace and a name which together identifies the node.
    • getChildren

      public List<ParsedNode> getChildren()
      Returns the child ParsedNodes of this node. Returned list is unmodifiableList.
    • getChildren

      public List<ParsedNode> getChildren(String namespace, String nodename)
      Returns all child nodes with the given namespace and name. If none match, an empty list is returned. Returned list is unmodifiableList.
    • getValue

      public Object getValue()
      Return the value associated with this node.
    • setValue

      public ParsedNode setValue(Object value) throws ParsedNodeException
      Sets the value of this ParsedNode. If the passed value is a ParsedNode, it is added as a child, not as the value. If the passed value is a Map, it is converted to a ParsedNode and added as a child, not as the value. If the passed value is a Collection, each object is added as a child if it is a ParsedNode or a Map. If there are multiple simple values in a passed collection, value is set to a List. If there is a single value in a collection, value is set to the single value.
      Throws:
      ParsedNodeException
    • getValue

      public <T> T getValue(Class<T> type) throws ParsedNodeException
      Return the value associated with this node converted to the given type.
      Throws:
      ParsedNodeException - if the current value type cannot be converted
    • addChild

      public ParsedNode addChild(String namespace, String nodeName, Object value) throws ParsedNodeException
      Convenience method to add a new ParsedNode with the passed namespace/name and value
      Throws:
      ParsedNodeException
    • createNode

      protected ParsedNode createNode(String namespace, String nodeName)
    • addChild

      public ParsedNode addChild(ParsedNode node) throws ParsedNodeException
      Adds the given ParsedNode as a child
      Throws:
      ParsedNodeException
    • addChildren

      public ParsedNode addChildren(Map<String,Object> child) throws ParsedNodeException
      Adds the given map as children of this node. If the passed map is empty, it is a no-op For each key in the map, a new child is added with the key as the name and the value (with all setValue(Object)) logic) is the value.
      Throws:
      ParsedNodeException
    • getChild

      public ParsedNode getChild(String namespace, String name) throws ParsedNodeException
      Returns the ParsedNode defined by the given namespace and name.
      Throws:
      ParsedNodeException - if multiple nodes match.
    • removeChild

      public ParsedNode removeChild(String namespace, String name) throws ParsedNodeException
      Throws:
      ParsedNodeException
    • nodeMatches

      protected boolean nodeMatches(ParsedNode node, String namespace, String nodename)
      Matches the namespace and name of this node. Matching is performed case-insensitively.
      Parameters:
      node - The node to match against.
      namespace - The namespace to match against.
      nodename - The name to match against.
      Returns:
      true if the namespace and name of the node match the specified namespace and name, ignoring case; false otherwise.
    • namespaceMatches

      protected boolean namespaceMatches(ParsedNode node, String namespace)
    • getChildValue

      public <T> T getChildValue(String namespace, String nodename, T defaultValue) throws ParsedNodeException
      Convenience method for getChildValue(String, String, Class) but returns the passed defaultValue if the given node is null or not defined.
      Throws:
      ParsedNodeException
    • getChildValue

      public <T> T getChildValue(String namespace, String nodename, Class<T> type) throws ParsedNodeException
      Returns the value of the given node, converted to the passed type.
      Throws:
      ParsedNodeException - if there is an error converting the value
    • convertObject

      protected <T> T convertObject(Object rawValue, Class<T> type) throws ParsedNodeException
      Throws:
      ParsedNodeException
    • getChildValue

      public Object getChildValue(String namespace, String nodename) throws ParsedNodeException
      Returns the value of the given node with no conversion attempted.
      Throws:
      ParsedNodeException
    • toString

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object