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

The following examples show how to use org.jboss.staxmapper.XMLExtendedStreamReader#getLocation() . 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: CliConfigImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void readDefaultProtocol_2_0(XMLExtendedStreamReader reader, Namespace expectedNs, CliConfigImpl config)
        throws XMLStreamException {
    final int attributes = reader.getAttributeCount();
    for (int i = 0; i < attributes; i++) {
        String namespace = reader.getAttributeNamespace(i);
        String localName = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        if (namespace != null && !namespace.equals("")) {
            throw new XMLStreamException("Unexpected attribute '" + namespace + ":" + localName + "'",
                    reader.getLocation());
        } else if (localName.equals(USE_LEGACY_OVERRIDE)) {
            config.useLegacyOverride = Boolean.parseBoolean(value);
        } else {
            throw new XMLStreamException("Unexpected attribute '" + localName + "'", reader.getLocation());
        }
    }

    final String resolved = resolveString(reader.getElementText());
    if (resolved != null && resolved.length() > 0) {
        config.defaultControllerProtocol = resolved;
    }
}
 
Example 2
Source File: VaultConfig.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * In the 3.0 xsd the vault configuration and its options are part of the vault xsd.
 *
 * @param reader the reader at the vault element
 * @param expectedNs the namespace
 * @return the vault configuration
 */
static VaultConfig readVaultElement_3_0(XMLExtendedStreamReader reader, Namespace expectedNs) throws XMLStreamException {
    final VaultConfig config = new VaultConfig();

    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        String name = reader.getAttributeLocalName(i);
        if (name.equals(CODE)){
            config.code = value;
        } else if (name.equals(MODULE)){
            config.module = value;
        } else {
            unexpectedVaultAttribute(reader.getAttributeLocalName(i), reader);
        }
    }
    if (config.code == null && config.module != null){
        throw new XMLStreamException("Attribute 'module' was specified without an attribute"
                + " 'code' for element '" + VAULT + "' at " + reader.getLocation());
    }
    readVaultOptions(reader, config);
    return config;
}
 
Example 3
Source File: FeatureSpecXmlParser10.java    From galleon with Apache License 2.0 5 votes vote down vote up
private FeatureDependencySpec parseDependency(XMLExtendedStreamReader reader) throws XMLStreamException {
    String dependency = null;
    boolean include = false;
    String featureId = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case DEPENDENCY:
                dependency = reader.getAttributeValue(i);
                break;
            case FEATURE_ID:
                featureId = reader.getAttributeValue(i);
                break;
            case INCLUDE:
                include = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if(featureId == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.FEATURE_ID));
    }
    ParsingUtils.parseNoContent(reader);
    try {
        return FeatureDependencySpec.create(FeatureId.fromString(featureId), dependency, include);
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse feature dependency", reader.getLocation(), e);
    }
}
 
