public class ModelNode extends Object implements Cloneable, org.timepedia.exporter.client.Exportable
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() |
| 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(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 |
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)
Add the given expression to the end of this node's value list.
|
BigDecimal |
asBigDecimal()
Get the value of this node as a
BigDecimal. |
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. |
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.
|
List<Property> |
asPropertyList()
Get the value of this node as a property list.
|
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(Object other)
Determine whether this object is equal to another.
|
static ModelNode |
fromBase64(String encoded) |
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.
|
String |
getFailureDescription() |
Object |
getTag(String 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 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 key)
Determine whether this node has a defined child with the given name.
|
int |
hashCode()
Get the hash code of this node object.
|
static boolean |
hasNativeBase64Support() |
boolean |
isDefined()
Determine whether this node is defined.
|
boolean |
isFailure() |
Set<String> |
keys()
Get the set of keys contained in this object.
|
static boolean |
nativeBase64() |
static String |
nativeDecode(String encoded) |
static String |
nativeEncode(String plain) |
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.
|
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 system property expressions 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(ModelType type,
Object propValue) |
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 |
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)
Change this node's value to the given expression value.
|
ModelNode |
setExpression(String propertyName,
String propertyValue)
Change this node's value to a property with the given name and expression value.
|
void |
setTag(String name,
Object value) |
String |
toBase64String() |
static byte[] |
toBytes(String str) |
String |
toJSONString() |
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 |
writeExternal(DataOutput out)
Write this node's content in binary format to the given target.
|
IllegalArgumentException - if no conversion is possiblepublic 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 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 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 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 possiblepublic boolean asBoolean()
throws IllegalArgumentException
boolean. Collection types return true for non-empty
collections. Numerical types return true for non-zero values.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 possiblepublic String asString()
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 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 possiblepublic ModelType asType() throws IllegalArgumentException
ModelType enum. The string
value of this node must be convertible to a type.ModelType valueIllegalArgumentException - 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 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 no conversion is possiblepublic byte[] asBytes()
throws IllegalArgumentException
IllegalArgumentException - if no conversion is possiblepublic Property asProperty() throws IllegalArgumentException
IllegalArgumentException - if no conversion is possiblepublic List<Property> asPropertyList() throws IllegalArgumentException
IllegalArgumentException - 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 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 valuepublic ModelNode setExpression(String 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 valuepublic ModelNode setExpression(String propertyName, String propertyValue)
propertyName - the property namepropertyValue - the property expression 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
When called on property values, the name must match the property name.
name - the child nameNoSuchElementException - 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 addpublic ModelNode add(long newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(double newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(boolean newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode addExpression(String newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(String newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(BigDecimal newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(BigInteger newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(ModelNode newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(byte[] newValue)
ModelType.LIST.newValue - the new value to addpublic ModelNode add(String propertyName, int propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, long propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, double propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, boolean propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, String propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, BigDecimal propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, BigInteger propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, ModelNode propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic ModelNode add(String propertyName, byte[] propertyValue)
ModelType.LIST.propertyName - the property namepropertyValue - the property valuepublic 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 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 hasDefined(int index)
index - the indextrue if there is a node at the given index and its type is not ModelType.UNDEFINEDpublic boolean hasDefined(String key)
key - the nametrue if there is a node at the given index and its type is not ModelType.UNDEFINEDpublic Set<String> keys()
public List<ModelNode> asList()
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 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 String toJSONString()
public String toBase64String()
public static boolean hasNativeBase64Support()
public static boolean nativeBase64()
public static byte[] toBytes(String str)
public ModelNode resolve()
public 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(DataOutput out) throws IOException
out - the target to which the content should be writtenIOException - 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 boolean isFailure()
public String getFailureDescription()
Copyright © 2014 JBoss, a division of Red Hat. All rights reserved.