public class ModelNode extends Object implements Externalizable, Cloneable
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.
Type | Property and Description |
---|---|
Property |
as
Get the value of this node as a property.
|
Constructor and Description |
---|
ModelNode()
Creates a new
ModelNode with an undefined value. |
ModelNode(BigDecimal value)
Creates a new
ModelNode with the given value . |
ModelNode(BigInteger value)
Creates a new
ModelNode with the given value . |
ModelNode(boolean value)
Creates a new
ModelNode with the given value . |
ModelNode(byte[] value)
Creates a new
ModelNode with the given value . |
ModelNode(double value)
Creates a new
ModelNode with the given value . |
ModelNode(int value)
Creates a new
ModelNode with the given value . |
ModelNode(long value)
Creates a new
ModelNode with the given value . |
ModelNode(ModelType value)
Creates a new
ModelNode with the given value . |
ModelNode(String value)
Creates a new
ModelNode with the given value . |
ModelNode(ValueExpression value)
Creates a new
ModelNode with the given value . |
Modifier and Type | Method and Description |
---|---|
ModelNode |
add()
Add a node to the end of this node's value list and return it.
|
ModelNode |
add(BigDecimal newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(BigInteger newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(boolean newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(byte[] newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(double newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(int newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(long newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(ModelNode newValue)
Add a copy of the given value to the end of this node's value list.
|
ModelNode |
add(Property property)
Add a property to the end of this node's value list.
|
ModelNode |
add(String newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
BigDecimal propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
BigInteger propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
boolean propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
byte[] propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
double propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
int propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
long propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
ModelNode propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
String propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(String propertyName,
ValueExpression propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(ValueExpression newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
addEmptyList()
Add a node of type
ModelType.LIST to the end of this node's value list and return it. |
ModelNode |
addEmptyObject()
Add a node of type
ModelType.OBJECT to the end of this node's value list and return it. |
ModelNode |
addExpression(String newValue)
Deprecated.
Use
add(ValueExpression) instead. |
BigDecimal |
asBigDecimal()
Get the value of this node as a
BigDecimal . |
BigDecimal |
asBigDecimalOrNull()
|
BigInteger |
asBigInteger()
Get the value of this node as a
BigInteger . |
BigInteger |
asBigIntegerOrNull()
|
boolean |
asBoolean()
Get the value of this node as a
boolean . |
boolean |
asBoolean(boolean defVal)
Get the value of this node as a
boolean . |
Boolean |
asBooleanOrNull()
|
byte[] |
asBytes()
Get the value of this node as a byte array.
|
byte[] |
asBytesOrNull()
Get the value of this node as a byte array or
null if this node is not defined . |
double |
asDouble()
Get the value of this node as a
double . |
double |
asDouble(double defVal)
Get the value of this node as an
double . |
Double |
asDoubleOrNull()
|
ValueExpression |
asExpression()
Get the value of this node as an expression.
|
int |
asInt()
Get the value of this node as an
int . |
int |
asInt(int defVal)
Get the value of this node as an
int . |
Integer |
asIntOrNull()
|
List<ModelNode> |
asList()
Get the list of entries contained in this object.
|
long |
asLong()
Get the value of this node as a
long . |
long |
asLong(long defVal)
Get the value of this node as a
long . |
Long |
asLongOrNull()
|
ModelNode |
asObject()
Get a copy of this value as an object.
|
Property |
asProperty()
Get the value of this node as a property.
|
List<Property> |
asPropertyList()
Get the value of this node as a property list.
|
String |
asString()
Get the value as a string.
|
String |
asString(String defVal)
Get the value as a string.
|
String |
asStringOrNull()
Get the value as a string or
null if this node is not defined . |
ModelType |
asType()
Get the value of this node as a type, expressed using the
ModelType enum. |
ModelNode |
clear()
Clear this node's value and change its type to
ModelType.UNDEFINED . |
ModelNode |
clone()
Clone this model node.
|
boolean |
equals(ModelNode other)
Determine whether this object is equal to another.
|
boolean |
equals(Object other)
Determine whether this object is equal to another.
|
static ModelNode |
fromBase64(InputStream stream)
Reads base64 data from the passed stream,
and deserializes the decoded result.
|
static ModelNode |
fromBase64String(String encoded)
Reads base64 data from the passed string,
and deserializes the decoded result.
|
static ModelNode |
fromJSONStream(InputStream stream)
Get a model node from a JSON text representation of the model node.
|
static ModelNode |
fromJSONString(String input) |
static ModelNode |
fromStream(InputStream stream)
Get a model node from a text representation of the model node.
|
static ModelNode |
fromString(String input)
Get a model node from a string representation of the model node.
|
ModelNode |
get(int index)
Get the child of this node with the given index.
|
ModelNode |
get(String... names)
Recursively get the children of this node with the given names.
|
ModelNode |
get(String name)
Get the child of this node with the given name.
|
ModelType |
getType()
Get the current type of this node.
|
boolean |
has(int index)
Determine whether this node has a child with the given index.
|
boolean |
has(String... names)
Recursively determine whether this node has children with the given names.
|
boolean |
has(String key)
Determine whether this node has a child with the given name.
|
boolean |
hasDefined(int index)
Determine whether this node has a defined child with the given index.
|
boolean |
hasDefined(String... names)
Recursively determine whether this node has defined children with the given names.
|
boolean |
hasDefined(String key)
Determine whether this node has a defined child with the given name.
|
int |
hashCode()
Get the hash code of this node object.
|
ModelNode |
insert(int index)
Insert a node at provided index of this node's value list and return it.
|
ModelNode |
insert(ModelNode newValue,
int index)
insert copy of the given value to provided index of this node's value list.
|
boolean |
isDefined()
Determine whether this node is defined.
|
Set<String> |
keys()
Get the set of keys contained in this object.
|
void |
protect()
Prevent further modifications to this node and its sub-nodes.
|
void |
readExternal(DataInput in)
Read this node's content in binary format from the given source.
|
void |
readExternal(DataInputStream in)
Read this node's content in binary format from the given source.
|
void |
readExternal(InputStream in)
Read this node's content in binary format from the given source.
|
void |
readExternal(ObjectInput in)
Read this node's content in binary format from the given source.
|
ModelNode |
remove(int index)
Remove a child of this list, returning the child.
|
ModelNode |
remove(String name)
Remove a child of this node, returning the child.
|
ModelNode |
require(int index)
Require the existence of a child of this node with the given index, returning the child.
|
ModelNode |
require(String name)
Require the existence of a child of this node with the given name, returning the child.
|
ModelNode |
resolve()
Return a copy of this model node, with all values of type
ModelType.EXPRESSION locally resolved. |
ModelNode |
set(BigDecimal newValue)
Change this node's value to the given value.
|
ModelNode |
set(BigInteger newValue)
Change this node's value to the given value.
|
ModelNode |
set(boolean newValue)
Change this node's value to the given value.
|
ModelNode |
set(byte[] newValue)
Change this node's value to the given value.
|
ModelNode |
set(Collection<ModelNode> newValue)
Change this node's value to a list whose values are copied from the given collection.
|
ModelNode |
set(double newValue)
Change this node's value to the given value.
|
ModelNode |
set(int newValue)
Change this node's value to the given value.
|
ModelNode |
set(long newValue)
Change this node's value to the given value.
|
ModelNode |
set(ModelNode newValue)
Change this node's value to the given value.
|
ModelNode |
set(ModelType newValue)
Change this node's value to the given value.
|
ModelNode |
set(Property newValue)
Change this node's value to the given value.
|
ModelNode |
set(String newValue)
Change this node's value to the given value.
|
ModelNode |
set(String propertyName,
BigDecimal propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
BigInteger propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
boolean propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
byte[] propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
double propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
int propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
long propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
ModelNode propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
ModelType propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
String propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(String propertyName,
ValueExpression propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(ValueExpression newValue)
Change this node's value to the given value.
|
ModelNode |
setEmptyList()
Change this node's value to an empty list.
|
ModelNode |
setEmptyObject()
Change this node's value to an empty object.
|
ModelNode |
setExpression(String newValue)
Deprecated.
Use
set(ValueExpression) instead. |
ModelNode |
setExpression(String propertyName,
String propertyValue)
Deprecated.
Use
set(String,ValueExpression) instead. |
String |
toJSONString(boolean compact)
Get a JSON string representation of this model node, formatted nicely, if requested.
|
String |
toString()
Get a human-readable string representation of this model node, formatted nicely (possibly on multiple lines).
|
void |
writeBase64(OutputStream stream)
Encodes the serialized representation in base64 form
and writes it to the specified output stream.
|
void |
writeExternal(DataOutput out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(DataOutputStream out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(ObjectOutput out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(OutputStream out)
Write this node's content in binary format to the given target.
|
void |
writeJSONString(PrintWriter writer,
boolean compact)
Output the JSON string representation of this model node, formatted nicely, if requested to the supplied PrintWriter
instance.
|
void |
writeString(PrintWriter writer,
boolean compact)
Output the DMR string representation of this model node, formatted nicely, if requested to the supplied PrintWriter
instance.
|
public Property asProperty
IllegalArgumentException
public ModelNode()
ModelNode
with an undefined value.public ModelNode(BigDecimal value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public ModelNode(BigInteger value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public ModelNode(boolean value)
ModelNode
with the given value
.value
- the value.public ModelNode(byte[] value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public ModelNode(double value)
ModelNode
with the given value
.value
- the value.public ModelNode(int value)
ModelNode
with the given value
.value
- the value.public ModelNode(long value)
ModelNode
with the given value
.value
- the value.public ModelNode(String value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public ModelNode(ValueExpression value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public ModelNode(ModelType value)
ModelNode
with the given value
.value
- the value. Cannot be null
IllegalArgumentException
- if value
is null
public void protect()
public long asLong() throws IllegalArgumentException
long
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic long asLong(long defVal)
long
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.defVal
- the default value to return if this node is not defined
NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possibleIllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic Long asLongOrNull()
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.null
NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possibleIllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic int asInt() throws IllegalArgumentException
int
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic int asInt(int defVal)
int
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.defVal
- the default value to return if this node is not defined
NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possibleIllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic Integer asIntOrNull()
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.null
IllegalArgumentException
- if no conversion is possiblepublic boolean asBoolean() throws IllegalArgumentException
boolean
. Collection types return true
for non-empty
collections. Numerical types return true
for non-zero values.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic boolean asBoolean(boolean defVal)
boolean
. Collection types return true
for non-empty
collections. Numerical types return true
for non-zero values.defVal
- the default value to return if this node is not defined
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
public Boolean asBooleanOrNull() throws IllegalArgumentException
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.null
IllegalArgumentException
- if no conversion is possiblepublic String asString()
defined
returns the literal string undefined
public String asString(String defVal)
defVal
- the default value to return if this node is not defined
public String asStringOrNull()
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.null
public double asDouble() throws IllegalArgumentException
double
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic double asDouble(double defVal)
double
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.defVal
- the default value to return if this node is not defined
NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possibleIllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic Double asDoubleOrNull() throws IllegalArgumentException
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.null
IllegalArgumentException
- if no conversion is possiblepublic ModelType asType() throws IllegalArgumentException
ModelType
enum. The string
value of this node must be convertible to a type.ModelType
valueIllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic BigDecimal asBigDecimal() throws IllegalArgumentException
BigDecimal
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.BigDecimal
valueIllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic BigDecimal asBigDecimalOrNull() throws IllegalArgumentException
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.BigDecimal
value or null
IllegalArgumentException
- if no conversion is possiblepublic BigInteger asBigInteger() throws IllegalArgumentException
BigInteger
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.BigInteger
valueIllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic BigInteger asBigIntegerOrNull() throws IllegalArgumentException
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.BigInteger
value or null
IllegalArgumentException
- if no conversion is possiblepublic byte[] asBytes() throws IllegalArgumentException
IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic byte[] asBytesOrNull() throws IllegalArgumentException
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.null
IllegalArgumentException
- if no conversion is possiblepublic ValueExpression asExpression() throws IllegalArgumentException
IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic Property asProperty() throws IllegalArgumentException
IllegalArgumentException
public List<Property> asPropertyList() throws IllegalArgumentException
IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic ModelNode asObject() throws IllegalArgumentException
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.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic boolean isDefined()
getType() != ModelType.UNDEFINED
.true
if this node's value is definedpublic ModelNode set(int newValue)
newValue
- the new valuepublic ModelNode set(long newValue)
newValue
- the new valuepublic ModelNode set(double newValue)
newValue
- the new valuepublic ModelNode set(boolean newValue)
newValue
- the new value@Deprecated public ModelNode setExpression(String newValue)
set(ValueExpression)
instead.newValue
- the new valuepublic ModelNode set(ValueExpression newValue)
newValue
- the new valuepublic ModelNode set(String newValue)
newValue
- the new valuepublic ModelNode set(BigDecimal newValue)
newValue
- the new valuepublic ModelNode set(BigInteger newValue)
newValue
- the new valuepublic ModelNode set(ModelNode newValue)
newValue
- the new valuepublic ModelNode set(byte[] newValue)
newValue
- the new valuepublic ModelNode set(ModelType newValue)
newValue
- the new valuepublic ModelNode set(Property newValue)
newValue
- the new valuepublic ModelNode set(String propertyName, ModelNode propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, int propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, long propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, double propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, boolean propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, String propertyValue)
propertyName
- the property namepropertyValue
- the property value@Deprecated public ModelNode setExpression(String propertyName, String propertyValue)
set(String,ValueExpression)
instead.propertyName
- the property namepropertyValue
- the property expression valuepublic ModelNode set(String propertyName, ValueExpression propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, BigDecimal propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, BigInteger propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, byte[] propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(String propertyName, ModelType propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(Collection<ModelNode> newValue)
newValue
- the list valuepublic ModelNode setEmptyList()
public ModelNode setEmptyObject()
public ModelNode clear()
ModelType.UNDEFINED
.public ModelNode get(String name)
ModelType.OBJECT
.
When called on property values, the name must match the property name.
name
- the child nameIllegalArgumentException
- if this node does not support getting a child with the given namepublic ModelNode require(String name) throws NoSuchElementException
When called on property values, the name must match the property name.
name
- the child nameNoSuchElementException
- if the element does not existpublic ModelNode remove(String name) throws NoSuchElementException
null
is returned.
When called on property values, the name must match the property name.
name
- the child namenull
if no child with the given name
existsNoSuchElementException
public ModelNode remove(int index) throws NoSuchElementException
When called on property values, the name must match the property name.
index
- the child indexNoSuchElementException
- if the element does not existpublic ModelNode get(int index)
ModelType.LIST
.
When called on property values, the index must be zero.
index
- the child indexIllegalArgumentException
- if this node does not support getting a child with the given indexpublic ModelNode require(int index)
When called on property values, the index must be zero.
index
- the child indexNoSuchElementException
- if the element does not existpublic ModelNode add(int newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(long newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(double newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(boolean newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
@Deprecated public ModelNode addExpression(String newValue)
add(ValueExpression)
instead.ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(ValueExpression newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(BigDecimal newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(BigInteger newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(ModelNode newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode insert(ModelNode newValue, int index)
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.)newValue
- the new value to addIndexOutOfBoundsException
- if index
is greater than zero and is greater than the number of child nodes currently stored in this nodeIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(byte[] newValue)
ModelType.LIST
.newValue
- the new value to addIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(Property property)
ModelType.LIST
.property
- the propertyIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, int propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, long propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, double propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, boolean propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, ValueExpression propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, String propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, BigDecimal propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, BigInteger propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, ModelNode propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(String propertyName, byte[] propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valueIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add()
ModelType.LIST
.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode insert(int index)
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.)index
- where in list to put itIndexOutOfBoundsException
- if index
is greater than zero and is greater than the number of child nodes currently stored in this nodeIllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode addEmptyList()
ModelType.LIST
to the end of this node's value list and return it. If this node is
undefined, it will be initialized to be of type ModelType.LIST
.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode addEmptyObject()
ModelType.OBJECT
to the end of this node's value list and return it. If this node is
undefined, it will be initialized to be of type ModelType.LIST
.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public boolean has(int index)
index
- the indextrue
if there is a (possibly undefined) node at the given indexpublic boolean has(String key)
key
- the nametrue
if there is a (possibly undefined) node at the given keypublic boolean has(String... names)
false
.names
- the child namestrue
if a call to get(String...)
with the given names
would succeed without
needing to create any new nodes; false
otherwisepublic boolean hasDefined(int index)
index
- the indextrue
if there is a node at the given index and its type
is not ModelType.UNDEFINED
public boolean hasDefined(String key)
key
- the nametrue
if there is a node at the given index and its type
is not ModelType.UNDEFINED
public boolean hasDefined(String... names)
false
.names
- the child namestrue
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
otherwisepublic Set<String> keys()
IllegalArgumentException
- if this node's type
is not ModelType.OBJECT
or ModelType.PROPERTY
public List<ModelNode> asList()
isDefined()
types will return an empty list.IllegalArgumentException
- if this node is not defined
public ModelNode get(String... names)
ModelType.OBJECT
.names
- the child namesIllegalArgumentException
- if a node does not support getting a child with the given name pathpublic String toString()
public void writeString(PrintWriter writer, boolean compact)
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
).public String toJSONString(boolean compact)
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
).public void writeJSONString(PrintWriter writer, boolean compact)
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
).public static ModelNode fromString(String input)
input
- the input stringpublic static ModelNode fromStream(InputStream stream) throws IOException
stream
- the source streamIOException
public static ModelNode fromJSONStream(InputStream stream) throws IOException
stream
- the source streamIOException
public static ModelNode fromBase64(InputStream stream) throws IOException
IOException
- if the passed stream has an issuewriteBase64(OutputStream)
public static ModelNode fromBase64String(String encoded) throws IOException
IOException
- if the passed stream has an issuewriteBase64(OutputStream)
public ModelNode resolve()
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 ${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.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 expressionSecurityException
- if a security manager exists and its
checkPermission
method doesn't allow access to the relevant system property or environment variablepublic boolean equals(Object other)
public boolean equals(ModelNode other)
other
- the other objecttrue
if they are equal, false
otherwisepublic int hashCode()
protect()
ed, the hash code may
change over time, thus making unprotected nodes unsuitable for use as hash table keys.public ModelNode clone()
public ModelType getType()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
out
- the target to which the content should be writtenIOException
- if an I/O error occurspublic void writeExternal(OutputStream out) throws IOException
out
- the target to which the content should be writtenIOException
- if an I/O error occurspublic void writeExternal(DataOutputStream out) throws IOException
out
- the target to which the content should be writtenIOException
- if an I/O error occurspublic void writeExternal(DataOutput out) throws IOException
out
- the target to which the content should be writtenIOException
- if an I/O error occurspublic void readExternal(ObjectInput in) throws IOException
readExternal
in interface Externalizable
in
- the source from which the content should be readIOException
- if an I/O error occurspublic void readExternal(DataInputStream in) throws IOException
in
- the source from which the content should be readIOException
- if an I/O error occurspublic void readExternal(InputStream in) throws IOException
in
- the source from which the content should be readIOException
- if an I/O error occurspublic void readExternal(DataInput in) throws IOException
in
- the source from which the content should be readIOException
- if an I/O error occurspublic void writeBase64(OutputStream stream) throws IOException
stream
- the stream to write toIOException
- if the specified stream has an issueCopyright © 2017 JBoss by Red Hat. All rights reserved.