Example 4
Source File: FeatureSpecXmlParser10.java    From galleon with Apache License 2.0 5 votes vote down vote up
private void parseParameters(XMLExtendedStreamReader reader, FeatureSpec.Builder specBuilder) throws XMLStreamException {
    ParsingUtils.parseNoAttributes(reader);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());
                switch (element) {
                    case PARAMETER:
                        try {
                            specBuilder.addParam(parseParameter(reader));
                        } catch (ProvisioningDescriptionException e) {
                            throw new XMLStreamException("Failed to add parameter to the spec", reader.getLocation(), e);
                        }
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 5
Source File: FeatureSpecXmlParser10.java    From galleon with Apache License 2.0 5 votes vote down vote up
private FeatureParameterSpec parseParameter(XMLExtendedStreamReader reader) throws XMLStreamException {
    final FeatureParameterSpec.Builder builder = FeatureParameterSpec.builder();
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                builder.setName(reader.getAttributeValue(i));
                break;
            case FEATURE_ID:
                if(Boolean.parseBoolean(reader.getAttributeValue(i))) {
                    builder.setFeatureId();
                }
                break;
            case DEFAULT:
                builder.setDefaultValue(reader.getAttributeValue(i));
                break;
            case NILLABLE:
                if(Boolean.parseBoolean(reader.getAttributeValue(i))) {
                    builder.setNillable();
                }
                break;
            case TYPE:
                builder.setType(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if(builder.getName() == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
    }
    ParsingUtils.parseNoContent(reader);
    try {
        return builder.build();
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to create feature parameter", reader.getLocation(), e);
    }
}
 
Example 6
Source File: FeatureSpecXmlParser10.java    From galleon with Apache License 2.0 5 votes vote down vote up
private CapabilitySpec parseCapabilityName(XMLExtendedStreamReader reader) throws XMLStreamException {
    String name = null;
    boolean optional = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case OPTIONAL:
                optional = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
    }
    ParsingUtils.parseNoContent(reader);
    try {
        return CapabilitySpec.fromString(name, optional);
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse capability '" + name + "'", reader.getLocation(), e);
   }
}
 
Example 7
Source File: CliConfigImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void readControllers_2_0(XMLExtendedStreamReader reader, Namespace expectedNs, CliConfigImpl config) throws XMLStreamException {
    Map<String, ControllerAddress> aliasedAddresses = new HashMap<String, ControllerAddress>();
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        assertExpectedNamespace(reader, expectedNs);
        final String localName = reader.getLocalName();

        if (CONTROLLER.equals(localName)) {
            String name = null;
            final int attributes = reader.getAttributeCount();
            for (int i = 0; i < attributes; i++) {
                String namespace = reader.getAttributeNamespace(i);
                String attrLocalName = reader.getAttributeLocalName(i);
                String value = reader.getAttributeValue(i);

                if (namespace != null && !namespace.equals("")) {
                    throw new XMLStreamException("Unexpected attribute '" + namespace + ":" + attrLocalName + "'",
                            reader.getLocation());
                } else if (attrLocalName.equals(NAME) && name == null) {
                    name = value;
                } else {
                    throw new XMLStreamException("Unexpected attribute '" + attrLocalName + "'", reader.getLocation());
                }
            }

            if (name == null) {
                throw new XMLStreamException("Missing required attribute 'name'", reader.getLocation());
            }
            aliasedAddresses.put(name, readController(true, reader, expectedNs));
        } else {
            throw new XMLStreamException("Unexpected child of " + CONTROLLER + ": " + localName);
        }
    }

    config.controllerAliases = Collections.unmodifiableMap(aliasedAddresses);
}
 
Example 8
Source File: PackageDepsSpecXmlParser.java    From galleon with Apache License 2.0 5 votes vote down vote up
private static PackageDependencySpec parsePackageDependency(XMLExtendedStreamReader reader) throws XMLStreamException {
    String name = null;
    Boolean optional = null;
    boolean passive = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case OPTIONAL:
                optional = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            case PASSIVE:
                passive = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
    }
    ParsingUtils.parseNoContent(reader);
    if(passive) {
        if(optional != null && !optional) {
            throw new XMLStreamException(Errors.requiredPassiveDependency(name), reader.getLocation());
        }
        return PackageDependencySpec.passive(name);
    }
    return optional == null || !optional ? PackageDependencySpec.required(name) : PackageDependencySpec.optional(name);
}
 
