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

The following examples show how to use org.jboss.dmr.ModelType#TYPE . 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: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void replaceFilePathsWithBytes(ModelNode request, ModelNode opDescOutcome) throws CommandFormatException {
    ModelNode requestProps = opDescOutcome.get("result", "request-properties");
    for (Property prop : requestProps.asPropertyList()) {
        ModelNode typeDesc = prop.getValue().get("type");
        if (typeDesc.getType() == ModelType.TYPE && typeDesc.asType() == ModelType.BYTES
                && request.hasDefined(prop.getName())) {
            String filePath = request.get(prop.getName()).asString();
            File localFile = new File(filePath);
            if (!localFile.exists())
                continue;
            try {
                request.get(prop.getName()).set(Util.readBytes(localFile));
            } catch (OperationFormatException e) {
                throw new CommandFormatException(e);
            }
        }
    }
}
 
Example 2
Source File: OperationValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkList(final ModelNode operation, final String paramName, final ModelNode describedProperty, final ModelNode value) {
    if (describedProperty.get(TYPE).asType() == ModelType.LIST) {
        if (describedProperty.hasDefined(VALUE_TYPE) && describedProperty.get(VALUE_TYPE).getType() == ModelType.TYPE) {
            ModelType elementType = describedProperty.get(VALUE_TYPE).asType();
            for (ModelNode element : value.asList()) {
                try {
                    checkType(elementType, element);
                } catch (IllegalArgumentException e) {
                    throw ControllerLogger.ROOT_LOGGER.validationFailedInvalidElementType(paramName, elementType, formatOperationForMessage(operation));
                }
            }
        }
    }
}
 
Example 3
Source File: KnownIssuesValidationConfiguration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void replaceLocalDomainControllerType(ModelNode description) {
    /*
     The description looks like, and we don't want the local to be OBJECT for validation so we replace it with STRING
    "domain-controller" => {
        "type" => OBJECT,
        "description" => "Configuration of how the host should interact with the Domain Controller",
        "expressions-allowed" => false,
        "nillable" => false,
        "value-type" => {
            "local" => {
                "type" => OBJECT,
                "description" => "Configure a local Domain Controller",
                "expressions-allowed" => false,
                "nillable" => true
            },
            "remote" => {
                "type" => OBJECT,
                "description" => "Remote Domain Controller connection configuration",
                "expressions-allowed" => false,
                "nillable" => true,
                "value-type" => {"host" => {
                    "type" => INT,
                    "description" => "The address used for the Domain Controller connection",
                    "expressions-allowed" => false,
                    "nillable" => false
                }}
            }
        },
        "access-type" => "read-only",
        "storage" => "runtime"
    }*/
    ModelNode node = find(description, ATTRIBUTES, DOMAIN_CONTROLLER, VALUE_TYPE, LOCAL, TYPE);
    if (node != null) {
        if (node.getType() != ModelType.TYPE && node.asType() != ModelType.OBJECT) {
            //Validate it here before we do the naughty replacement
            throw new IllegalStateException("Bad local domain controller " + node);
        }
        node.set(ModelType.STRING);
    }
}
 
Example 4
Source File: CommandExecutor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean replaceFilePathsWithBytes(ModelNode request) throws CommandFormatException, IOException {
    boolean didReplacement = false;
    ModelNode opDesc = new ModelNode();
    opDesc.get("address").set(request.get("address"));
    opDesc.get("operation").set("read-operation-description");
    final String opName = request.get("operation").asString();
    opDesc.get("name").set(opName);
    ModelNode response = execute(opDesc, false).getResponseNode();
    if (response.hasDefined("result", "request-properties")) {
        final ModelNode requestProps = response.get("result", "request-properties");
        for (Property prop : requestProps.asPropertyList()) {
            ModelNode typeDesc = prop.getValue().get("type");
            if (typeDesc.getType() == ModelType.TYPE && typeDesc.asType() == ModelType.BYTES
                    && request.hasDefined(prop.getName())) {
                String filePath = request.get(prop.getName()).asString();
                File localFile = new File(filePath);
                if (!localFile.exists())
                    continue;
                try {
                    request.get(prop.getName()).set(Util.readBytes(localFile));
                    didReplacement = true;
                } catch (OperationFormatException e) {
                    throw new CommandFormatException(e);
                }
            }
        }
    }
    return didReplacement;
}