Java Code Examples for org.jboss.as.controller.parsing.ParseUtils#missingRequiredElement()

The following examples show how to use org.jboss.as.controller.parsing.ParseUtils#missingRequiredElement() . 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: LoggingSubsystemParser_1_2.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void parseSyslogHandler(final XMLExtendedStreamReader reader, final PathAddress address, final List<ModelNode> operations, final Set<String> names) throws XMLStreamException {
    final ModelNode operation = Util.createAddOperation();
    // Attributes
    String name = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case ENABLED:
                ENABLED.parseAndSetParameter(value, operation, reader);
                break;
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    if (!names.add(name)) {
        throw duplicateNamedElement(reader, name);
    }

    // Setup the operation address
    addOperationAddress(operation, address, SyslogHandlerResourceDefinition.NAME, name);

    final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
    while (reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (!encountered.add(element)) {
            throw unexpectedElement(reader);
        }
        switch (element) {
            case APP_NAME: {
                APP_NAME.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case FACILITY: {
                FACILITY.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case HOSTNAME: {
                HOSTNAME.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case LEVEL: {
                LEVEL.parseAndSetParameter(readNameAttribute(reader), operation, reader);
                break;
            }
            case FORMATTER: {
                if (reader.nextTag() != START_ELEMENT) {
                    throw ParseUtils.missingRequiredElement(reader, Collections.singleton(Element.SYSLOG_FORMATTER.getLocalName()));
                }
                switch (Element.forName(reader.getLocalName())) {
                    case SYSLOG_FORMATTER: {
                        requireSingleAttribute(reader, Attribute.SYSLOG_TYPE.getLocalName());
                        operation.get(SYSLOG_FORMATTER.getName()).set(readStringAttributeElement(reader, Attribute.SYSLOG_TYPE.getLocalName()));
                        requireNoContent(reader);
                        break;
                    }
                    default: {
                        throw unexpectedElement(reader);
                    }
                }
                break;
            }
            case PORT: {
                PORT.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case SERVER_ADDRESS: {
                SERVER_ADDRESS.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
    operations.add(operation);
}
 
Example 2
Source File: LoggingSubsystemParser_7_0.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
void parseSyslogHandler(final XMLExtendedStreamReader reader, final PathAddress address, final List<ModelNode> operations, final Set<String> names) throws XMLStreamException {
    final ModelNode operation = Util.createAddOperation();
    // Attributes
    String name = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case ENABLED:
                ENABLED.parseAndSetParameter(value, operation, reader);
                break;
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    if (!names.add(name)) {
        throw duplicateNamedElement(reader, name);
    }

    // Setup the operation address
    addOperationAddress(operation, address, SyslogHandlerResourceDefinition.NAME, name);

    final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
    while (reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (!encountered.add(element)) {
            throw unexpectedElement(reader);
        }
        switch (element) {
            case APP_NAME: {
                APP_NAME.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case FACILITY: {
                FACILITY.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case HOSTNAME: {
                HOSTNAME.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case LEVEL: {
                LEVEL.parseAndSetParameter(readNameAttribute(reader), operation, reader);
                break;
            }
            case FORMATTER: {
                final EnumSet<Element> requiredFormatter = EnumSet.of(Element.SYSLOG_FORMATTER);
                while (reader.nextTag() != END_ELEMENT) {
                    switch (Element.forName(reader.getLocalName())) {
                        case SYSLOG_FORMATTER: {
                            requiredFormatter.remove(Element.SYSLOG_FORMATTER);
                            operation.get(SYSLOG_FORMATTER.getName()).set(readStringAttributeElement(reader, Attribute.SYSLOG_TYPE.getLocalName()));
                            break;
                        }
                        case NAMED_FORMATTER: {
                            SyslogHandlerResourceDefinition.NAMED_FORMATTER.parseAndSetParameter(readNameAttribute(reader), operation, reader);
                            break;
                        }
                        default: {
                            throw unexpectedElement(reader);
                        }
                    }
                }
                if (!requiredFormatter.isEmpty()) {
                    throw ParseUtils.missingRequiredElement(reader, requiredFormatter);
                }
                break;
            }
            case PORT: {
                PORT.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            case SERVER_ADDRESS: {
                SERVER_ADDRESS.parseAndSetParameter(readValueAttribute(reader), operation, reader);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
    operations.add(operation);
}