Example 9
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readKeyStore(ModelNode addKey, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode addKeyStore = addKey.get(Constants.Model.KEY_STORE);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = KeyStoreDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKeyStore, reader);
    }

    if (!addKeyStore.hasDefined(Constants.Model.FILE) && !addKeyStore.hasDefined(Constants.Model.RESOURCE)) {
        throw new XMLStreamException("KeyStore element must have 'file' or 'resource' attribute set", reader.getLocation());
    }
    if (!addKeyStore.hasDefined(Constants.Model.PASSWORD)) {
        throw ParseUtils.missingRequired(reader, Constants.XML.PASSWORD);
    }

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the keystore type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (Constants.XML.PRIVATE_KEY.equals(tagName)) {
            readPrivateKey(reader, addKeyStore);
        } else if (Constants.XML.CERTIFICATE.equals(tagName)) {
            readCertificate(reader, addKeyStore);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 10
Source File: FeatureGroupXml.java    From galleon with Apache License 2.0 5 votes vote down vote up
private static FeatureGroup readFeatureGroupDependency(String origin, XMLExtendedStreamReader reader) throws XMLStreamException {
    String name = null;
    Boolean inheritFeatures = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                break;
            case INHERIT_FEATURES:
                inheritFeatures = Boolean.parseBoolean(reader.getAttributeValue(i));
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null && inheritFeatures != null) {
        throw new XMLStreamException(Attribute.INHERIT_FEATURES + " attribute can't be used w/o attribute " + Attribute.NAME);
    }
    final FeatureGroup.Builder depBuilder = FeatureGroup.builder(name).setOrigin(origin);
    if(inheritFeatures != null) {
        depBuilder.setInheritFeatures(inheritFeatures);
    }
    readFeatureGroupConfigBody(reader, depBuilder);
    try {
        return depBuilder.build();
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse feature group dependency", reader.getLocation(), e);
    }
}
 
