liquibase.parser.core
Class ParsedNode

java.lang.Object
  extended by 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:


Constructor Summary
ParsedNode(String namespace, String name)
           
 
Method Summary
 ParsedNode addChild(ParsedNode node)
          Adds the given ParsedNode as a child
 ParsedNode addChild(String namespace, String nodeName, Object value)
          Convenience method to add a new ParsedNode with the passed namespace/name and value
 ParsedNode addChildren(Map<String,Object> child)
          Adds the given map as children of this node.
protected
<T> T
convertObject(Object rawValue, Class<T> type)
           
protected  ParsedNode createNode(String namespace, String nodeName)
           
 boolean equals(Object obj)
           
 ParsedNode getChild(String namespace, String name)
          Returns the ParsedNode defined by the given namespace and name.
 List<ParsedNode> getChildren()
          Returns the child ParsedNodes of this node.
 List<ParsedNode> getChildren(String namespace, String nodename)
          Returns all child nodes with the given namespace and name.
 Object getChildValue(String namespace, String nodename)
          Returns the value of the given node with no conversion attempted.
<T> T
getChildValue(String namespace, String nodename, Class<T> type)
          Returns the value of the given node, converted to the passed type.
<T> T
getChildValue(String namespace, String nodename, T defaultValue)
          Convenience method for getChildValue(String, String, Class) but returns the passed defaultValue if the given node is null or not defined.
 String getName()
          Each node key contains both a namespace and a name which together identifies the node.
 String getNamespace()
          Each node key contains both a namespace and a name which together identifies the node.
 Object getValue()
          Return the value associated with this node.
<T> T
getValue(Class<T> type)
          Return the value associated with this node converted to the given type.
 int hashCode()
           
protected  boolean namespaceMatches(ParsedNode node, String namespace)
           
protected  boolean nodeMatches(ParsedNode node, String namespace, String nodename)
           
 ParsedNode removeChild(String namespace, String name)
           
 ParsedNode setValue(Object value)
          Sets the value of this ParsedNode.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParsedNode

public ParsedNode(String namespace,
                  String name)
Method Detail

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.


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

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

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)

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


Copyright © 2016 Liquibase.org. All rights reserved.