public class ModelNode
extends java.lang.Object
implements java.io.Externalizable, java.lang.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.
Modifier and Type | Field and Description |
---|---|
static ModelNode |
FALSE
|
static ModelNode |
TRUE
|
static ModelNode |
ZERO
|
static ModelNode |
ZERO_LONG
|
Constructor and Description |
---|
ModelNode()
Creates a new
ModelNode with an undefined value. |
ModelNode(java.math.BigDecimal value)
Creates a new
ModelNode with the given value . |
ModelNode(java.math.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(java.lang.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(java.math.BigDecimal newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(java.math.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(java.lang.String newValue)
Add the given value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
java.math.BigDecimal propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
java.math.BigInteger propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
boolean propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
byte[] propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
double propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
int propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
long propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
ModelNode propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.String propertyName,
java.lang.String propertyValue)
Add a property with the given name and value to the end of this node's value list.
|
ModelNode |
add(java.lang.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(java.lang.String newValue)
Deprecated.
Use
add(ValueExpression) instead. |
java.math.BigDecimal |
asBigDecimal()
Get the value of this node as a
BigDecimal . |
java.math.BigDecimal |
asBigDecimalOrNull()
|
java.math.BigInteger |
asBigInteger()
Get the value of this node as a
BigInteger . |
java.math.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 . |
java.lang.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 . |
java.lang.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 . |
java.lang.Integer |
asIntOrNull()
|
java.util.List<ModelNode> |
asList()
Get the list of entries contained in this object.
|
java.util.List<ModelNode> |
asList(java.util.List<ModelNode> defVal)
|
java.util.List<ModelNode> |
asListOrEmpty()
|
long |
asLong()
Get the value of this node as a
long . |
long |
asLong(long defVal)
Get the value of this node as a
long . |
java.lang.Long |
asLongOrNull()
|
ModelNode |
asObject()
Get a copy of this value as an object.
|
Property |
asProperty()
Get the value of this node as a property.
|
java.util.List<Property> |
asPropertyList()
Get the value of this node as a property list.
|
java.lang.String |
asString()
Get the value as a string.
|
java.lang.String |
asString(java.lang.String defVal)
Get the value as a string.
|
java.lang.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(java.lang.Object other)
Determine whether this object is equal to another.
|
static ModelNode |
fromBase64(java.io.InputStream stream)
Reads base64 data from the passed stream,
and deserializes the decoded result.
|
static ModelNode |
fromBase64String(java.lang.String encoded)
Reads base64 data from the passed string,
and deserializes the decoded result.
|
static ModelNode |
fromJSONStream(java.io.InputStream stream)
Get a model node from a JSON text representation of the model node.
|
static ModelNode |
fromJSONString(java.lang.String input) |
static ModelNode |
fromStream(java.io.InputStream stream)
Get a model node from a text representation of the model node.
|
static ModelNode |
fromString(java.lang.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(java.lang.String... names)
Recursively get the children of this node with the given names.
|
ModelNode |
get(java.lang.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(java.lang.String... names)
Recursively determine whether this node has children with the given names.
|
boolean |
has(java.lang.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(java.lang.String... names)
Recursively determine whether this node has defined children with the given names.
|
boolean |
hasDefined(java.lang.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.
|
boolean |
isProtected()
Returns whether this node has been
protected . |
java.util.Set<java.lang.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(java.io.DataInput in)
Read this node's content in binary format from the given source.
|
void |
readExternal(java.io.DataInputStream in)
Read this node's content in binary format from the given source.
|
void |
readExternal(java.io.InputStream in)
Read this node's content in binary format from the given source.
|
void |
readExternal(java.io.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(java.lang.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(java.lang.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(java.math.BigDecimal newValue)
Change this node's value to the given value.
|
ModelNode |
set(java.math.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(java.util.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(java.lang.String newValue)
Change this node's value to the given value.
|
ModelNode |
set(java.lang.String propertyName,
java.math.BigDecimal propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
java.math.BigInteger propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
boolean propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
byte[] propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
double propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
int propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
long propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
ModelNode propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
ModelType propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.String propertyName,
java.lang.String propertyValue)
Change this node's value to a property with the given name and value.
|
ModelNode |
set(java.lang.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(java.lang.String newValue)
Deprecated.
Use
set(ValueExpression) instead. |
ModelNode |
setExpression(java.lang.String propertyName,
java.lang.String propertyValue)
Deprecated.
Use
set(String,ValueExpression) instead. |
java.lang.String |
toJSONString(boolean compact)
Get a JSON string representation of this model node, formatted nicely, if requested.
|
java.lang.String |
toString()
Get a human-readable string representation of this model node, formatted nicely (possibly on multiple lines).
|
void |
writeBase64(java.io.OutputStream stream)
Encodes the serialized representation in base64 form
and writes it to the specified output stream.
|
void |
writeExternal(java.io.DataOutput out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(java.io.DataOutputStream out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(java.io.ObjectOutput out)
Write this node's content in binary format to the given target.
|
void |
writeExternal(java.io.OutputStream out)
Write this node's content in binary format to the given target.
|
void |
writeJSONString(java.io.PrintWriter writer,
boolean compact)
Output the JSON string representation of this model node, formatted nicely, if requested to the supplied PrintWriter
instance.
|
void |
writeString(java.io.PrintWriter writer,
boolean compact)
Output the DMR string representation of this model node, formatted nicely, if requested to the supplied PrintWriter
instance.
|
public static final ModelNode TRUE
public static final ModelNode FALSE
public static final ModelNode ZERO
public static final ModelNode ZERO_LONG
public ModelNode()
ModelNode
with an undefined value.public ModelNode(java.math.BigDecimal value)
ModelNode
with the given value
.value
- the value. Cannot be null
java.lang.IllegalArgumentException
- if value
is null
public ModelNode(java.math.BigInteger value)
ModelNode
with the given value
.value
- the value. Cannot be null
java.lang.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
java.lang.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(java.lang.String value)
ModelNode
with the given value
.value
- the value. Cannot be null
java.lang.IllegalArgumentException
- if value
is null
public ModelNode(ValueExpression value)
ModelNode
with the given value
.value
- the value. Cannot be null
java.lang.IllegalArgumentException
- if value
is null
public ModelNode(ModelType value)
ModelNode
with the given value
.value
- the value. Cannot be null
java.lang.IllegalArgumentException
- if value
is null
public void protect()
public boolean isProtected()
protected
.true
if protect()
has been invoked on this nodepublic long asLong() throws java.lang.IllegalArgumentException
long
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.java.lang.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
java.lang.NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possiblejava.lang.IllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic java.lang.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
java.lang.NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possiblejava.lang.IllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic int asInt() throws java.lang.IllegalArgumentException
int
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.java.lang.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
java.lang.NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possiblejava.lang.IllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic boolean asBoolean() throws java.lang.IllegalArgumentException
boolean
. Collection types return true
for non-empty
collections. Numerical types return true
for non-zero values.java.lang.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
java.lang.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 java.lang.Boolean asBooleanOrNull() throws java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic java.lang.String asString()
defined
returns the literal string undefined
public java.lang.String asString(java.lang.String defVal)
defVal
- the default value to return if this node is not defined
public java.lang.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 java.lang.IllegalArgumentException
double
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.java.lang.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
java.lang.NumberFormatException
- if this node's type
is ModelType.STRING
and a numeric conversion of the string value is not possiblejava.lang.IllegalArgumentException
- if this node's type
is one where no numeric conversion is possiblepublic java.lang.Double asDoubleOrNull() throws java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic ModelType asType() throws java.lang.IllegalArgumentException
ModelType
enum. The string
value of this node must be convertible to a type.ModelType
valuejava.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic java.math.BigDecimal asBigDecimal() throws java.lang.IllegalArgumentException
BigDecimal
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.BigDecimal
valuejava.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic java.math.BigDecimal asBigDecimalOrNull() throws java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic java.math.BigInteger asBigInteger() throws java.lang.IllegalArgumentException
BigInteger
. Collection types will return the size
of the collection for this value. Other types may attempt a string conversion.BigInteger
valuejava.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic java.math.BigInteger asBigIntegerOrNull() throws java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic byte[] asBytes() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic byte[] asBytesOrNull() throws java.lang.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
java.lang.IllegalArgumentException
- if no conversion is possiblepublic ValueExpression asExpression() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic Property asProperty() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic java.util.List<Property> asPropertyList() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if this node is not defined
or if no conversion is possiblepublic ModelNode asObject() throws java.lang.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.java.lang.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(java.lang.String newValue)
set(ValueExpression)
instead.newValue
- the new valuepublic ModelNode set(ValueExpression newValue)
newValue
- the new valuepublic ModelNode set(java.lang.String newValue)
newValue
- the new valuepublic ModelNode set(java.math.BigDecimal newValue)
newValue
- the new valuepublic ModelNode set(java.math.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(java.lang.String propertyName, ModelNode propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, int propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, long propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, double propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, boolean propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, java.lang.String propertyValue)
propertyName
- the property namepropertyValue
- the property value@Deprecated public ModelNode setExpression(java.lang.String propertyName, java.lang.String propertyValue)
set(String,ValueExpression)
instead.propertyName
- the property namepropertyValue
- the property expression valuepublic ModelNode set(java.lang.String propertyName, ValueExpression propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, java.math.BigDecimal propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, java.math.BigInteger propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, byte[] propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.lang.String propertyName, ModelType propertyValue)
propertyName
- the property namepropertyValue
- the property valuepublic ModelNode set(java.util.Collection<ModelNode> newValue)
newValue
- the list valuepublic ModelNode setEmptyList()
public ModelNode setEmptyObject()
public ModelNode clear()
ModelType.UNDEFINED
.public ModelNode get(java.lang.String name)
ModelType.OBJECT
.
When called on property values, the name must match the property name.
name
- the child namejava.lang.IllegalArgumentException
- if this node does not support getting a child with the given namepublic ModelNode require(java.lang.String name) throws java.util.NoSuchElementException
When called on property values, the name must match the property name.
name
- the child namejava.util.NoSuchElementException
- if the element does not existpublic ModelNode remove(java.lang.String name) throws java.util.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
existsjava.util.NoSuchElementException
public ModelNode remove(int index) throws java.util.NoSuchElementException
When called on property values, the name must match the property name.
index
- the child indexjava.util.NoSuchElementException
- 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 indexjava.lang.IllegalArgumentException
- 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 indexjava.util.NoSuchElementException
- if the element does not existpublic ModelNode add(int newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(long newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(double newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(boolean newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
@Deprecated public ModelNode addExpression(java.lang.String newValue)
add(ValueExpression)
instead.ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(ValueExpression newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.math.BigDecimal newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.math.BigInteger newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(ModelNode newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- 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 addjava.lang.IndexOutOfBoundsException
- if index
is greater than zero and is greater than the number of child nodes currently stored in this nodejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(byte[] newValue)
ModelType.LIST
.newValue
- the new value to addjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(Property property)
ModelType.LIST
.property
- the propertyjava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, int propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, long propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, double propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, boolean propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, ValueExpression propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, java.lang.String propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, java.math.BigDecimal propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, java.math.BigInteger propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, ModelNode propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add(java.lang.String propertyName, byte[] propertyValue)
ModelType.LIST
.propertyName
- the property namepropertyValue
- the property valuejava.lang.IllegalArgumentException
- if this node is defined
and its type
is not ModelType.LIST
public ModelNode add()
ModelType.LIST
.java.lang.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 itjava.lang.IndexOutOfBoundsException
- if index
is greater than zero and is greater than the number of child nodes currently stored in this nodejava.lang.IllegalArgumentException
- 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
.java.lang.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
.java.lang.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(java.lang.String key)
key
- the nametrue
if there is a (possibly undefined) node at the given keypublic boolean has(java.lang.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(java.lang.String key)
key
- the nametrue
if there is a node at the given index and its type
is not ModelType.UNDEFINED
public boolean hasDefined(java.lang.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 java.util.Set<java.lang.String> keys()
java.lang.IllegalArgumentException
- if this node's type
is not ModelType.OBJECT
or ModelType.PROPERTY
public java.util.List<ModelNode> asList()
isDefined()
types will return an empty list.java.lang.IllegalArgumentException
- if this node is not defined
public java.util.List<ModelNode> asList(java.util.List<ModelNode> defVal)
defVal
- the default value to return if this node is not definedpublic java.util.List<ModelNode> asListOrEmpty()
null
)public ModelNode get(java.lang.String... names)
ModelType.OBJECT
.names
- the child namesjava.lang.IllegalArgumentException
- if a node does not support getting a child with the given name pathpublic java.lang.String toString()
toString
in class java.lang.Object
public void writeString(java.io.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 java.lang.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(java.io.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(java.lang.String input)
input
- the input stringpublic static ModelNode fromJSONString(java.lang.String input)
public static ModelNode fromStream(java.io.InputStream stream) throws java.io.IOException
stream
- the source streamjava.io.IOException
public static ModelNode fromJSONStream(java.io.InputStream stream) throws java.io.IOException
stream
- the source streamjava.io.IOException
public static ModelNode fromBase64(java.io.InputStream stream) throws java.io.IOException
java.io.IOException
- if the passed stream has an issuewriteBase64(OutputStream)
public static ModelNode fromBase64String(java.lang.String encoded) throws java.io.IOException
java.io.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.java.lang.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 expressionjava.lang.SecurityException
- if a security manager exists and its
checkPermission
method doesn't allow access to the relevant system property or environment variablepublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other objecttrue
if they are equal, false
otherwisepublic 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.hashCode
in class java.lang.Object
public ModelNode clone()
clone
in class java.lang.Object
public ModelType getType()
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- the target to which the content should be writtenjava.io.IOException
- if an I/O error occurspublic void writeExternal(java.io.OutputStream out) throws java.io.IOException
out
- the target to which the content should be writtenjava.io.IOException
- if an I/O error occurspublic void writeExternal(java.io.DataOutputStream out) throws java.io.IOException
out
- the target to which the content should be writtenjava.io.IOException
- if an I/O error occurspublic void writeExternal(java.io.DataOutput out) throws java.io.IOException
out
- the target to which the content should be writtenjava.io.IOException
- if an I/O error occurspublic void readExternal(java.io.ObjectInput in) throws java.io.IOException
readExternal
in interface java.io.Externalizable
in
- the source from which the content should be readjava.io.IOException
- if an I/O error occurspublic void readExternal(java.io.DataInputStream in) throws java.io.IOException
in
- the source from which the content should be readjava.io.IOException
- if an I/O error occurspublic void readExternal(java.io.InputStream in) throws java.io.IOException
in
- the source from which the content should be readjava.io.IOException
- if an I/O error occurspublic void readExternal(java.io.DataInput in) throws java.io.IOException
in
- the source from which the content should be readjava.io.IOException
- if an I/O error occurspublic void writeBase64(java.io.OutputStream stream) throws java.io.IOException
stream
- the stream to write tojava.io.IOException
- if the specified stream has an issueCopyright © 2013 JBoss, a division of Red Hat, Inc.