Java Code Examples for org.jboss.dmr.ModelNode#asBigDecimal()

The following examples show how to use org.jboss.dmr.ModelNode#asBigDecimal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DMRDriver.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private static Object toObject(ModelNode value) throws ProtocolException {
    switch (value.getType()) {
        case BIG_DECIMAL:
            return value.asBigDecimal();
        case BIG_INTEGER:
            return value.asBigInteger();
        case BOOLEAN:
            return value.asBoolean();
        case BYTES:
            return value.asBytes();
        case DOUBLE:
            return value.asDouble();
        case INT:
            return value.asInt();
        case LONG:
            return value.asLong();
        case OBJECT:
            return value.asObject();
        case PROPERTY:
            return value.asProperty();
        case STRING:
            return value.asString();
        case UNDEFINED:
            return null;
        case LIST:
            return toObjectList(value.asList());
        default:
            throw new ProtocolException("cannot handle an attribute of type [" + value.getType() + "]");
    }
}
 
Example 2
Source File: JmxManagementInterface.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Object object(ModelNode node) {
    switch (node.getType()) {
        case BIG_DECIMAL:
            return node.asBigDecimal();
        case BIG_INTEGER:
            return node.asBigInteger();
        case BOOLEAN:
            return node.asBoolean();
        case BYTES:
            return node.asBytes();
        case DOUBLE:
            return node.asDouble();
        case EXPRESSION:
            return node.asExpression();
        case INT:
            return node.asInt();
        case LIST:
            return node.asList();
        case LONG:
            return node.asLong();
        case PROPERTY:
            return node.asProperty();
        case STRING:
            return node.asString();
        case UNDEFINED:
            return null;
        default:
            throw new UnsupportedOperationException("Can't convert '" + node.getType() + "' to object");
    }
}
 
Example 3
Source File: TypeConverters.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
Object fromModelNode(final ModelNode node) {
    return node.asBigDecimal();
}
 
Example 4
Source File: AttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode convertToExpectedType(final ModelNode node) {
    ModelType nodeType = node.getType();
    if (nodeType == type || nodeType == ModelType.UNDEFINED || nodeType == ModelType.EXPRESSION || Util.isExpression(node.asString())) {
        return node;
    }
    switch (type) {
        case BIG_DECIMAL:
            return new ModelNode(node.asBigDecimal());
        case BIG_INTEGER:
            return new ModelNode(node.asBigInteger());
        case BOOLEAN:
            return new ModelNode(node.asBoolean());
        case BYTES:
            return new ModelNode(node.asBytes());
        case DOUBLE:
            return new ModelNode(node.asDouble());
        case INT:
            return new ModelNode(node.asInt());
        case LIST:
            return new ModelNode().set(node.asList());
        case LONG:
            return new ModelNode(node.asLong());
        case PROPERTY:
            return new ModelNode().set(node.asProperty());
        case TYPE:
            return new ModelNode(node.asType());
        case STRING:
            return new ModelNode(node.asString());
        case OBJECT:
            // Check for LIST of PROPERTY. If that is found convert.
            // But only convert if that specifically is found in order
            // to avoid odd unintended conversions (e.g. LIST of STRING, which DMR can convert to OBJECT)
            if (nodeType == ModelType.LIST) {
                if (node.asInt() == 0) {
                    return new ModelNode().setEmptyObject();
                }
                ModelNode first = node.get(0);
                if (first.getType() != ModelType.PROPERTY) {
                    return node;
                }
                // Now we know at least the first element is property, so
                // we assume the rest are as well.
                List<Property> propertyList;
                try {
                    propertyList = node.asPropertyList();
                } catch (IllegalArgumentException iae) {
                    // ignore. The validator allowed this node or we wouldn't be here,
                    // so just fall through and return the unconverted node
                    // Note this isn't expected to be a real world case
                    return node;
                }
                ModelNode result = new ModelNode().setEmptyObject();
                for (Property prop : propertyList) {
                    result.get(prop.getName()).set(prop.getValue());
                }
                return result;
            }
            return node;
        default:
            return node;
    }
}
 
Example 5
Source File: OperationValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void checkType(final ModelType modelType, final ModelNode value) {
    ModelNode resolved;
    try {
        resolved = expressionResolver.resolveExpressions(value);
    } catch (OperationFailedException e) {
        // Dealing with an unresolvable expression is beyond what this class can do.
        // So fall through and see what happens. Basically if modelType is EXPRESSION or STRING
        // it will pass, otherwise an IAE will be thrown
        resolved = value;
    }
    switch (modelType) {
        case BIG_DECIMAL:
            resolved.asBigDecimal();
            break;
        case BIG_INTEGER:
            resolved.asBigInteger();
            break;
        case BOOLEAN:
            resolved.asBoolean();
            break;
        case BYTES:
            resolved.asBytes();
            break;
        case DOUBLE:
            resolved.asDouble();
            break;
        case EXPRESSION:
            value.asString();
            break;
        case INT:
            resolved.asInt();
            break;
        case LIST:
            value.asList();
            break;
        case LONG:
            resolved.asLong();
            break;
        case OBJECT:
            value.asObject();
            break;
        case PROPERTY:
            value.asProperty();
            break;
        case STRING:
            value.asString();
            break;
        case TYPE:
            resolved.asType();
            break;
    }
}