Java Code Examples for org.jboss.staxmapper.XMLExtendedStreamReader#getListAttributeValue()

The following examples show how to use org.jboss.staxmapper.XMLExtendedStreamReader#getListAttributeValue() . 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: CommonXml.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void parseSchemaLocations(final XMLExtendedStreamReader reader, final ModelNode address,
                                    final List<ModelNode> updateList, final int idx) throws XMLStreamException {
    final List<String> elements = reader.getListAttributeValue(idx);
    final List<String> values = new ArrayList<String>();
    for (String element : elements) {
        if (!element.trim().isEmpty()) {
            values.add(element);
        }
    }
    if ((values.size() & 1) != 0) {
        throw invalidAttributeValue(reader, idx);
    }
    final Iterator<String> it = values.iterator();
    while (it.hasNext()) {
        String key = it.next();
        String val = it.next();
        if (key.length() > 0 && val.length() > 0) {
            updateList.add(SchemaLocationAddHandler.getAddSchemaLocationOperation(address, key, val));
        }
    }
}
 
Example 2
Source File: ManagementXml_4.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseLdapConnection(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
        throws XMLStreamException {

    final ModelNode add = new ModelNode();
    add.get(OP).set(ADD);

    list.add(add);

    ModelNode connectionAddress = null;

    Set<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.URL);
    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));
            required.remove(attribute);
            switch (attribute) {
                case NAME: {
                    connectionAddress = address.clone().add(LDAP_CONNECTION, value);
                    add.get(OP_ADDR).set(connectionAddress);
                    break;
                }
                case URL: {
                    LdapConnectionResourceDefinition.URL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SEARCH_DN: {
                    LdapConnectionResourceDefinition.SEARCH_DN.parseAndSetParameter(value,  add, reader);
                    break;
                }
                case SEARCH_CREDENTIAL: {
                    LdapConnectionResourceDefinition.SEARCH_CREDENTIAL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SECURITY_REALM: {
                    LdapConnectionResourceDefinition.SECURITY_REALM.parseAndSetParameter(value, add, reader);
                    break;
                }
                case INITIAL_CONTEXT_FACTORY: {
                    LdapConnectionResourceDefinition.INITIAL_CONTEXT_FACTORY.parseAndSetParameter(value, add, reader);
                    break;
                }
                case REFERRALS: {
                    LdapConnectionResourceDefinition.REFERRALS.parseAndSetParameter(value, add, reader);
                    break;
                }
                case HANDLES_REFERRALS_FOR: {
                    for (String url : reader.getListAttributeValue(i)) {
                        LdapConnectionResourceDefinition.HANDLES_REFERRALS_FOR.parseAndAddParameterElement(url, add, reader);
                    }
                    break;
                }
                default: {
                    throw unexpectedAttribute(reader, i);
                }
            }
        }
    }

    if (required.size() > 0) {
        throw missingRequired(reader, required);
    }

    boolean propertiesFound = false;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);

        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PROPERTIES: {
                if (propertiesFound) {
                    throw unexpectedElement(reader);
                }
                propertiesFound = true;
                parseLdapConnectionProperties(reader, connectionAddress, list);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
}
 
Example 3
Source File: ManagementXml_4.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseKeyTab(final XMLExtendedStreamReader reader,
        final ModelNode parentAddress, final List<ModelNode> list) throws XMLStreamException {

    ModelNode keytab = new ModelNode();
    keytab.get(OP).set(ADD);
    list.add(keytab);

    Set<Attribute> requiredAttributes = EnumSet.of(Attribute.PRINCIPAL, Attribute.PATH);
    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));
            requiredAttributes.remove(attribute);
            switch (attribute) {
                case PRINCIPAL:
                    keytab.get(OP_ADDR).set(parentAddress).add(KEYTAB, value);
                    break;
                case PATH:
                    KeytabResourceDefinition.PATH.parseAndSetParameter(value, keytab, reader);
                    break;
                case RELATIVE_TO:
                    KeytabResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, keytab, reader);
                    break;
                case FOR_HOSTS:
                    for (String host : reader.getListAttributeValue(i)) {
                        KeytabResourceDefinition.FOR_HOSTS.parseAndAddParameterElement(host, keytab, reader);
                    }
                    break;
                case DEBUG:
                    KeytabResourceDefinition.DEBUG.parseAndSetParameter(value, keytab, reader);
                    break;
                default:
                    throw unexpectedAttribute(reader, i);

            }
        }
    }

    // This would pick up if the address for the operation has not yet been set.
    if (requiredAttributes.isEmpty() == false) {
        throw missingRequired(reader, requiredAttributes);
    }

    requireNoContent(reader);

}
 
