Package org.jboss.dmr

Class ModelNode

  • All Implemented Interfaces:
    Externalizable, Serializable, Cloneable

    public class ModelNode
    extends Object
    implements Externalizable, Cloneable
    A dynamic model representation node object.

    A node can be of any type specified in the ModelType enumeration. The type can be queried via getType() and updated via any of the set*() methods. The value of the node can be acquired via the as<type>() methods, where <type> is the desired value type. If the type is not the same as the node type, a conversion is attempted between the types.

    A node can be made read-only by way of its protect() method, which will prevent any further changes to the node or its sub-nodes.

    Instances of this class are not thread-safe and need to be synchronized externally.

    Author:
    David M. Lloyd, Richard Opalka
    See Also:
    Serialized Form
    • Constructor Detail

      • ModelNode

        public ModelNode()
        Creates a new ModelNode with an undefined value.
      • ModelNode

        public ModelNode​(BigDecimal value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
      • ModelNode

        public ModelNode​(BigInteger value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
      • ModelNode

        public ModelNode​(boolean value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value.
      • ModelNode

        public ModelNode​(byte[] value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
      • ModelNode

        public ModelNode​(double value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value.
      • ModelNode

        public ModelNode​(int value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value.
      • ModelNode

        public ModelNode​(long value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value.
      • ModelNode

        public ModelNode​(String value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
      • ModelNode

        public ModelNode​(ValueExpression value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
      • ModelNode

        public ModelNode​(ModelType value)
        Creates a new ModelNode with the given value.
        Parameters:
        value - the value. Cannot be null
        Throws:
        IllegalArgumentException - if value is null
    • Method Detail

      • protect

        public void protect()
        Prevent further modifications to this node and its sub-nodes. Note that copies of this node made after this method call will not be protected.
      • isProtected

        public boolean isProtected()
        Returns whether this node has been protected.
        Returns:
        true if protect() has been invoked on this node
      • asLong

        public long asLong()
                    throws IllegalArgumentException
        Get the value of this node as a long. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the long value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asLong

        public long asLong​(long defVal)
        Get the value of this node as a long. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the long value
        Throws:
        NumberFormatException - if this node's type is ModelType.STRING and a numeric conversion of the string value is not possible
        IllegalArgumentException - if this node's type is one where no numeric conversion is possible
      • asLongOrNull

        public Long asLongOrNull()
        Get the value of this node as a Long, or null if this node is not defined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the long value or null
        Throws:
        NumberFormatException - if this node's type is ModelType.STRING and a numeric conversion of the string value is not possible
        IllegalArgumentException - if this node's type is one where no numeric conversion is possible
      • asInt

        public int asInt()
                  throws IllegalArgumentException
        Get the value of this node as an int. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the int value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asInt

        public int asInt​(int defVal)
        Get the value of this node as an int. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the int value
        Throws:
        NumberFormatException - if this node's type is ModelType.STRING and a numeric conversion of the string value is not possible
        IllegalArgumentException - if this node's type is one where no numeric conversion is possible
      • asIntOrNull

        public Integer asIntOrNull()
        Get the value of this node as an int, or null if this node is not defined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the int value or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asBoolean

        public boolean asBoolean()
                          throws IllegalArgumentException
        Get the value of this node as a boolean. Collection types return true for non-empty collections. Numerical types return true for non-zero values.
        Returns:
        the boolean value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asBoolean

        public boolean asBoolean​(boolean defVal)
        Get the value of this node as a boolean. Collection types return true for non-empty collections. Numerical types return true for non-zero values.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the boolean value
        Throws:
        IllegalArgumentException - if this node's type is one where no numeric conversion is possible or if the type is ModelType.STRING and the string value is not equal, ignoring case, to the literal true or false
      • asBooleanOrNull

        public Boolean asBooleanOrNull()
                                throws IllegalArgumentException
        Get the value of this node as a boolean, or null if this node is not defined. Collection types return true for non-empty collections. Numerical types return true for non-zero values.
        Returns:
        the boolean value or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asString

        public String asString()
        Get the value as a string. This is the literal value of this model node. More than one node type may yield the same value for this method.
        Returns:
        the string value. A node that is not defined returns the literal string undefined
      • asString

        public String asString​(String defVal)
        Get the value as a string. This is the literal value of this model node. More than one node type may yield the same value for this method.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the string value.
      • asStringOrNull

        public String asStringOrNull()
        Get the value as a string or null if this node is not defined. This is the literal value of this model node. More than one node type may yield the same value for this method.
        Returns:
        the string value or null
      • asDouble

        public double asDouble()
                        throws IllegalArgumentException
        Get the value of this node as a double. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the double value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asDouble

        public double asDouble​(double defVal)
        Get the value of this node as an double. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the int value
        Throws:
        NumberFormatException - if this node's type is ModelType.STRING and a numeric conversion of the string value is not possible
        IllegalArgumentException - if this node's type is one where no numeric conversion is possible
      • asDoubleOrNull

        public Double asDoubleOrNull()
                              throws IllegalArgumentException
        Get the value of this node as a double or null if this node is not defined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the double value or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asType

        public ModelType asType()
                         throws IllegalArgumentException
        Get the value of this node as a type, expressed using the ModelType enum. The string value of this node must be convertible to a type.
        Returns:
        the ModelType value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asBigDecimal

        public BigDecimal asBigDecimal()
                                throws IllegalArgumentException
        Get the value of this node as a BigDecimal. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the BigDecimal value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asBigDecimalOrNull

        public BigDecimal asBigDecimalOrNull()
                                      throws IllegalArgumentException
        Get the value of this node as a BigDecimal or null if this node is not defined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the BigDecimal value or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asBigInteger

        public BigInteger asBigInteger()
                                throws IllegalArgumentException
        Get the value of this node as a BigInteger. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the BigInteger value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asBigIntegerOrNull

        public BigInteger asBigIntegerOrNull()
                                      throws IllegalArgumentException
        Get the value of this node as a BigInteger or null if this node is not defined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.
        Returns:
        the BigInteger value or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asBytes

        public byte[] asBytes()
                       throws IllegalArgumentException
        Get the value of this node as a byte array. Strings and string-like values will return the UTF-8 encoding of the string. Numerical values will return the byte representation of the number.
        Returns:
        the bytes
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asBytesOrNull

        public byte[] asBytesOrNull()
                             throws IllegalArgumentException
        Get the value of this node as a byte array or null if this node is not defined. Strings and string-like values will return the UTF-8 encoding of the string. Numerical values will return the byte representation of the number.
        Returns:
        the bytes or null
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asProperty

        public Property asProperty()
                            throws IllegalArgumentException
        Get the value of this node as a property. Object values will return a property if there is exactly one property in the object. List values will return a property if there are exactly two items in the list, and if the first is convertible to a string.
        Returns:
        the property value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asPropertyList

        public List<Property> asPropertyList()
                                      throws IllegalArgumentException
        Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.
        Returns:
        the property list value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • asPropertyListOrEmpty

        public List<Property> asPropertyListOrEmpty()
                                             throws IllegalArgumentException
        Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.
        Returns:
        the property list value or an empty list if not defined.
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asPropertyList

        public List<Property> asPropertyList​(List<Property> defaultValue)
                                      throws IllegalArgumentException
        Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.
        Parameters:
        defaultValue - the value to return if not defined.
        Returns:
        the property list value or the specified default value if not defined.
        Throws:
        IllegalArgumentException - if no conversion is possible
      • asObject

        public ModelNode asObject()
                           throws IllegalArgumentException
        Get a copy of this value as an object. Object values will simply copy themselves as by the clone() method. Property values will return a single-entry object whose key and value are copied from the property key and value. List values will attempt to interpolate the list into an object by iterating each item, mapping each property into an object entry and otherwise taking pairs of list entries, converting the first to a string, and using the pair of entries as a single object entry. If an object key appears more than once in the source object, the last key takes precedence.
        Returns:
        the object value
        Throws:
        IllegalArgumentException - if this node is not defined or if no conversion is possible
      • isDefined

        public boolean isDefined()
        Determine whether this node is defined. Equivalent to the expression: getType() != ModelType.UNDEFINED.
        Returns:
        true if this node's value is defined
      • set

        public ModelNode set​(int newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(long newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(double newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(boolean newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • setExpression

        @Deprecated
        public ModelNode setExpression​(String newValue)
        Deprecated.
        Change this node's value to the given expression value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(ValueExpression newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(String newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(BigDecimal newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(BigInteger newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(ModelNode newValue)
        Change this node's value to the given value. The value is copied from the parameter.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(byte[] newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(ModelType newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(Property newValue)
        Change this node's value to the given value.
        Parameters:
        newValue - the new value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             ModelNode propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             int propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             long propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             double propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             boolean propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             String propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • setExpression

        @Deprecated
        public ModelNode setExpression​(String propertyName,
                                       String propertyValue)
        Deprecated.
        Change this node's value to a property with the given name and expression value.
        Parameters:
        propertyName - the property name
        propertyValue - the property expression value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             ValueExpression propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             BigDecimal propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             BigInteger propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             byte[] propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(String propertyName,
                             ModelType propertyValue)
        Change this node's value to a property with the given name and value.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
      • set

        public ModelNode set​(Collection<ModelNode> newValue)
        Change this node's value to a list whose values are copied from the given collection.
        Parameters:
        newValue - the list value
        Returns:
        this node
      • setEmptyList

        public ModelNode setEmptyList()
        Change this node's value to an empty list.
        Returns:
        this node
      • setEmptyObject

        public ModelNode setEmptyObject()
        Change this node's value to an empty object.
        Returns:
        this node
      • get

        public ModelNode get​(String name)
        Get the child of this node with the given name. If no such child exists, create it. If the node is undefined, it will be initialized to be of type ModelType.OBJECT.

        When called on property values, the name must match the property name.

        Parameters:
        name - the child name
        Returns:
        the child
        Throws:
        IllegalArgumentException - if this node does not support getting a child with the given name
      • require

        public ModelNode require​(String name)
                          throws NoSuchElementException
        Require the existence of a child of this node with the given name, returning the child. If no such child exists, an exception is thrown.

        When called on property values, the name must match the property name.

        Parameters:
        name - the child name
        Returns:
        the child
        Throws:
        NoSuchElementException - if the element does not exist
      • remove

        public ModelNode remove​(String name)
                         throws NoSuchElementException
        Remove a child of this node, returning the child. If no such child exists, null is returned.

        When called on property values, the name must match the property name.

        Parameters:
        name - the child name
        Returns:
        the child, or null if no child with the given name exists
        Throws:
        NoSuchElementException
      • remove

        public ModelNode remove​(int index)
                         throws NoSuchElementException
        Remove a child of this list, returning the child. If no such child exists, an exception is thrown.

        When called on property values, the name must match the property name.

        Parameters:
        index - the child index
        Returns:
        the child
        Throws:
        NoSuchElementException - if the element does not exist
      • get

        public ModelNode get​(int index)
        Get the child of this node with the given index. If no such child exists, create it (adding list entries as needed). If the node is undefined, it will be initialized to be of type ModelType.LIST.

        When called on property values, the index must be zero.

        Parameters:
        index - the child index
        Returns:
        the child
        Throws:
        IllegalArgumentException - if this node does not support getting a child with the given index
      • require

        public ModelNode require​(int index)
        Require the existence of a child of this node with the given index, returning the child. If no such child exists, an exception is thrown.

        When called on property values, the index must be zero.

        Parameters:
        index - the child index
        Returns:
        the child
        Throws:
        NoSuchElementException - if the element does not exist
      • insert

        public ModelNode insert​(ModelNode newValue,
                                int index)
        insert copy of the given value to provided index of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST. An index equal to the current number of child elements held by this node is allowed (thus adding a child) but an index greater than that is not allowed (i.e. adding intervening elements is not supported.)
        Parameters:
        newValue - the new value to add
        Returns:
        this node
        Throws:
        IndexOutOfBoundsException - if index is greater than zero and is greater than the number of child nodes currently stored in this node
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             int propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             long propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             double propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             boolean propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             String propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • add

        public ModelNode add​(String propertyName,
                             byte[] propertyValue)
        Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of type ModelType.LIST.
        Parameters:
        propertyName - the property name
        propertyValue - the property value
        Returns:
        this node
        Throws:
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • insert

        public ModelNode insert​(int index)
        Insert a node at provided index of this node's value list and return it. If the node is undefined, it will be initialized to be of type ModelType.LIST. An index equal to the current number of child elements held by this node is allowed (thus adding a child) but an index greater than that is not allowed (i.e. adding intervening elements is not supported.)
        Parameters:
        index - where in list to put it
        Returns:
        the new node
        Throws:
        IndexOutOfBoundsException - if index is greater than zero and is greater than the number of child nodes currently stored in this node
        IllegalArgumentException - if this node is defined and its type is not ModelType.LIST
      • has

        public boolean has​(int index)
        Determine whether this node has a child with the given index. Property node types always contain exactly one value.
        Parameters:
        index - the index
        Returns:
        true if there is a (possibly undefined) node at the given index
      • has

        public boolean has​(String key)
        Determine whether this node has a child with the given name. Property node types always contain exactly one value with a key equal to the property name.
        Parameters:
        key - the name
        Returns:
        true if there is a (possibly undefined) node at the given key
      • has

        public boolean has​(String... names)
        Recursively determine whether this node has children with the given names. If any child along the path does not exist, return false.
        Parameters:
        names - the child names
        Returns:
        true if a call to get(String...) with the given names would succeed without needing to create any new nodes; false otherwise
      • hasDefined

        public boolean hasDefined​(int index)
        Determine whether this node has a defined child with the given index. Property node types always contain exactly one value.
        Parameters:
        index - the index
        Returns:
        true if there is a node at the given index and its type is not ModelType.UNDEFINED
      • hasDefined

        public boolean hasDefined​(String key)
        Determine whether this node has a defined child with the given name. Property node types always contain exactly one value with a key equal to the property name.
        Parameters:
        key - the name
        Returns:
        true if there is a node at the given index and its type is not ModelType.UNDEFINED
      • hasDefined

        public boolean hasDefined​(String... names)
        Recursively determine whether this node has defined children with the given names. If any child along the path does not exist or is not defined, return false.
        Parameters:
        names - the child names
        Returns:
        true if a call to get(String...) with the given names would succeed without needing to create any new nodes and without traversing any undefined nodes; false otherwise
      • asList

        public List<ModelNode> asList()
        Get the list of entries contained in this object. Property node types always contain exactly one entry (itself). Lists will return an unmodifiable view of their contained list. Objects will return a list of properties corresponding to the mappings within the object. Other isDefined() types will return an empty list.
        Returns:
        the entry list
        Throws:
        IllegalArgumentException - if this node is not defined
      • asList

        public List<ModelNode> asList​(List<ModelNode> defVal)
        Get the value as a list as per asList(), or return the given default if this node is not defined.
        Parameters:
        defVal - the default value to return if this node is not defined
        Returns:
        the list value or an empty list
      • asListOrEmpty

        public List<ModelNode> asListOrEmpty()
        Get the value as a list as per asList(), or return an empty list if this node is not defined.
        Returns:
        the list value or an empty list (not null)
      • get

        public ModelNode get​(String... names)
        Recursively get the children of this node with the given names. If any child along the path does not exist, create it. If any node is the path is undefined, it will be initialized to be of type ModelType.OBJECT.
        Parameters:
        names - the child names
        Returns:
        the child
        Throws:
        IllegalArgumentException - if a node does not support getting a child with the given name path
      • toString

        public String toString()
        Get a human-readable string representation of this model node, formatted nicely (possibly on multiple lines).
        Overrides:
        toString in class Object
        Returns:
        the string representation
      • writeString

        public void writeString​(PrintWriter writer,
                                boolean compact)
        Output the DMR string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.
        Parameters:
        writer - A PrintWriter instance used to output the DMR string.
        compact - Flag that indicates whether or not the string should be all on one line (i.e. true) or should be printed on multiple lines (false).
      • toJSONString

        public String toJSONString​(boolean compact)
        Get a JSON string representation of this model node, formatted nicely, if requested.
        Parameters:
        compact - Flag that indicates whether or not the string should be all on one line (i.e. true) or should be printed on multiple lines (false).
        Returns:
        The JSON string.
      • writeJSONString

        public void writeJSONString​(PrintWriter writer,
                                    boolean compact)
        Output the JSON string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.
        Parameters:
        writer - A PrintWriter instance used to output the JSON string.
        compact - Flag that indicates whether or not the string should be all on one line (i.e. true) or should be printed on multiple lines (false).
      • fromString

        public static ModelNode fromString​(String input)
        Get a model node from a string representation of the model node.
        Parameters:
        input - the input string
        Returns:
        the model node
      • fromJSONString

        public static ModelNode fromJSONString​(String input)
      • fromStream

        public static ModelNode fromStream​(InputStream stream)
                                    throws IOException
        Get a model node from a text representation of the model node. The stream must be decodable using the UTF-8 charset.
        Parameters:
        stream - the source stream
        Returns:
        the model node
        Throws:
        IOException
      • fromJSONStream

        public static ModelNode fromJSONStream​(InputStream stream)
                                        throws IOException
        Get a model node from a JSON text representation of the model node. The stream should be encoded in UTF-8.
        Parameters:
        stream - the source stream
        Returns:
        the model node
        Throws:
        IOException
      • resolve

        public ModelNode resolve()
        Return a copy of this model node, with all values of type ModelType.EXPRESSION locally resolved. The caller must have permission to access all of the system properties named in the node tree. If an expression begins with {@code ${env.} then a system property named {@code env.@lt;remainder of expression@gt;} will be checked, and if not present a {@link System#getenv(String) system environment variable named @lt;remainder of expression@gt;} will be checked. In that case the caller must have permission to access the environment variable.
        Returns:
        the resolved copy
        Throws:
        IllegalStateException - if there is a value of type ModelType.EXPRESSION in the node tree and there is no system property or environment variable that matches the expression
        SecurityException - if a security manager exists and its checkPermission method doesn't allow access to the relevant system property or environment variable
      • equals

        public boolean equals​(Object other)
        Determine whether this object is equal to another.
        Overrides:
        equals in class Object
        Parameters:
        other - the other object
        Returns:
        true if they are equal, false otherwise
      • equals

        public boolean equals​(ModelNode other)
        Determine whether this object is equal to another.
        Parameters:
        other - the other object
        Returns:
        true if they are equal, false otherwise
      • hashCode

        public int hashCode()
        Get the hash code of this node object. Note that unless the value is protect()ed, the hash code may change over time, thus making unprotected nodes unsuitable for use as hash table keys.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • clone

        public ModelNode clone()
        Clone this model node.
        Overrides:
        clone in class Object
        Returns:
        the clone
      • getType

        public ModelType getType()
        Get the current type of this node.
        Returns:
        the node type
      • writeExternal

        public void writeExternal​(ObjectOutput out)
                           throws IOException
        Write this node's content in binary format to the given target.
        Specified by:
        writeExternal in interface Externalizable
        Parameters:
        out - the target to which the content should be written
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(OutputStream out)
                           throws IOException
        Write this node's content in binary format to the given target.
        Parameters:
        out - the target to which the content should be written
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(DataOutputStream out)
                           throws IOException
        Write this node's content in binary format to the given target.
        Parameters:
        out - the target to which the content should be written
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(DataOutput out)
                           throws IOException
        Write this node's content in binary format to the given target.
        Parameters:
        out - the target to which the content should be written
        Throws:
        IOException - if an I/O error occurs
      • readExternal

        public void readExternal​(ObjectInput in)
                          throws IOException
        Read this node's content in binary format from the given source.
        Specified by:
        readExternal in interface Externalizable
        Parameters:
        in - the source from which the content should be read
        Throws:
        IOException - if an I/O error occurs
      • readExternal

        public void readExternal​(DataInputStream in)
                          throws IOException
        Read this node's content in binary format from the given source.
        Parameters:
        in - the source from which the content should be read
        Throws:
        IOException - if an I/O error occurs
      • readExternal

        public void readExternal​(InputStream in)
                          throws IOException
        Read this node's content in binary format from the given source.
        Parameters:
        in - the source from which the content should be read
        Throws:
        IOException - if an I/O error occurs
      • readExternal

        public void readExternal​(DataInput in)
                          throws IOException
        Read this node's content in binary format from the given source.
        Parameters:
        in - the source from which the content should be read
        Throws:
        IOException - if an I/O error occurs
      • writeBase64

        public void writeBase64​(OutputStream stream)
                         throws IOException
        Encodes the serialized representation in base64 form and writes it to the specified output stream.
        Parameters:
        stream - the stream to write to
        Throws:
        IOException - if the specified stream has an issue