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

The following examples show how to use org.jboss.dmr.ModelNode#getType() . 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: 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 3
Source File: ObjectListAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Overrides the superclass implementation to allow the value type's AttributeDefinition to in turn
 * resolve each element.
 *
 * {@inheritDoc}
 */
@Override
public ModelNode resolveValue(ExpressionResolver resolver, ModelNode value) throws OperationFailedException {

    // Pass non-LIST values through the superclass so it can reject weird values and, in the odd chance
    // that's how this object is set up, turn undefined into a default list value.
    ModelNode superResult = value.getType() == ModelType.LIST ? value : super.resolveValue(resolver, value);

    // If it's not a LIST (almost certainly UNDEFINED), then nothing more we can do
    if (superResult.getType() != ModelType.LIST) {
        return superResult;
    }
    // Resolve each element.
    // Don't mess with the original value
    ModelNode clone = superResult == value ? value.clone() : superResult;
    ModelNode result = new ModelNode();
    result.setEmptyList();
    for (ModelNode element : clone.asList()) {
        result.add(valueType.resolveValue(resolver, element));
    }
    // Validate the entire list
    getValidator().validateParameter(getName(), result);
    return result;
}
 
Example 4
Source File: AnalysisContext.java    From revapi with Apache License 2.0 6 votes vote down vote up
private static void mergeNodes(String extension, String id, List<String> path, ModelNode a, ModelNode b) {
    switch (b.getType()) {
        case LIST:
            for (ModelNode v : b.asList()) {
                a.add(v.clone());
            }
            break;
        case OBJECT:
            for (String k : b.keys()) {
                ModelNode ak = a.get(k);
                path.add(k);
                mergeNodes(extension, id, path, ak, b.get(k));
                path.remove(path.size() - 1);
            }
            break;
        default:
            if (a.isDefined()) {
                String p = path.stream().collect(Collectors.joining("/"));
                throw new IllegalArgumentException(
                        "A conflict detected while merging configurations of extension '" + extension +
                                "' with id '" + id + "'. A value on path '" + p + "' would overwrite an already existing one.");
            } else {
                a.set(b);
            }
    }
}
 
Example 5
Source File: MulticastAddressValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);

    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        String inetAddr = value.asString();
        try {
            final InetAddress mcastAddr = InetAddress.getByName(inetAddr);
            if (!mcastAddr.isMulticastAddress()) {
                throw ControllerLogger.ROOT_LOGGER.invalidMulticastAddress(inetAddr, parameterName);
            }
        } catch (final UnknownHostException e) {
            throw ControllerLogger.ROOT_LOGGER.unknownMulticastAddress(e, inetAddr, parameterName);
        }

    }
}
 
Example 6
Source File: InterfaceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Deprecated
static ParameterValidator createNestedParamValidator() {
    return new ModelTypeValidator(ModelType.OBJECT, true, false, true) {
        @Override
        public void validateParameter(final String parameterName, final ModelNode value) throws OperationFailedException {
            super.validateParameter(parameterName, value);

            for (final AttributeDefinition def : NESTED_ATTRIBUTES) {
                final String name = def.getName();
                if (value.hasDefined(name)) {
                    final ModelNode v = value.get(name);
                    if (NESTED_LIST_ATTRIBUTES.contains(def)) {
                        if (ModelType.LIST != v.getType()) {
                            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidType(v.getType()));
                        }
                    } else {
                        def.getValidator().validateParameter(name, v);
                    }
                }
            }
        }
    };
}
 
Example 7
Source File: AttributeTransformationRequirementChecker.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Check an attribute for expressions.
 *
 * @param node the attribute value
 * @return whether an expression was found or not
 */
private boolean checkForExpression(final ModelNode node) {
    if (!node.isDefined()) {
        return false;
    }

    final ModelNode resolved = node.clone();
    if (node.getType() == ModelType.EXPRESSION || node.getType() == ModelType.STRING) {
        return checkForExpression(resolved.asString());
    } else if (node.getType() == ModelType.OBJECT) {
        for (Property prop : resolved.asPropertyList()) {
            if(checkForExpression(prop.getValue())) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.LIST) {
        for (ModelNode current : resolved.asList()) {
            if(checkForExpression(current)) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.PROPERTY) {
        return checkForExpression(resolved.asProperty().getValue());
    }
    return false;
}
 
Example 8
Source File: EnumValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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 9
Source File: BaseOperationCommand.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void addHeaders(CommandContext ctx, ModelNode request) throws CommandFormatException {
    if(headers == null || !headers.isPresent(ctx.getParsedCommandLine())) {
        return;
    }
    final ModelNode headersNode = headers.toModelNode(ctx);
    if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
        throw new CommandFormatException("--headers option has wrong value '"+headersNode+"'");
    }
    final ModelNode opHeaders = request.get(Util.OPERATION_HEADERS);
    opHeaders.set(headersNode);
}
 
Example 10
Source File: ExpressionResolverImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Examine the given model node, resolving any expressions found within, including within child nodes.
 *
 * @param node the node
 * @return a node with all expressions resolved
 * @throws OperationFailedException if an expression cannot be resolved
 */
private ModelNode resolveExpressionsRecursively(final ModelNode node) throws OperationFailedException {
    if (!node.isDefined()) {
        return node;
    }

    ModelType type = node.getType();
    ModelNode resolved;
    if (type == ModelType.EXPRESSION) {
        resolved = resolveExpressionStringRecursively(node.asExpression().getExpressionString(), lenient, true);
    } else if (type == ModelType.OBJECT) {
        resolved = node.clone();
        for (Property prop : resolved.asPropertyList()) {
            resolved.get(prop.getName()).set(resolveExpressionsRecursively(prop.getValue()));
        }
    } else if (type == ModelType.LIST) {
        resolved = node.clone();
        ModelNode list = new ModelNode();
        list.setEmptyList();
        for (ModelNode current : resolved.asList()) {
            list.add(resolveExpressionsRecursively(current));
        }
        resolved = list;
    } else if (type == ModelType.PROPERTY) {
        resolved = node.clone();
        resolved.set(resolved.asProperty().getName(), resolveExpressionsRecursively(resolved.asProperty().getValue()));
    } else {
        resolved = node;
    }

    return resolved;
}
 
Example 11
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;
}
 
