Package liquibase.parser.core
Class ParsedNode
java.lang.Object
liquibase.parser.core.ParsedNode
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionConvenience method to add a new ParsedNode with the passed namespace/name and valueaddChild
(ParsedNode node) Adds the given ParsedNode as a childaddChildren
(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
Returns the ParsedNode defined by the given namespace and name.Returns the child ParsedNodes of this node.getChildren
(String namespace, String nodename) Returns all child nodes with the given namespace and name.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 forgetChildValue(String, String, Class)
but returns the passed defaultValue if the given node is null or not defined.getName()
Each node key contains both a namespace and a name which together identifies the node.Each node key contains both a namespace and a name which together identifies the node.getValue()
Return the value associated with this node.<T> T
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) Matches the namespace and name of this node.removeChild
(String namespace, String name) Sets the value of this ParsedNode.toString()
-
Constructor Details
-
ParsedNode
-
-
Method Details
-
getNamespace
Each node key contains both a namespace and a name which together identifies the node. -
getName
Each node key contains both a namespace and a name which together identifies the node. -
getChildren
Returns the child ParsedNodes of this node. Returned list is unmodifiableList. -
getChildren
Returns all child nodes with the given namespace and name. If none match, an empty list is returned. Returned list is unmodifiableList. -
getValue
Return the value associated with this node. -
setValue
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
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
-
addChild
Adds the given ParsedNode as a child- Throws:
ParsedNodeException
-
addChildren
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 allsetValue(Object)
) logic) is the value.- Throws:
ParsedNodeException
-
getChild
Returns the ParsedNode defined by the given namespace and name.- Throws:
ParsedNodeException
- if multiple nodes match.
-
removeChild
- Throws:
ParsedNodeException
-
nodeMatches
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
-
getChildValue
public <T> T getChildValue(String namespace, String nodename, T defaultValue) throws ParsedNodeException Convenience method forgetChildValue(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
- Throws:
ParsedNodeException
-
getChildValue
Returns the value of the given node with no conversion attempted.- Throws:
ParsedNodeException
-
toString
-
equals
-
hashCode
public int hashCode()
-