Java Code Examples for org.jboss.dmr.ModelType#UNDEFINED

The following examples show how to use org.jboss.dmr.ModelType#UNDEFINED . 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: JBossASClient.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * This tries to find specific node within a list of nodes. Given an address and a named node
 * at that address (the "haystack"), it is assumed that haystack is actually a list of other
 * nodes. This method looks in the haystack and tries to find the named needle. If it finds it,
 * that list item is returned. If it does not find the needle in the haystack, it returns null.
 *
 * For example, if you want to find a specific datasource in the list of datasources, you
 * can pass in the address for the datasource subsystem, and ask to look in the data-source
 * node list (the haystack) and return the named datasource (the needle).
 *
 * @param addr resource address
 * @param haystack the collection
 * @param needle the item to find in the collection
 * @return the found item or null if not found
 * @throws Exception if the lookup fails for some reason
 */
public ModelNode findNodeInList(Address addr, String haystack, String needle) throws Exception {
    final ModelNode queryNode = createRequest(READ_RESOURCE, addr);
    final ModelNode results = execute(queryNode);
    if (isSuccess(results)) {
        final ModelNode haystackNode = getResults(results).get(haystack);
        if (haystackNode.getType() != ModelType.UNDEFINED) {
            final List<ModelNode> haystackList = haystackNode.asList();
            for (ModelNode needleNode : haystackList) {
                if (needleNode.has(needle)) {
                    return needleNode;
                }
            }
        }
        return null;
    } else {
        throw new FailureException(results, "Failed to get data for [" + addr + "]");
    }
}
 
Example 2
Source File: FileCorrector.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) {
    if (newValue.getType() == ModelType.UNDEFINED) {
        return newValue;
    }
    if (newValue.getType() != ModelType.OBJECT || currentValue.getType() != ModelType.OBJECT) {
        return newValue;
    }
    final ModelNode newPath = newValue.get(PATH.getName());
    if (newPath.isDefined() && !AbstractPathService.isAbsoluteUnixOrWindowsPath(newPath.asString())) {
        if (currentValue.hasDefined(RELATIVE_TO.getName()) && !newValue.hasDefined(RELATIVE_TO.getName())) {
            newValue.get(RELATIVE_TO.getName()).set(currentValue.get(RELATIVE_TO.getName()));
        }
    }
    return newValue;
}
 
Example 3
Source File: PropagatingCorrector.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ModelNode correct(ModelNode newValue, ModelNode currentValue) {
    if(newValue.getType() == ModelType.UNDEFINED) {
        return newValue;
    }
    if(newValue.getType() != ModelType.OBJECT || currentValue.getType() != ModelType.OBJECT) {
        return newValue;
    }
    final Set<String> operationKeys = newValue.keys();
    final Set<String> currentKeys = currentValue.keys();
    for(String currentKey : currentKeys) {
        if(!operationKeys.contains(currentKey)) {
            newValue.get(currentKey).set(currentValue.get(currentKey));
        }
    }
    return newValue;
}
 
Example 4
Source File: OperationDialog.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void setInputComponent() {
    this.label = makeLabel();
    if (type == ModelType.BOOLEAN && !expressionsAllowed) {
        this.valueComponent = new JCheckBox(makeLabelString(false));
        this.valueComponent.setToolTipText(description);
        this.label = new JLabel(); // checkbox doesn't need a label
    } else if (type == ModelType.UNDEFINED) {
        JLabel jLabel = new JLabel();
        this.valueComponent = jLabel;
    } else if (props.get("allowed").isDefined()) {
        JComboBox comboBox = makeJComboBox(props.get("allowed").asList());
        this.valueComponent = comboBox;
    } else if (type == ModelType.LIST) {
        ListEditor listEditor = new ListEditor(OperationDialog.this);
        this.valueComponent = listEditor;
    } else if (type == ModelType.BYTES) {
        this.valueComponent = new BrowsePanel(OperationDialog.this);
    } else {
        JTextField textField = new JTextField(30);
        this.valueComponent = textField;
    }
}
 
Example 5
Source File: TypeConverters.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ModelType getType(ModelNode typeNode) {
    if (typeNode == null) {
        return ModelType.UNDEFINED;
    }
    try {
        return ModelType.valueOf(typeNode.toString());
    } catch (RuntimeException e) {
        return null;
    }
}
 
Example 6
Source File: CaseParameterCorrector.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) {
    if (newValue.getType() == ModelType.UNDEFINED) {
        return newValue;
    }
    if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) {
        return newValue;
    }
    final String stringValue = newValue.asString();
    final String uCase = stringValue.toUpperCase(Locale.ENGLISH);
    if (!stringValue.equals(uCase)) {
        newValue.set(uCase);
    }
    return newValue;
}
 
Example 7
Source File: CaseParameterCorrector.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) {
    if (newValue.getType() == ModelType.UNDEFINED) {
        return newValue;
    }
    if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) {
        return newValue;
    }
    final String stringValue = newValue.asString();
    final String uCase = stringValue.toLowerCase(Locale.ENGLISH);
    if (!stringValue.equals(uCase)) {
        newValue.set(uCase);
    }
    return newValue;
}
 
Example 8
Source File: OptionAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setType() {
    try {
        final Field typeField;
        if (option.getClass().getSimpleName().equals("SequenceOption")) {
            typeField = option.getClass().getDeclaredField("elementType");
        } else {
            typeField = option.getClass().getDeclaredField("type");
        }

        typeField.setAccessible(true);
        optionType = (Class<?>) typeField.get(option);

        if (optionType.isAssignableFrom(Integer.class)) {
            type = ModelType.INT;
        } else if (optionType.isAssignableFrom(Long.class)) {
            type = ModelType.LONG;
        } else if (optionType.isAssignableFrom(BigInteger.class)) {
            type = ModelType.BIG_INTEGER;
        } else if (optionType.isAssignableFrom(Double.class)) {
            type = ModelType.DOUBLE;
        } else if (optionType.isAssignableFrom(BigDecimal.class)) {
            type = ModelType.BIG_DECIMAL;
        } else if (optionType.isEnum() || optionType.isAssignableFrom(String.class)) {
            type = ModelType.STRING;
        } else if (optionType.isAssignableFrom(Boolean.class)) {
            type = ModelType.BOOLEAN;
        } else {
            type = ModelType.UNDEFINED;
        }

    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 9
Source File: TypeConverters.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
ObjectTypeConverter(ModelNode valueTypeNode) {
    this.valueTypeNode = nullNodeAsUndefined(valueTypeNode);
    ModelType valueType = getType(valueTypeNode);
    this.valueType = valueType == ModelType.UNDEFINED ? null : valueType;
}
 
Example 10
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 11
Source File: OptionAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Builder(String attributeName, Option<?> option, ModelNode defaultValue) {
    super(attributeName, ModelType.UNDEFINED, true);
    this.option = option;
    this.defaultValue = defaultValue;
    setType();
}