Java Code Examples for org.jboss.dmr.ModelType#STRING
The following examples show how to use
org.jboss.dmr.ModelType#STRING .
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: RunAsRoleMapper.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static Set<String> getOperationHeaderRoles(ModelNode operation) { Set<String> result = null; if (operation.hasDefined(ModelDescriptionConstants.OPERATION_HEADERS)) { ModelNode headers = operation.get(ModelDescriptionConstants.OPERATION_HEADERS); if (headers.hasDefined(ModelDescriptionConstants.ROLES)) { ModelNode rolesNode = headers.get(ModelDescriptionConstants.ROLES); if (rolesNode.getType() == ModelType.STRING) { rolesNode = parseRolesString(rolesNode.asString()); } if (rolesNode.getType() == ModelType.STRING) { result = Collections.singleton(getRoleFromText(rolesNode.asString())); } else { result = new HashSet<String>(); for (ModelNode role : rolesNode.asList()) { result.add(getRoleFromText(role.asString())); } } } } return result; }
Example 2
Source File: PropertiesAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public PropertiesAttributeDefinition build() { if (elementValidator == null) { elementValidator = new ModelTypeValidator(ModelType.STRING); } String xmlName = getXmlName(); String elementName = getName().equals(xmlName) ? null : xmlName; if (getAttributeMarshaller() == null) { setAttributeMarshaller(new AttributeMarshallers.PropertiesAttributeMarshaller(wrapperElement, xmlNameExplicitlySet ? xmlName : elementName, wrapXmlElement)); } if (getParser() == null) { setAttributeParser(new AttributeParsers.PropertiesParser(wrapperElement, elementName, wrapXmlElement)); } return new PropertiesAttributeDefinition(this); }
Example 3
Source File: PrimitiveListAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
static ModelNode parseSingleElementToList(AttributeDefinition ad, ModelNode original, ModelNode resolved) { ModelNode result = resolved; if (original.isDefined() && !resolved.equals(original) && resolved.getType() == ModelType.LIST && resolved.asInt() == 1) { // WFCORE-3448. We have a list with 1 element that is not the same as the defined original. // So that implies we had an expression as the element, which is what we would have gotten // if the expression string was passed by an xml parser to parseAndSetParameter. See if the // resolved form of that expression in turn parses to a list and if it does, used the parsed list. ModelNode element = resolved.get(0); if (element.getType() == ModelType.STRING) { ModelNode holder = new ModelNode(); try { ad.getParser().parseAndSetParameter(ad, element.asString(), holder, null); ModelNode parsed = holder.get(ad.getName()); if (parsed.getType() == ModelType.LIST && parsed.asInt() > 1) { result = parsed; } } catch (XMLStreamException | RuntimeException e) { // ignore and just return the original value } } } return result; }
Example 4
Source File: EnumValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); ModelType type = value.getType(); if (type == ModelType.STRING ) { String tuString = ExpressionResolver.SIMPLE.resolveExpressions(value).asString(); // Sorry, no support for resolving against vault! E enumValue = toStringMap.get(tuString); if (enumValue == null) { try { enumValue = Enum.valueOf(enumType, tuString.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw ControllerLogger.ROOT_LOGGER.invalidEnumValue(tuString, parameterName, toStringMap.keySet()); } } if (!allowedValues.contains(enumValue)) { throw ControllerLogger.ROOT_LOGGER.invalidEnumValue(tuString, parameterName, toStringMap.keySet()); } // Hack to store the allowed value in the model, not the user input if (!value.isProtected()) { value.set(enumValue.toString()); } } }
Example 5
Source File: OperationErrorTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void validateResponseDetails(ModelNode response, String host, String server, ErrorExtension.ErrorPoint errorPoint, boolean multiphase) { ModelNode unmodified = response.clone(); ModelNode fd; if (server != null) { ModelNode serverResp = response.get(SERVER_GROUPS, "main-server-group", HOST, host, server, RESPONSE); assertEquals(unmodified.toString(), FAILED, serverResp.get(OUTCOME).asString()); fd = serverResp.get(FAILURE_DESCRIPTION); } else if ("master".equals(host)) { if (errorPoint == ErrorExtension.ErrorPoint.COMMIT || errorPoint == ErrorExtension.ErrorPoint.ROLLBACK) { // In this case the late error destroys the normal response structure and we // get a simple failure. This isn't ideal. I'm writing the test to specifically assert // this simple failure structure mostly so it can assert the more complex // structure in the other cases, not because I'm explicitly ruling out any change to this // simple structure and want this test to enforce that. OTOH it shouldn't be changed lightly // as it would be easy to mess up. fd = response.get(FAILURE_DESCRIPTION); } else if (!multiphase) { fd = response.get(FAILURE_DESCRIPTION); } else if (RUNTIME_POINTS.contains(errorPoint)) { fd = response.get(FAILURE_DESCRIPTION, HOST_FAILURE_DESCRIPTIONS, host); } else { fd = response.get(FAILURE_DESCRIPTION, DOMAIN_FAILURE_DESCRIPTION); } } else { if (errorPoint == ErrorExtension.ErrorPoint.COMMIT) { // post-commit failure currently does not produce a failure-description assertFalse(unmodified.toString(), response.hasDefined(FAILURE_DESCRIPTION)); return; } fd = multiphase ? response.get(FAILURE_DESCRIPTION, HOST_FAILURE_DESCRIPTIONS, host) : response.get(FAILURE_DESCRIPTION); } ModelType errorType = errorPoint == ErrorExtension.ErrorPoint.SERVICE_START ? ModelType.OBJECT : ModelType.STRING; assertEquals(unmodified.toString(), errorType, fd.getType()); assertTrue(unmodified.toString(), fd.asString().contains(ErrorExtension.ERROR_MESSAGE)); }
Example 6
Source File: HelpSupport.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static ModelType getAdaptedArgumentType(ModelNode mn) { ModelType type = mn.get(Util.TYPE).asType(); if (mn.hasDefined(Util.FILESYSTEM_PATH) && mn.hasDefined(Util.ATTACHED_STREAMS)) { type = ModelType.STRING; } return type; }
Example 7
Source File: CaseParameterCorrector.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@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: FailedOperationTransformationConfig.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected ModelNode correctValue(ModelNode toResolve, boolean isGeneratedWriteAttribute) { if (toResolve.getType() == ModelType.STRING) { toResolve = new ModelNode().set(new ValueExpression(toResolve.asString())); } try { return ExpressionResolver.TEST_RESOLVER.resolveExpressions(toResolve); } catch (OperationFailedException e) { throw new IllegalArgumentException(e); } }
Example 9
Source File: EnumValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** @deprecated use {@link #EnumValidator(Class, Enum[])} with {@link EnumSet#allOf(Class)} since {@link org.jboss.as.controller.AttributeDefinition} handles the nullable and expression checks.*/ @SafeVarargs @Deprecated public EnumValidator(final Class<E> enumType, final boolean nullable, final boolean allowExpressions, final E... allowed) { super(ModelType.STRING, nullable, allowExpressions); this.enumType = enumType; this.allowedValues = setOf(enumType, allowed); for (E value : allowed) { toStringMap.put(value.toString(), value); } }
Example 10
Source File: ServiceURIValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.getType() == ModelType.STRING) { try { // Ensure this is a valid URI URI uri = URI.create(value.asString()); // Ensure the URI is a valid for use in a ServiceURL new ServiceURL.Builder().setUri(uri); } catch (IllegalArgumentException e) { throw new OperationFailedException(e); } } }
Example 11
Source File: ReadResourceDescriptionAccessControlTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
void addAttribute(String name, AccessConstraintDefinition...constraints) { SimpleAttributeDefinitionBuilder builder = new SimpleAttributeDefinitionBuilder(name, ModelType.STRING); if (constraints != null) { builder.setAccessConstraints(constraints); } attributes.add(builder.build()); }
Example 12
Source File: SensitiveVaultExpressionConstraint.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private boolean isSensitiveValue(ModelNode value) { if (value.getType() == ModelType.EXPRESSION || value.getType() == ModelType.STRING) { String valueString = value.asString(); if (ExpressionResolver.EXPRESSION_PATTERN.matcher(valueString).matches()) { int start = valueString.indexOf("${") + 2; int end = valueString.indexOf("}", start); valueString = valueString.substring(start, end); return VaultReader.STANDARD_VAULT_PATTERN.matcher(valueString).matches(); } } return false; }
Example 13
Source File: ReadResourceDescriptionAccessControlTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
void addReadOnlyAttribute(String name, AccessConstraintDefinition...constraints) { SimpleAttributeDefinitionBuilder builder = new SimpleAttributeDefinitionBuilder(name, ModelType.STRING); if (constraints != null) { builder.setAccessConstraints(constraints); } readOnlyAttributes.add(builder.build()); }
Example 14
Source File: InterfacesXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public void parseInterfaces(final XMLExtendedStreamReader reader, final Set<String> names, final ModelNode address, final Namespace expectedNs, final List<ModelNode> list, final boolean checkSpecified) throws XMLStreamException { requireNoAttributes(reader); while (reader.nextTag() != END_ELEMENT) { requireNamespace(reader, expectedNs); Element element = Element.forName(reader.getLocalName()); if (Element.INTERFACE != element) { throw unexpectedElement(reader); } // Attributes requireSingleAttribute(reader, Attribute.NAME.getLocalName()); final String name = reader.getAttributeValue(0); if (!names.add(name)) { throw ControllerLogger.ROOT_LOGGER.duplicateInterfaceDeclaration(reader.getLocation()); } final ModelNode interfaceAdd = new ModelNode(); interfaceAdd.get(OP_ADDR).set(address).add(ModelDescriptionConstants.INTERFACE, name); interfaceAdd.get(OP).set(ADD); final ModelNode criteriaNode = interfaceAdd; parseInterfaceCriteria(reader, expectedNs, interfaceAdd); if (checkSpecified && criteriaNode.getType() != ModelType.STRING && criteriaNode.getType() != ModelType.EXPRESSION && criteriaNode.asInt() == 0) { throw unexpectedEndElement(reader); } list.add(interfaceAdd); } }
Example 15
Source File: MaskedAddressValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public MaskedAddressValidator(final boolean nullable, final boolean allowExpressions) { super(ModelType.STRING, nullable, allowExpressions, true); }
Example 16
Source File: ParsedInterfaceCriteria.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private static void checkStringType(ModelNode node, String id, boolean allowExpressions) { if (node.getType() != ModelType.STRING && (!allowExpressions || node.getType() != ModelType.EXPRESSION)) { throw new ParsingException(ControllerLogger.ROOT_LOGGER.illegalValueForInterfaceCriteria(node.getType(), id, ModelType.STRING)); } }
Example 17
Source File: SSLDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
CipherSuiteNamesValidator() { super(ModelType.STRING, true, true, false); }
Example 18
Source File: AuditResourceDefinitions.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public SizeValidator(final boolean nullable) { super(ModelType.STRING, nullable); }
Example 19
Source File: SuffixValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public SuffixValidator(final boolean nullable, final boolean denySeconds) { super(ModelType.STRING, nullable); this.denySeconds = denySeconds; }
Example 20
Source File: AttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 3 votes |
/** * Checks if the given node is of {@link ModelType#STRING} with a string value that includes expression syntax. * If so returns a node of {@link ModelType#EXPRESSION}, else simply returns {@code node} unchanged * * @param node the node to examine. Will not be {@code null} * @return the node with expressions converted, or the original node if no conversion was performed * Cannot return {@code null} */ protected static ModelNode convertStringExpression(ModelNode node) { if (node.getType() == ModelType.STRING) { return ParseUtils.parsePossibleExpression(node.asString()); } return node; }