Search in sources :

Example 56 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.

the class JaxrsSubsystemParser_2_0 method handleSimpleElement.

protected void handleSimpleElement(final XMLExtendedStreamReader reader, final EnumSet<JaxrsElement> encountered, final ModelNode subsystem, final JaxrsElement element) throws XMLStreamException {
    if (!encountered.add(element)) {
        throw unexpectedElement(reader);
    }
    final String name = element.getLocalName();
    final String value = parseElementNoAttributes(reader);
    final SimpleAttributeDefinition attribute = (SimpleAttributeDefinition) JaxrsConstants.nameToAttributeMap.get(name);
    attribute.parseAndSetParameter(value, subsystem, reader);
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Example 57 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.

the class JacORBSubsystemParser method parseSecurityConfig_1_0.

/**
 * <p>
 * Parses the {@code security} section of the JacORB subsystem configuration according to the XSD version 1.0.
 * </p>
 *
 * @param reader the {@code XMLExtendedStreamReader} used to read the configuration XML.
 * @param node   the {@code ModelNode} that will hold the parsed security configuration.
 * @throws javax.xml.stream.XMLStreamException
 *          if an error occurs while parsing the XML.
 */
private void parseSecurityConfig_1_0(XMLExtendedStreamReader reader, ModelNode node) throws XMLStreamException {
    // parse all security attributes.
    EnumSet<Attribute> expectedAttributes = EnumSet.of(Attribute.SECURITY_SUPPORT_SSL, Attribute.SECURITY_ADD_COMPONENT_INTERCEPTOR, Attribute.SECURITY_CLIENT_SUPPORTS, Attribute.SECURITY_CLIENT_REQUIRES, Attribute.SECURITY_SERVER_SUPPORTS, Attribute.SECURITY_SERVER_REQUIRES, Attribute.SECURITY_USE_DOMAIN_SF, Attribute.SECURITY_USE_DOMAIN_SSF);
    EnumSet<Attribute> parsedAttributes = EnumSet.noneOf(Attribute.class);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        requireNoNamespaceAttribute(reader, i);
        String attrValue = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        // check for unexpected attributes.
        if (!expectedAttributes.contains(attribute))
            throw unexpectedAttribute(reader, i);
        // check for duplicate attributes.
        if (!parsedAttributes.add(attribute)) {
            throw duplicateAttribute(reader, attribute.getLocalName());
        }
        switch(attribute) {
            // check the attributes that need to be converted from int to string.
            case SECURITY_CLIENT_SUPPORTS:
            case SECURITY_CLIENT_REQUIRES:
            case SECURITY_SERVER_SUPPORTS:
            case SECURITY_SERVER_REQUIRES:
                SSLConfigValue value = SSLConfigValue.fromValue(attrValue);
                if (value == null)
                    throw JacORBLogger.ROOT_LOGGER.invalidSSLConfig(attrValue, reader.getLocation());
                attrValue = value.toString();
            default:
                SimpleAttributeDefinition definition = ((SimpleAttributeDefinition) JacORBSubsystemDefinitions.valueOf(attribute.getLocalName()));
                // a null definition represents an attribute that has been deprecated and is no longer used.
                if (definition != null)
                    definition.parseAndSetParameter(attrValue, node, reader);
        }
    }
    // the security element doesn't have child elements.
    requireNoContent(reader);
}
Also used : ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.duplicateAttribute(org.jboss.as.controller.parsing.ParseUtils.duplicateAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Example 58 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.

the class MessagingSubsystemParser method processHornetQServer.

protected void processHornetQServer(final XMLExtendedStreamReader reader, final ModelNode subsystemAddress, final List<ModelNode> list, Namespace namespace) throws XMLStreamException {
    String hqServerName = null;
    String elementName = null;
    if (namespace == Namespace.MESSAGING_1_0) {
        // We're parsing the 1.0 xsd's <subsystem> element
        requireNoAttributes(reader);
        elementName = ModelDescriptionConstants.SUBSYSTEM;
    } else {
        final int count = reader.getAttributeCount();
        if (count > 0) {
            requireSingleAttribute(reader, Attribute.NAME.getLocalName());
            hqServerName = reader.getAttributeValue(0).trim();
        }
        elementName = HORNETQ_SERVER;
    }
    if (hqServerName == null || hqServerName.length() == 0) {
        hqServerName = DEFAULT;
    }
    final ModelNode address = subsystemAddress.clone();
    address.add(HORNETQ_SERVER, hqServerName);
    address.protect();
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(ADD);
    operation.get(OP_ADDR).set(address);
    list.add(operation);
    EnumSet<Element> seen = EnumSet.noneOf(Element.class);
    // Handle elements
    String localName = null;
    do {
        reader.nextTag();
        localName = reader.getLocalName();
        final Element element = Element.forName(reader.getLocalName());
        if (!seen.add(element)) {
            throw ParseUtils.duplicateNamedElement(reader, element.getLocalName());
        }
        switch(element) {
            case ACCEPTORS:
                processAcceptors(reader, address, list);
                break;
            case ADDRESS_SETTINGS:
                processAddressSettings(reader, address, list);
                break;
            case BINDINGS_DIRECTORY:
                parseDirectory(reader, CommonAttributes.BINDINGS_DIRECTORY, address, list);
                break;
            case BRIDGES:
                processBridges(reader, address, list);
                break;
            case BROADCAST_GROUPS:
                processBroadcastGroups(reader, address, list);
                break;
            case CLUSTER_CONNECTIONS:
                processClusterConnections(reader, address, list);
                break;
            case CONNECTORS:
                processConnectors(reader, address, list);
                break;
            case CONNECTOR_SERVICES:
                processConnectorServices(reader, address, list);
                break;
            case DISCOVERY_GROUPS:
                processDiscoveryGroups(reader, address, list);
                break;
            case DIVERTS:
                parseDiverts(reader, address, list);
                break;
            case FILE_DEPLOYMENT_ENABLED:
                // This isn't an element in the xsd as there is no filesystem support in AS
                unhandledElement(reader, element);
                break;
            case GROUPING_HANDLER:
                processGroupingHandler(reader, address, list);
                break;
            case JOURNAL_DIRECTORY:
                parseDirectory(reader, CommonAttributes.JOURNAL_DIRECTORY, address, list);
                break;
            case LARGE_MESSAGES_DIRECTORY:
                parseDirectory(reader, CommonAttributes.LARGE_MESSAGES_DIRECTORY, address, list);
                break;
            case LIVE_CONNECTOR_REF:
                {
                    MessagingLogger.ROOT_LOGGER.deprecatedXMLElement(element.toString());
                    skipElementText(reader);
                    break;
                }
            case PAGING_DIRECTORY:
                parseDirectory(reader, CommonAttributes.PAGING_DIRECTORY, address, list);
                break;
            case REMOTING_INTERCEPTORS:
                processRemotingInterceptors(reader, operation);
                break;
            case SECURITY_DOMAIN:
                handleElementText(reader, element, null, operation);
                break;
            case SECURITY_SETTINGS:
                {
                    // process security settings
                    processSecuritySettings(reader, address, list);
                    break;
                }
            case CORE_QUEUES:
                {
                    parseQueues(reader, address, list);
                    break;
                }
            case CONNECTION_FACTORIES:
                {
                    processConnectionFactories(reader, address, list);
                    break;
                }
            case JMS_DESTINATIONS:
                {
                    processJmsDestinations(reader, address, list);
                    break;
                }
            case SCHEDULED_THREAD_POOL_MAX_SIZE:
            case THREAD_POOL_MAX_SIZE:
                {
                    // Use the "server" variant
                    handleElementText(reader, element, "server", operation);
                    break;
                }
            case MESSAGE_COUNTER_ENABLED:
                {
                    MessagingLogger.ROOT_LOGGER.deprecatedXMLElement(element.toString(), Element.STATISTICS_ENABLED.toString());
                    handleElementText(reader, element, operation);
                    break;
                }
            case HORNETQ_SERVER:
                // The end of the hornetq-server element
                if (namespace == Namespace.MESSAGING_1_0) {
                    throw unexpectedEndElement(reader);
                }
                break;
            case SUBSYSTEM:
                // The end of the subsystem element
                if (namespace != Namespace.MESSAGING_1_0) {
                    throw unexpectedEndElement(reader);
                }
                break;
            case CLUSTERED:
                // log that the attribute is deprecated but handle it anyway
                MessagingLogger.ROOT_LOGGER.deprecatedXMLElement(element.toString());
            default:
                if (SIMPLE_ROOT_RESOURCE_ELEMENTS.contains(element)) {
                    AttributeDefinition attributeDefinition = element.getDefinition();
                    if (attributeDefinition instanceof SimpleAttributeDefinition) {
                        handleElementText(reader, element, operation);
                    } else {
                        // These should be handled in specific case blocks above, e.g. case REMOTING_INTERCEPTORS:
                        handleComplexConfigurationAttribute(reader, element, operation);
                    }
                } else {
                    handleUnknownConfigurationAttribute(reader, element, operation);
                }
        }
    } while (reader.hasNext() && localName.equals(elementName) == false);
}
Also used : ParseUtils.readStringAttributeElement(org.jboss.as.controller.parsing.ParseUtils.readStringAttributeElement) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ParseUtils.unexpectedEndElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedEndElement) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ListAttributeDefinition(org.jboss.as.controller.ListAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.

the class PooledConnectionFactoryDefinition method copy.

private static AttributeDefinition copy(AttributeDefinition attribute, AttributeAccess.Flag flag) {
    AbstractAttributeDefinitionBuilder builder;
    if (attribute instanceof SimpleListAttributeDefinition) {
        builder = new SimpleListAttributeDefinition.Builder((SimpleListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((SimpleListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else if (attribute instanceof SimpleMapAttributeDefinition) {
        builder = new SimpleMapAttributeDefinition.Builder((SimpleMapAttributeDefinition) attribute);
    } else if (attribute instanceof PrimitiveListAttributeDefinition) {
        builder = new PrimitiveListAttributeDefinition.Builder((PrimitiveListAttributeDefinition) attribute);
        // TODO remove once WFCORE-95 is fixed
        ((PrimitiveListAttributeDefinition.Builder) builder).setListValidator(attribute.getValidator());
    } else {
        builder = new SimpleAttributeDefinitionBuilder((SimpleAttributeDefinition) attribute);
    }
    builder.setFlags(flag);
    return builder.build();
}
Also used : SimpleListAttributeDefinition(org.jboss.as.controller.SimpleListAttributeDefinition) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) AbstractAttributeDefinitionBuilder(org.jboss.as.controller.AbstractAttributeDefinitionBuilder) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) SimpleMapAttributeDefinition(org.jboss.as.controller.SimpleMapAttributeDefinition) PrimitiveListAttributeDefinition(org.jboss.as.controller.PrimitiveListAttributeDefinition)

Example 60 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project wildfly by wildfly.

the class WebSubsystemParser method writeContent.

/**
 * {@inheritDoc}
 */
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
    context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);
    ModelNode node = context.getModelNode();
    WebDefinition.DEFAULT_VIRTUAL_SERVER.marshallAsAttribute(node, true, writer);
    WebDefinition.INSTANCE_ID.marshallAsAttribute(node, false, writer);
    WebDefinition.NATIVE.marshallAsAttribute(node, true, writer);
    WebDefinition.DEFAULT_SESSION_TIMEOUT.marshallAsAttribute(node, false, writer);
    if (node.hasDefined(CONFIGURATION)) {
        writeContainerConfig(writer, node.get(CONFIGURATION));
    }
    if (node.hasDefined(CONNECTOR)) {
        for (final Property connector : node.get(CONNECTOR).asPropertyList()) {
            final ModelNode config = connector.getValue();
            writer.writeStartElement(Element.CONNECTOR.getLocalName());
            writer.writeAttribute(NAME, connector.getName());
            List<AttributeDefinition> connectorAttributes = new ArrayList<>(Arrays.asList(WebConnectorDefinition.CONNECTOR_ATTRIBUTES));
            if (config.hasDefined(Constants.PROXY_BINDING)) {
                connectorAttributes.remove(WebConnectorDefinition.PROXY_PORT);
                connectorAttributes.remove(WebConnectorDefinition.PROXY_NAME);
            } else {
                connectorAttributes.remove(WebConnectorDefinition.PROXY_BINDING);
            }
            if (config.hasDefined(Constants.REDIRECT_BINDING)) {
                connectorAttributes.remove(WebConnectorDefinition.REDIRECT_PORT);
            } else {
                connectorAttributes.remove(WebConnectorDefinition.REDIRECT_BINDING);
            }
            for (AttributeDefinition attr : connectorAttributes) {
                if (attr instanceof SimpleAttributeDefinition) {
                    ((SimpleAttributeDefinition) attr).marshallAsAttribute(config, true, writer);
                }
            }
            if (config.get(SSL_PATH.getKey(), SSL_PATH.getValue()).isDefined()) {
                ModelNode sslConfig = config.get(SSL_PATH.getKey(), SSL_PATH.getValue());
                writer.writeStartElement(Element.SSL.getLocalName());
                WebSSLDefinition.NAME.marshallAsAttribute(sslConfig, writer);
                for (SimpleAttributeDefinition attr : WebSSLDefinition.SSL_ATTRIBUTES) {
                    attr.marshallAsAttribute(sslConfig, false, writer);
                }
                writer.writeEndElement();
            }
            if (config.hasDefined(VIRTUAL_SERVER)) {
                for (final ModelNode virtualServer : config.get(VIRTUAL_SERVER).asList()) {
                    writer.writeEmptyElement(VIRTUAL_SERVER);
                    writer.writeAttribute(NAME, virtualServer.asString());
                }
            }
            writer.writeEndElement();
        }
    }
    if (node.hasDefined(VIRTUAL_SERVER)) {
        for (final Property host : node.get(VIRTUAL_SERVER).asPropertyList()) {
            final ModelNode config = host.getValue();
            writer.writeStartElement(Element.VIRTUAL_SERVER.getLocalName());
            writer.writeAttribute(NAME, host.getName());
            WebVirtualHostDefinition.ENABLE_WELCOME_ROOT.marshallAsAttribute(config, true, writer);
            WebVirtualHostDefinition.DEFAULT_WEB_MODULE.marshallAsAttribute(config, true, writer);
            if (config.hasDefined(ALIAS)) {
                for (final ModelNode alias : config.get(ALIAS).asList()) {
                    writer.writeEmptyElement(ALIAS);
                    writer.writeAttribute(NAME, alias.asString());
                }
            }
            if (config.get(ACCESS_LOG_PATH.getKey(), ACCESS_LOG_PATH.getValue()).isDefined()) {
                ModelNode accessLog = config.get(ACCESS_LOG_PATH.getKey(), ACCESS_LOG_PATH.getValue());
                writer.writeStartElement(Element.ACCESS_LOG.getLocalName());
                for (SimpleAttributeDefinition attr : WebAccessLogDefinition.ACCESS_LOG_ATTRIBUTES) {
                    attr.marshallAsAttribute(accessLog, false, writer);
                }
                if (accessLog.get(DIRECTORY_PATH.getKey(), DIRECTORY_PATH.getValue()).isDefined()) {
                    ModelNode directory = accessLog.get(DIRECTORY_PATH.getKey(), DIRECTORY_PATH.getValue());
                    String name = Element.DIRECTORY.getLocalName();
                    boolean startwritten = false;
                    startwritten = writeAttribute(writer, WebAccessLogDirectoryDefinition.PATH, directory, startwritten, name);
                    startwritten = writeAttribute(writer, WebAccessLogDirectoryDefinition.RELATIVE_TO, directory, startwritten, name);
                    if (startwritten) {
                        writer.writeEndElement();
                    }
                }
                writer.writeEndElement();
            }
            if (config.hasDefined(REWRITE)) {
                for (final ModelNode rewritenode : config.get(REWRITE).asList()) {
                    Property prop = rewritenode.asProperty();
                    ModelNode rewrite = prop.getValue();
                    writer.writeStartElement(REWRITE);
                    writer.writeAttribute(NAME, prop.getName());
                    WebReWriteDefinition.PATTERN.marshallAsAttribute(rewrite, false, writer);
                    WebReWriteDefinition.SUBSTITUTION.marshallAsAttribute(rewrite, false, writer);
                    WebReWriteDefinition.FLAGS.marshallAsAttribute(rewrite, false, writer);
                    if (rewrite.hasDefined(CONDITION)) {
                        for (final ModelNode conditionnode : rewrite.get(CONDITION).asList()) {
                            Property conditionProp = conditionnode.asProperty();
                            ModelNode condition = conditionProp.getValue();
                            writer.writeStartElement(CONDITION);
                            writer.writeAttribute(NAME, conditionProp.getName());
                            WebReWriteConditionDefinition.TEST.marshallAsAttribute(condition, false, writer);
                            WebReWriteConditionDefinition.PATTERN.marshallAsAttribute(condition, false, writer);
                            WebReWriteConditionDefinition.FLAGS.marshallAsAttribute(condition, false, writer);
                            writer.writeEndElement();
                        }
                    }
                    writer.writeEndElement();
                }
            }
            if (config.get(SSO_PATH.getKey(), SSO_PATH.getValue()).isDefined()) {
                final ModelNode sso;
                sso = config.get(SSO_PATH.getKey(), SSO_PATH.getValue());
                writer.writeStartElement(SSO);
                for (SimpleAttributeDefinition attr : WebSSODefinition.SSO_ATTRIBUTES) {
                    attr.marshallAsAttribute(sso, false, writer);
                }
                writer.writeEndElement();
            }
            // End of the VIRTUAL_SERVER
            writer.writeEndElement();
        }
        if (node.hasDefined(VALVE)) {
            for (final Property valve : node.get(VALVE).asPropertyList()) {
                final ModelNode config = valve.getValue();
                writer.writeStartElement(Element.VALVE.getLocalName());
                writer.writeAttribute(NAME, valve.getName());
                for (AttributeDefinition attr : WebValveDefinition.ATTRIBUTES) {
                    if (attr instanceof SimpleAttributeDefinition) {
                        ((SimpleAttributeDefinition) attr).marshallAsAttribute(config, false, writer);
                    }
                }
                if (config.hasDefined(PARAM)) {
                    for (final Property entry : config.get(PARAM).asPropertyList()) {
                        writer.writeEmptyElement(Element.PARAM.getLocalName());
                        writer.writeAttribute(Attribute.PARAM_NAME.getLocalName(), entry.getName());
                        writer.writeAttribute(Attribute.PARAM_VALUE.getLocalName(), entry.getValue().asString());
                    }
                }
                writer.writeEndElement();
            }
        }
    }
    writer.writeEndElement();
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Aggregations

SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)89 ModelNode (org.jboss.dmr.ModelNode)47 PathAddress (org.jboss.as.controller.PathAddress)14 Property (org.jboss.dmr.Property)13 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)12 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)9 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)9 HashSet (java.util.HashSet)8 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)8 XMLStreamException (javax.xml.stream.XMLStreamException)7 OperationContext (org.jboss.as.controller.OperationContext)4 ArrayList (java.util.ArrayList)3 AbstractAttributeDefinitionBuilder (org.jboss.as.controller.AbstractAttributeDefinitionBuilder)3 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)3 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)3 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)3 SimpleMapAttributeDefinition (org.jboss.as.controller.SimpleMapAttributeDefinition)3 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)3 ClearWorkManagerStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)2 WorkManagerRuntimeAttributeReadHandler (org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler)2