|
JBoss Dynamic Model Representation API 1.0.0.Final | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.dmr.ModelNode
public class ModelNode
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.
Constructor Summary | |
---|---|
ModelNode()
|
Method Summary | |
---|---|
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(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 |
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)
Add the given expression to the end of this node's value list. |
java.math.BigDecimal |
asBigDecimal()
Get the value of this node as a BigDecimal . |
java.math.BigInteger |
asBigInteger()
Get the value of this node as a BigInteger . |
boolean |
asBoolean()
Get the value of this node as a boolean . |
boolean |
asBoolean(boolean defVal)
Get the value of this node as a boolean . |
byte[] |
asBytes()
Get the value of this node as a byte array. |
double |
asDouble()
Get the value of this node as a double . |
double |
asDouble(double defVal)
Get the value of this node as an double . |
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.util.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 . |
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. |
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 |
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 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 key)
Determine whether this node has a defined child with the given name. |
int |
hashCode()
Get the hash code of this node object. |
boolean |
isDefined()
Determine whether this node is defined. |
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(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 system property expressions 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 |
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)
Change this node's value to the given expression value. |
ModelNode |
setExpression(java.lang.String propertyName,
java.lang.String propertyValue)
Change this node's value to a property with the given name and expression value. |
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. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ModelNode()
Method Detail |
---|
public void protect()
public 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 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 if no conversion is possible
public 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 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 if no conversion is possible
public 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 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 if no conversion is possible
public java.lang.String asString()
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 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 if no conversion is possible
public ModelType asType() throws java.lang.IllegalArgumentException
ModelType
enum. The string
value of this node must be convertible to a type.
ModelType
value
java.lang.IllegalArgumentException
- 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
value
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
value
java.lang.IllegalArgumentException
- if no conversion is possiblepublic byte[] asBytes() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if no conversion is possiblepublic Property asProperty() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if no conversion is possiblepublic java.util.List<Property> asPropertyList() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- 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 no conversion is possiblepublic boolean isDefined()
getType() != ModelType.UNDEFINED
.
true
if this node's value is definedpublic ModelNode set(int newValue)
newValue
- the new value
public ModelNode set(long newValue)
newValue
- the new value
public ModelNode set(double newValue)
newValue
- the new value
public ModelNode set(boolean newValue)
newValue
- the new value
public ModelNode setExpression(java.lang.String newValue)
newValue
- the new value
public ModelNode set(java.lang.String newValue)
newValue
- the new value
public ModelNode set(java.math.BigDecimal newValue)
newValue
- the new value
public ModelNode set(java.math.BigInteger newValue)
newValue
- the new value
public ModelNode set(ModelNode newValue)
newValue
- the new value
public ModelNode set(byte[] newValue)
newValue
- the new value
public ModelNode set(ModelType newValue)
newValue
- the new value
public ModelNode set(Property newValue)
newValue
- the new value
public ModelNode set(java.lang.String propertyName, ModelNode propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, int propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, long propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, double propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, boolean propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, java.lang.String propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode setExpression(java.lang.String propertyName, java.lang.String propertyValue)
propertyName
- the property namepropertyValue
- the property expression value
public ModelNode set(java.lang.String propertyName, java.math.BigDecimal propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, java.math.BigInteger propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, byte[] propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.lang.String propertyName, ModelType propertyValue)
propertyName
- the property namepropertyValue
- the property value
public ModelNode set(java.util.Collection<ModelNode> newValue)
newValue
- the list value
public 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 name
java.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 name
java.util.NoSuchElementException
- if the element does not existpublic ModelNode remove(java.lang.String name) throws java.util.NoSuchElementException
When called on property values, the name must match the property name.
name
- the child name
java.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 index
java.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 index
java.util.NoSuchElementException
- if the element does not existpublic ModelNode add(int newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(long newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(double newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(boolean newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode addExpression(java.lang.String newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(java.lang.String newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(java.math.BigDecimal newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(java.math.BigInteger newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(ModelNode newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(byte[] newValue)
ModelType.LIST
.
newValue
- the new value to add
public ModelNode add(java.lang.String propertyName, int propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, long propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, double propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, boolean propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, java.lang.String propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, java.math.BigDecimal propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, java.math.BigInteger propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, ModelNode propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add(java.lang.String propertyName, byte[] propertyValue)
ModelType.LIST
.
propertyName
- the property namepropertyValue
- the property value
public ModelNode add()
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
.
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
.
public boolean has(int index)
index
- the index
true
if there is a (possibly undefined) node at the given indexpublic boolean has(java.lang.String key)
key
- the name
true
if there is a (possibly undefined) node at the given keypublic boolean hasDefined(int index)
index
- the index
true
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 name
true
if there is a node at the given index and its type
is not ModelType.UNDEFINED
public java.util.Set<java.lang.String> keys()
public java.util.List<ModelNode> asList()
public ModelNode get(java.lang.String... names)
ModelType.OBJECT
.
names
- the child names
java.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 string
public static ModelNode fromJSONString(java.lang.String input)
public static ModelNode fromStream(java.io.InputStream stream) throws java.io.IOException
stream
- the source stream
java.io.IOException
public static ModelNode fromJSONStream(java.io.InputStream stream) throws java.io.IOException
stream
- the source stream
java.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 ModelNode resolve()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other object
true
if they are equal, false
otherwisepublic boolean equals(ModelNode other)
other
- the other object
true
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 written
java.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 written
java.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 written
java.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 written
java.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 read
java.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 read
java.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 read
java.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 read
java.io.IOException
- if an I/O error occurspublic void writeBase64(java.io.OutputStream stream) throws java.io.IOException
stream
- the stream to write to
java.io.IOException
- if the specified stream has an issue
|
JBoss Dynamic Model Representation API 1.0.0.Final | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |