Search in sources :

Example 1 with ParseUtils.unexpectedAttribute

use of org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute in project wildfly by wildfly.

the class AppClientXml method parseSocketBindingGroup.

private void parseSocketBindingGroup(final XMLExtendedStreamReader reader, final Set<String> interfaces, final ModelNode address, final Namespace expectedNs, final List<ModelNode> updates) throws XMLStreamException {
    // unique names for both socket-binding and outbound-socket-binding(s)
    final Set<String> uniqueBindingNames = new HashSet<String>();
    ModelNode op = Util.getEmptyOperation(ADD, null);
    // Handle attributes
    String socketBindingGroupName = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.DEFAULT_INTERFACE);
    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);
        }
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        switch(attribute) {
            case NAME:
                {
                    socketBindingGroupName = value;
                    required.remove(attribute);
                    break;
                }
            case DEFAULT_INTERFACE:
                {
                    SocketBindingGroupResourceDefinition.DEFAULT_INTERFACE.parseAndSetParameter(value, op, reader);
                    required.remove(attribute);
                    break;
                }
            case PORT_OFFSET:
                {
                    SocketBindingGroupResourceDefinition.PORT_OFFSET.parseAndSetParameter(value, op, reader);
                    break;
                }
            default:
                throw ParseUtils.unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    ModelNode groupAddress = address.clone().add(SOCKET_BINDING_GROUP, socketBindingGroupName);
    op.get(OP_ADDR).set(groupAddress);
    updates.add(op);
    // Handle elements
    while (reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, expectedNs);
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case SOCKET_BINDING:
                {
                    // FIXME JBAS-8825
                    final String bindingName = parseSocketBinding(reader, interfaces, groupAddress, updates);
                    if (!uniqueBindingNames.add(bindingName)) {
                        throw ControllerLogger.ROOT_LOGGER.alreadyDeclared(Element.SOCKET_BINDING.getLocalName(), Element.OUTBOUND_SOCKET_BINDING.getLocalName(), bindingName, Element.SOCKET_BINDING_GROUP.getLocalName(), socketBindingGroupName, reader.getLocation());
                    }
                    break;
                }
            case OUTBOUND_SOCKET_BINDING:
                {
                    final String bindingName = parseOutboundSocketBinding(reader, interfaces, groupAddress, updates);
                    if (!uniqueBindingNames.add(bindingName)) {
                        throw ControllerLogger.ROOT_LOGGER.alreadyDeclared(Element.SOCKET_BINDING.getLocalName(), Element.OUTBOUND_SOCKET_BINDING.getLocalName(), bindingName, Element.SOCKET_BINDING_GROUP.getLocalName(), socketBindingGroupName, reader.getLocation());
                    }
                    break;
                }
            default:
                throw unexpectedElement(reader);
        }
    }
}
Also used : ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) ParseUtils.isNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.isNoNamespaceAttribute) Attribute(org.jboss.as.controller.parsing.Attribute) ParseUtils.nextElement(org.jboss.as.controller.parsing.ParseUtils.nextElement) Element(org.jboss.as.controller.parsing.Element) ParseUtils.unexpectedElement(org.jboss.as.controller.parsing.ParseUtils.unexpectedElement) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 2 with ParseUtils.unexpectedAttribute

use of org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute in project wildfly by wildfly.

the class MessagingSubsystemParser method processConnectors.

void processConnectors(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> updates) throws XMLStreamException {
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        String name = null;
        String socketBinding = null;
        String serverId = null;
        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            final String attrValue = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch(attribute) {
                case NAME:
                    {
                        name = attrValue;
                        break;
                    }
                case SOCKET_BINDING:
                    {
                        socketBinding = attrValue;
                        break;
                    }
                case SERVER_ID:
                    {
                        serverId = attrValue;
                        break;
                    }
                default:
                    {
                        throw ParseUtils.unexpectedAttribute(reader, i);
                    }
            }
        }
        if (name == null) {
            throw missingRequired(reader, Collections.singleton(Attribute.NAME));
        }
        final ModelNode connectorAddress = address.clone();
        final ModelNode operation = new ModelNode();
        operation.get(OP).set(ADD);
        boolean generic = false;
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case CONNECTOR:
                {
                    operation.get(OP_ADDR).set(connectorAddress.add(CONNECTOR, name));
                    if (socketBinding != null) {
                        operation.get(RemoteTransportDefinition.SOCKET_BINDING.getName()).set(socketBinding);
                    }
                    generic = true;
                    break;
                }
            case NETTY_CONNECTOR:
                {
                    operation.get(OP_ADDR).set(connectorAddress.add(REMOTE_CONNECTOR, name));
                    if (socketBinding == null) {
                        throw missingRequired(reader, Collections.singleton(Attribute.SOCKET_BINDING));
                    }
                    operation.get(RemoteTransportDefinition.SOCKET_BINDING.getName()).set(socketBinding);
                    break;
                }
            case IN_VM_CONNECTOR:
                {
                    operation.get(OP_ADDR).set(connectorAddress.add(IN_VM_CONNECTOR, name));
                    if (serverId != null) {
                        InVMTransportDefinition.SERVER_ID.parseAndSetParameter(serverId, operation, reader);
                    }
                    break;
                }
            default:
                {
                    throw ParseUtils.unexpectedElement(reader);
                }
        }
        updates.add(operation);
        parseTransportConfiguration(reader, operation, generic, updates);
    }
}
Also used : ParseUtils.requireSingleAttribute(org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) 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) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with ParseUtils.unexpectedAttribute

use of org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute in project wildfly by wildfly.

the class MessagingSubsystemParser method processJmsConnectors.

static ModelNode processJmsConnectors(final XMLExtendedStreamReader reader) throws XMLStreamException {
    final ModelNode connectors = new ModelNode();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        String name = null;
        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            final String value = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch(attribute) {
                case CONNECTOR_NAME:
                    {
                        name = value.trim();
                        break;
                    }
                case BACKUP_CONNECTOR_NAME:
                    {
                        MessagingLogger.ROOT_LOGGER.deprecatedXMLAttribute(attribute.toString());
                        break;
                    }
                default:
                    {
                        throw ParseUtils.unexpectedAttribute(reader, i);
                    }
            }
        }
        if (name == null) {
            throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.CONNECTOR_NAME));
        }
        final Element element = Element.forName(reader.getLocalName());
        if (element != Element.CONNECTOR_REF) {
            throw ParseUtils.unexpectedElement(reader);
        }
        ParseUtils.requireNoContent(reader);
        // create the connector node
        connectors.get(name);
    }
    return connectors;
}
Also used : ParseUtils.requireSingleAttribute(org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) 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) ModelNode(org.jboss.dmr.ModelNode)

Example 4 with ParseUtils.unexpectedAttribute

use of org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute in project wildfly by wildfly.

the class MessagingSubsystemParser method processAcceptors.

void processAcceptors(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> updates) throws XMLStreamException {
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        String name = null;
        String socketBinding = null;
        String serverId = null;
        int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            final String attrValue = reader.getAttributeValue(i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch(attribute) {
                case NAME:
                    {
                        name = attrValue;
                        break;
                    }
                case SOCKET_BINDING:
                    {
                        socketBinding = attrValue;
                        break;
                    }
                case SERVER_ID:
                    {
                        serverId = attrValue;
                        break;
                    }
                default:
                    {
                        throw ParseUtils.unexpectedAttribute(reader, i);
                    }
            }
        }
        if (name == null) {
            throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.NAME));
        }
        final ModelNode acceptorAddress = address.clone();
        final ModelNode operation = new ModelNode();
        operation.get(OP).set(ADD);
        boolean generic = false;
        final Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case ACCEPTOR:
                {
                    operation.get(OP_ADDR).set(acceptorAddress.add(ACCEPTOR, name));
                    if (socketBinding != null) {
                        operation.get(RemoteTransportDefinition.SOCKET_BINDING.getName()).set(socketBinding);
                    }
                    generic = true;
                    break;
                }
            case NETTY_ACCEPTOR:
                {
                    operation.get(OP_ADDR).set(acceptorAddress.add(REMOTE_ACCEPTOR, name));
                    if (socketBinding == null) {
                        throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.SOCKET_BINDING));
                    }
                    operation.get(RemoteTransportDefinition.SOCKET_BINDING.getName()).set(socketBinding);
                    break;
                }
            case IN_VM_ACCEPTOR:
                {
                    operation.get(OP_ADDR).set(acceptorAddress.add(IN_VM_ACCEPTOR, name));
                    if (serverId != null) {
                        InVMTransportDefinition.SERVER_ID.parseAndSetParameter(serverId, operation, reader);
                    }
                    break;
                }
            default:
                {
                    throw ParseUtils.unexpectedElement(reader);
                }
        }
        updates.add(operation);
        parseTransportConfiguration(reader, operation, generic, updates);
    }
}
Also used : ParseUtils.requireSingleAttribute(org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) 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) ModelNode(org.jboss.dmr.ModelNode)

Example 5 with ParseUtils.unexpectedAttribute

use of org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute in project wildfly by wildfly.

the class MessagingSubsystemParser method parseSecurityRoles.

private void parseSecurityRoles(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> operations) throws XMLStreamException {
    final Map<String, Set<AttributeDefinition>> permsByRole = new HashMap<String, Set<AttributeDefinition>>();
    String localName = null;
    do {
        reader.nextTag();
        localName = reader.getLocalName();
        final Element element = Element.forName(localName);
        if (element != Element.PERMISSION_ELEMENT_NAME) {
            break;
        }
        final Set<Attribute> required = EnumSet.of(Attribute.ROLES_ATTR_NAME, Attribute.TYPE_ATTR_NAME);
        List<String> roles = null;
        AttributeDefinition perm = null;
        final int count = reader.getAttributeCount();
        for (int i = 0; i < count; i++) {
            requireNoNamespaceAttribute(reader, i);
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            required.remove(attribute);
            switch(attribute) {
                case ROLES_ATTR_NAME:
                    roles = parseRolesAttribute(reader, i);
                    break;
                case TYPE_ATTR_NAME:
                    perm = SecurityRoleDefinition.ROLE_ATTRIBUTES_BY_XML_NAME.get(reader.getAttributeValue(i));
                    if (perm == null) {
                        throw ControllerLogger.ROOT_LOGGER.invalidAttributeValue(reader.getAttributeValue(i), reader.getAttributeName(i), SecurityRoleDefinition.ROLE_ATTRIBUTES_BY_XML_NAME.keySet(), reader.getLocation());
                    }
                    break;
                default:
                    throw ParseUtils.unexpectedAttribute(reader, i);
            }
        }
        if (!required.isEmpty()) {
            throw missingRequired(reader, required);
        }
        for (String role : roles) {
            role = role.trim();
            Set<AttributeDefinition> perms = permsByRole.get(role);
            if (perms == null) {
                perms = new HashSet<AttributeDefinition>();
                permsByRole.put(role, perms);
            }
            perms.add(perm);
        }
        // Scan to element end
        reader.discardRemainder();
    } while (reader.hasNext());
    for (Map.Entry<String, Set<AttributeDefinition>> entry : permsByRole.entrySet()) {
        final String role = entry.getKey();
        final Set<AttributeDefinition> perms = entry.getValue();
        final ModelNode addr = address.clone();
        addr.add(ROLE, role);
        final ModelNode operation = new ModelNode();
        operation.get(OP).set(ADD);
        operation.get(OP_ADDR).set(addr);
        for (AttributeDefinition perm : SecurityRoleDefinition.ATTRIBUTES) {
            operation.get(perm.getName()).set(perms.contains(perm));
        }
        operations.add(operation);
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ParseUtils.requireSingleAttribute(org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) 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) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)5 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)5 ModelNode (org.jboss.dmr.ModelNode)5 ParseUtils.readStringAttributeElement (org.jboss.as.controller.parsing.ParseUtils.readStringAttributeElement)4 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)4 ParseUtils.requireSingleAttribute (org.jboss.as.controller.parsing.ParseUtils.requireSingleAttribute)4 ParseUtils.unexpectedEndElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedEndElement)4 HashSet (java.util.HashSet)2 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 ListAttributeDefinition (org.jboss.as.controller.ListAttributeDefinition)1 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)1 Attribute (org.jboss.as.controller.parsing.Attribute)1 Element (org.jboss.as.controller.parsing.Element)1 ParseUtils.isNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.isNoNamespaceAttribute)1 ParseUtils.nextElement (org.jboss.as.controller.parsing.ParseUtils.nextElement)1