Example 11
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readKeyStore(ModelNode addKey, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode addKeyStore = addKey.get(Constants.Model.KEY_STORE);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = KeyStoreDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKeyStore, reader);
    }

    if (!addKeyStore.hasDefined(Constants.Model.FILE) && !addKeyStore.hasDefined(Constants.Model.RESOURCE)) {
        throw new XMLStreamException("KeyStore element must have 'file' or 'resource' attribute set", reader.getLocation());
    }
    if (!addKeyStore.hasDefined(Constants.Model.PASSWORD)) {
        throw ParseUtils.missingRequired(reader, asSet(Constants.XML.PASSWORD));
    }

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the keystore type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (Constants.XML.PRIVATE_KEY.equals(tagName)) {
            readPrivateKey(reader, addKeyStore);
        } else if (Constants.XML.CERTIFICATE.equals(tagName)) {
            readCertificate(reader, addKeyStore);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 12
Source File: ParsingUtils.java    From galleon with Apache License 2.0 5 votes vote down vote up
public static XMLStreamException expectedAtLeastOneChild(final XMLExtendedStreamReader reader, XmlNameProvider parent, XmlNameProvider... child) {
    final StringBuilder buf = new StringBuilder("The content of element '").append(parent.getLocalName()).append("' is not complete. One of ");
    XmlNameProvider c = child[0];
    buf.append('\'').append(c.getLocalName()).append('\'');
    if(child.length > 1) {
        for(int i = 1; i < child.length; ++i) {
            buf.append(", '").append(child[i].getLocalName()).append('\'');
        }
    }
    buf.append(" is expected.");
    return new XMLStreamException(buf.toString(), reader.getLocation());
}
 
Example 13
Source File: JBossAllXMLElementReader.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void readElement(final XMLExtendedStreamReader xmlExtendedStreamReader, final JBossAllXmlParseContext jBossXmlParseContext) throws XMLStreamException {
    final Location nsLocation = xmlExtendedStreamReader.getLocation();
    final QName elementName = xmlExtendedStreamReader.getName();
    final Object result = parserDescription.getParser().parse(xmlExtendedStreamReader, jBossXmlParseContext.getDeploymentUnit());
    jBossXmlParseContext.addResult(elementName, result, nsLocation);
}
 
Example 14
Source File: FeaturePackXmlParser20.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, Builder fpBuilder) throws XMLStreamException {
    fpBuilder.setFPID(readFpl(reader).getFPID());
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName().getLocalPart());
                switch (element) {
                    case UNIVERSES:
                        ProvisioningXmlParser30.readUniverses(reader, fpBuilder);
                        break;
                    case DEPENDENCIES:
                        readFeaturePackDeps(reader, fpBuilder);
                        break;
                    case DEFAULT_CONFIGS:
                        ProvisioningXmlParser30.parseDefaultConfigs(reader, fpBuilder);
                        break;
                    case CONFIG:
                        final ConfigModel.Builder config = ConfigModel.builder();
                        ConfigXml.readConfig(reader, config);
                        try {
                            fpBuilder.addConfig(config.build());
                        } catch (ProvisioningDescriptionException e) {
                            throw new XMLStreamException("Failed to parse config element", reader.getLocation(), e);
                        }
                        break;
                    case DEFAULT_PACKAGES:
                        readDefaultPackages(reader, fpBuilder);
                        break;
                    case TRANSITIVE:
                        readTransitive(reader, fpBuilder);
                        break;
                    case PLUGINS:
                        parsePlugins(reader, fpBuilder);
                        break;
                    case PATCH:
                        parsePatchFor(reader, fpBuilder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 15
Source File: CliConfigImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void unexpectedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
    throw new XMLStreamException("Unexpected element " + reader.getName() + " at " + reader.getLocation());
}
 
Example 16
Source File: RemotingSubsystem20Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static XMLStreamException workerThreadPoolEndpointChoiceRequired(XMLExtendedStreamReader reader) {
    return new XMLStreamException(
            RemotingLogger.ROOT_LOGGER.workerThreadsEndpointConfigurationChoiceRequired(
                    Element.WORKER_THREAD_POOL.getLocalName(), Element.ENDPOINT.getLocalName()
            ), reader.getLocation());
}
 
Example 17
Source File: ConfigXml.java    From galleon with Apache License 2.0 4 votes vote down vote up
private static void readLayers(XMLExtendedStreamReader reader, ConfigModel.Builder builder) throws XMLStreamException {
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case INHERIT:
                builder.setInheritLayers(Boolean.parseBoolean(reader.getAttributeValue(i)));
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    try {
        while (reader.hasNext()) {
            switch (reader.nextTag()) {
                case XMLStreamConstants.END_ELEMENT: {
                    return;
                }
                case XMLStreamConstants.START_ELEMENT: {
                    final Element element = Element.of(reader.getName().getLocalPart());
                    switch (element) {
                        case INCLUDE:
                            builder.includeLayer(readLayer(reader, builder));
                            break;
                        case EXCLUDE:
                            builder.excludeLayer(readLayer(reader, builder));
                            break;
                        default:
                            throw ParsingUtils.unexpectedContent(reader);
                    }
                    break;
                }
                default: {
                    throw ParsingUtils.unexpectedContent(reader);
                }
            }
        }
    } catch (ProvisioningDescriptionException e) {
        throw new XMLStreamException("Failed to parse layers configuration: " + e.getMessage(), reader.getLocation());
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 18
Source File: ProvisioningXmlParser30.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, ProvisioningConfig.Builder builder) throws XMLStreamException {
    ParsingUtils.parseNoAttributes(reader);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getLocalName());
                switch (element) {
                    case UNIVERSES:
                        readUniverses(reader, builder);
                        break;
                    case FEATURE_PACK:
                        readFeaturePackDep(reader, builder);
                        break;
                    case DEFAULT_CONFIGS:
                        parseDefaultConfigs(reader, builder);
                        break;
                    case CONFIG:
                        final ConfigModel.Builder config = ConfigModel.builder();
                        ConfigXml.readConfig(reader, config);
                        try {
                            builder.addConfig(config.build());
                        } catch (ProvisioningDescriptionException e) {
                            throw new XMLStreamException("Failed to parse config element", reader.getLocation(), e);
                        }
                        break;
                    case TRANSITIVE:
                        readTransitive(reader, builder);
                        break;
                    case OPTIONS:
                        readOptions(reader, builder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 19
Source File: FeatureGroupXml.java    From galleon with Apache License 2.0 4 votes vote down vote up
private static void attributesCantBeCombined(Attribute a1, Attribute a2, XMLExtendedStreamReader reader) throws XMLStreamException {
    throw new XMLStreamException(a1 + " attribute and " + a1 + " cannot be used in combination", reader.getLocation());
}
 
Example 20
Source File: ParsingUtils.java    From galleon with Apache License 2.0 2 votes vote down vote up
public static XMLStreamException unexpectedAttribute(final XMLExtendedStreamReader reader, final int index) {
    return new XMLStreamException(String.format("Unexpected attribute '%s' encountered", reader.getAttributeName(index)), reader.getLocation());

}