Example 4
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseLdapConnection(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
        throws XMLStreamException {

    final ModelNode add = new ModelNode();
    add.get(OP).set(ADD);

    list.add(add);

    ModelNode connectionAddress = null;

    Set<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.URL);
    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));
            required.remove(attribute);
            switch (attribute) {
                case NAME: {
                    connectionAddress = address.clone().add(LDAP_CONNECTION, value);
                    add.get(OP_ADDR).set(connectionAddress);
                    break;
                }
                case URL: {
                    LdapConnectionResourceDefinition.URL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SEARCH_DN: {
                    LdapConnectionResourceDefinition.SEARCH_DN.parseAndSetParameter(value,  add, reader);
                    break;
                }
                case SEARCH_CREDENTIAL: {
                    LdapConnectionResourceDefinition.SEARCH_CREDENTIAL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SECURITY_REALM: {
                    LdapConnectionResourceDefinition.SECURITY_REALM.parseAndSetParameter(value, add, reader);
                    break;
                }
                case INITIAL_CONTEXT_FACTORY: {
                    LdapConnectionResourceDefinition.INITIAL_CONTEXT_FACTORY.parseAndSetParameter(value, add, reader);
                    break;
                }
                case REFERRALS: {
                    LdapConnectionResourceDefinition.REFERRALS.parseAndSetParameter(value, add, reader);
                    break;
                }
                case HANDLES_REFERRALS_FOR: {
                    for (String url : reader.getListAttributeValue(i)) {
                        LdapConnectionResourceDefinition.HANDLES_REFERRALS_FOR.parseAndAddParameterElement(url, add, reader);
                    }
                    break;
                }
                case ALWAYS_SEND_CLIENT_CERT: {
                    LdapConnectionResourceDefinition.ALWAYS_SEND_CLIENT_CERT.parseAndSetParameter(value,  add, reader);
                    break;
                }
                default: {
                    throw unexpectedAttribute(reader, i);
                }
            }
        }
    }

    if (required.size() > 0) {
        throw missingRequired(reader, required);
    }

    boolean propertiesFound = false;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);

        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PROPERTIES: {
                if (propertiesFound) {
                    throw unexpectedElement(reader);
                }
                propertiesFound = true;
                parseLdapConnectionProperties(reader, connectionAddress, list);
                break;
            }
            case SEARCH_CREDENTIAL_REFERENCE: {
                LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE.getParser().parseElement(LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE, reader, add);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
}
 
Example 5
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseKeyTab(final XMLExtendedStreamReader reader,
        final ModelNode parentAddress, final List<ModelNode> list) throws XMLStreamException {

    ModelNode keytab = new ModelNode();
    keytab.get(OP).set(ADD);
    list.add(keytab);

    Set<Attribute> requiredAttributes = EnumSet.of(Attribute.PRINCIPAL, Attribute.PATH);
    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));
            requiredAttributes.remove(attribute);
            switch (attribute) {
                case PRINCIPAL:
                    keytab.get(OP_ADDR).set(parentAddress).add(KEYTAB, value);
                    break;
                case PATH:
                    KeytabResourceDefinition.PATH.parseAndSetParameter(value, keytab, reader);
                    break;
                case RELATIVE_TO:
                    KeytabResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, keytab, reader);
                    break;
                case FOR_HOSTS:
                    for (String host : reader.getListAttributeValue(i)) {
                        KeytabResourceDefinition.FOR_HOSTS.parseAndAddParameterElement(host, keytab, reader);
                    }
                    break;
                case DEBUG:
                    KeytabResourceDefinition.DEBUG.parseAndSetParameter(value, keytab, reader);
                    break;
                default:
                    throw unexpectedAttribute(reader, i);

            }
        }
    }

    // This would pick up if the address for the operation has not yet been set.
    if (requiredAttributes.isEmpty() == false) {
        throw missingRequired(reader, requiredAttributes);
    }

    requireNoContent(reader);

}
 
