Java Code Examples for org.jboss.dmr.ModelNode#asType()
The following examples show how to use
org.jboss.dmr.ModelNode#asType() .
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 |
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: KnownIssuesValidationConfiguration.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
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 3
Source File: GenericTypeOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected ModelType asType(ModelNode type) { if(type == null) { return null; } try { return type.asType(); } catch(IllegalArgumentException e) { // the value type is a structure return null; } }
Example 4
Source File: ResourceCompositeOperationHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected ModelType asType(ModelNode type) { if(type == null) { return null; } try { return type.asType(); } catch(IllegalArgumentException e) { // the value type is a structure return null; } }
Example 5
Source File: ValueTypeCompleter.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean typeEquals(ModelNode mn, ModelType type) { ModelType mt; try { mt = mn.asType(); } catch (IllegalArgumentException ex) { return false; } return mt.equals(type); }
Example 6
Source File: ValueTypeCompleter.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean isObject(ModelNode mn) { try { mn.asType(); } catch (IllegalArgumentException ex) { return true; } return false; }
Example 7
Source File: HelpSupport.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static boolean isObject(ModelNode vt) { try { vt.asType(); } catch (Exception ex) { return true; } return false; }
Example 8
Source File: CommandExecutor.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
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; }
Example 9
Source File: AttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
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 10
Source File: OperationValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
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; } }
Example 11
Source File: DefaultOperationCandidatesProvider.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static CommandLineCompleter getCompleter(final Property prop, CommandContext ctx, OperationRequestAddress address) { ModelNode attrDescr = prop.getValue(); final ModelNode typeNode = attrDescr.get(Util.TYPE); if (typeNode.isDefined() && ModelType.BOOLEAN.equals(typeNode.asType())) { return SimpleTabCompleter.BOOLEAN; } if (typeNode.isDefined() && ModelType.BYTES.equals(typeNode.asType())) { return BytesCompleter.INSTANCE; } if (attrDescr.has(Util.VALUE_TYPE)) { final ModelNode valueTypeNode = attrDescr.get(Util.VALUE_TYPE); if (typeNode.isDefined() && ModelType.LIST.equals(typeNode.asType())) { return new ValueTypeCompleter(attrDescr, address); } try { // the logic is: if value-type is set to a specific type // (i.e. doesn't describe a custom structure) // then if allowed is specified, use it. // it might be broken but so far this is not looking clear to me valueTypeNode.asType(); if (attrDescr.has(Util.ALLOWED)) { return getAllowedCompleter(prop); } // Possibly a Map. if (typeNode.isDefined() && ModelType.OBJECT.equals(typeNode.asType())) { return new ValueTypeCompleter(attrDescr, address); } } catch (IllegalArgumentException e) { // TODO this means value-type describes a custom structure return new ValueTypeCompleter(attrDescr, address); } } if (attrDescr.has(Util.FILESYSTEM_PATH) && attrDescr.get(Util.FILESYSTEM_PATH).asBoolean()) { return FilenameTabCompleter.newCompleter(ctx); } if (attrDescr.has(Util.RELATIVE_TO) && attrDescr.get(Util.RELATIVE_TO).asBoolean()) { return new DeploymentItemCompleter(address); } if (attrDescr.has(Util.ALLOWED)) { return getAllowedCompleter(prop); } if (attrDescr.has(Util.CAPABILITY_REFERENCE)) { return new CapabilityReferenceCompleter(address, attrDescr.get(Util.CAPABILITY_REFERENCE).asString()); } return null; }