Example 12
Source File: SchemaDrivenJSONToXmlConverter.java    From revapi with Apache License 2.0 5 votes vote down vote up
private static PlexusConfiguration convertObject(ModelNode configuration, ConversionContext ctx) {
    XmlPlexusConfiguration object = new XmlPlexusConfiguration(ctx.tagName);
    if (ctx.id != null) {
        object.setAttribute("id", ctx.id);
    }

    ModelNode propertySchemas = ctx.currentSchema.get("properties");
    ModelNode additionalPropSchemas = ctx.currentSchema.get("additionalProperties");
    for (String key : configuration.keys()) {
        ModelNode childConfig = configuration.get(key);
        ModelNode childSchema = propertySchemas.get(key);
        if (!childSchema.isDefined()) {
            if (additionalPropSchemas.getType() == ModelType.BOOLEAN) {
                throw new IllegalArgumentException("Cannot determine the format for the '" + key +
                        "' JSON value during the JSON-to-XML conversion.");
            }
            childSchema = additionalPropSchemas;
        }

        ctx.currentSchema = childSchema;
        ctx.pushTag(key);
        ctx.id = null;

        if (!childSchema.isDefined()) {
            //check if this is an ignorable path
            if (ctx.ignorablePaths.contains(ctx.getCurrentPathString())) {
                ctx.currentPath.pop();
                continue;
            }
            throw new IllegalArgumentException("Could not determine the format for the '" + key +
                    "' JSON value during the JSON-to-XML conversion.");
        }

        PlexusConfiguration xmlChild = convert(childConfig, ctx);
        ctx.currentPath.pop();
        object.addChild(xmlChild);
    }
    return object;
}
 
Example 13
Source File: LongRangeValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        long val = value.asLong();
        if (val < min) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMinValue(val, parameterName, min));
        }
        else if (val > max) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMaxValue(val, parameterName, max));
        }
    }
}
 
Example 14
Source File: ListOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void updateModel(OperationContext context, ModelNode model, AttributeDefinition attributeDefinition, ModelNode attribute) throws OperationFailedException {
    // We can't use the AD type to validate undefined, because "attribute" may be a child field of an OBJECT
    // and the AD is not for the field, it's for the top level attribute
    //if (attribute.getType() != ModelType.LIST && attributeDefinition.getType() != ModelType.LIST) {
    if (attribute.isDefined() && attribute.getType() != ModelType.LIST) {
        // TODO if "attribute" is a field of an OBJECT the AD will not reflect the thing
        // that is invalid so this message will be strange
        throw ControllerLogger.MGMT_OP_LOGGER.attributeIsWrongType(attributeDefinition.getName(), ModelType.LIST, attributeDefinition.getType());
    }
    updateModel(context, model, attribute);
}
 
Example 15
Source File: FailedOperationTransformationConfig.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean checkValue(String attrName, ModelNode attribute, boolean isGeneratedWriteAttribute) {
    if (!attribute.isDefined()) {
        return false;
    }

    AttributesPathAddressConfig<?> complexChildConfig = complexAttributes.get(attrName);
    switch (attribute.getType()) {
    case EXPRESSION:
        return true;
    case STRING:
        return EXPRESSION_PATTERN.matcher(attribute.asString()).matches();
    case LIST:
        for (ModelNode entry : attribute.asList()) {
            if (complexChildConfig == null) {
                if (checkValue(attrName, entry, isGeneratedWriteAttribute)) {
                    return true;
                }
            } else {
                if (childHasExpressions(complexChildConfig, attribute.get(attrName), isGeneratedWriteAttribute)) {
                    return true;
                }
            }
        }
        break;
    case OBJECT:
        for (Property prop : attribute.asPropertyList()) {
            if (complexChildConfig == null) {
                if (checkValue(attrName, prop.getValue(), isGeneratedWriteAttribute)) {
                    return true;
                }
            } else {
                if (childHasExpressions(complexChildConfig, attribute, isGeneratedWriteAttribute)) {
                    return true;
                }
            }
        }
        break;
    case PROPERTY:
        if (complexChildConfig == null) {
            if (checkValue(attrName, attribute.asProperty().getValue(), isGeneratedWriteAttribute)) {
                return true;
            }
        } else {
            if (childHasExpressions(complexChildConfig, attribute.asProperty().getValue(), isGeneratedWriteAttribute)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 16
Source File: HostXml_13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 17
Source File: ParsedInterfaceCriteria.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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 18
Source File: HostXml_12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 19
Source File: HostXml_9.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 20
Source File: HostXml_14.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}