Example 6
Source File: ManagementXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseLdapConnection_1_6_and_2_1(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
        throws XMLStreamException {

    final ModelNode add = new ModelNode();
    add.get(OP).set(ADD);

    list.add(add);

    ModelNode connectionAddress = null;

    Set<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.URL);
    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));
            required.remove(attribute);
            switch (attribute) {
                case NAME: {
                    connectionAddress = address.clone().add(LDAP_CONNECTION, value);
                    add.get(OP_ADDR).set(connectionAddress);
                    break;
                }
                case URL: {
                    LdapConnectionResourceDefinition.URL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SEARCH_DN: {
                    LdapConnectionResourceDefinition.SEARCH_DN.parseAndSetParameter(value,  add, reader);
                    break;
                }
                case SEARCH_CREDENTIAL: {
                    LdapConnectionResourceDefinition.SEARCH_CREDENTIAL.parseAndSetParameter(value, add, reader);
                    break;
                }
                case SECURITY_REALM: {
                    LdapConnectionResourceDefinition.SECURITY_REALM.parseAndSetParameter(value, add, reader);
                    break;
                }
                case INITIAL_CONTEXT_FACTORY: {
                    LdapConnectionResourceDefinition.INITIAL_CONTEXT_FACTORY.parseAndSetParameter(value, add, reader);
                    break;
                }
                case REFERRALS: {
                    LdapConnectionResourceDefinition.REFERRALS.parseAndSetParameter(value, add, reader);
                    break;
                }
                case HANDLES_REFERRALS_FOR: {
                    for (String url : reader.getListAttributeValue(i)) {
                        LdapConnectionResourceDefinition.HANDLES_REFERRALS_FOR.parseAndAddParameterElement(url, add, reader);
                    }
                    break;
                }
                default: {
                    throw unexpectedAttribute(reader, i);
                }
            }
        }
    }

    if (required.size() > 0) {
        throw missingRequired(reader, required);
    }

    boolean propertiesFound = false;
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        requireNamespace(reader, namespace);

        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case PROPERTIES: {
                if (propertiesFound) {
                    throw unexpectedElement(reader);
                }
                propertiesFound = true;
                parseLdapConnectionProperties(reader, connectionAddress, list);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
}
 
Example 7
Source File: ManagementXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseKeyTab(final XMLExtendedStreamReader reader,
        final ModelNode parentAddress, final List<ModelNode> list) throws XMLStreamException {

    ModelNode keytab = new ModelNode();
    keytab.get(OP).set(ADD);
    list.add(keytab);

    Set<Attribute> requiredAttributes = EnumSet.of(Attribute.PRINCIPAL, Attribute.PATH);
    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));
            requiredAttributes.remove(attribute);
            switch (attribute) {
                case PRINCIPAL:
                    keytab.get(OP_ADDR).set(parentAddress).add(KEYTAB, value);
                    break;
                case PATH:
                    KeytabResourceDefinition.PATH.parseAndSetParameter(value, keytab, reader);
                    break;
                case RELATIVE_TO:
                    KeytabResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, keytab, reader);
                    break;
                case FOR_HOSTS:
                    for (String host : reader.getListAttributeValue(i)) {
                        KeytabResourceDefinition.FOR_HOSTS.parseAndAddParameterElement(host, keytab, reader);
                    }
                    break;
                case DEBUG:
                    KeytabResourceDefinition.DEBUG.parseAndSetParameter(value, keytab, reader);
                    break;
                default:
                    throw unexpectedAttribute(reader, i);

            }
        }
    }

    // This would pick up if the address for the operation has not yet been set.
    if (requiredAttributes.isEmpty() == false) {
        throw missingRequired(reader, requiredAttributes);
    }

    requireNoContent(reader);

}
 
Example 8
Source File: ParseUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Read an element which contains only a single list attribute of a given
 * type.
 * @param reader the reader
 * @param attributeName the attribute name, usually "value"
 * @param type the value type class
 * @param <T> the value type
 * @return the value list
 * @throws javax.xml.stream.XMLStreamException if an error occurs or if the
 *         element does not contain the specified attribute, contains other
 *         attributes, or contains child elements.
 */
@SuppressWarnings({"unchecked", "WeakerAccess"})
public static <T> List<T> readListAttributeElement(final XMLExtendedStreamReader reader, final String attributeName,
        final Class<T> type) throws XMLStreamException {
    requireSingleAttribute(reader, attributeName);
    // todo: fix this when this method signature is corrected
    final List<T> value = (List<T>) reader.getListAttributeValue(0, type);
    requireNoContent(reader);
    return value;
}