Search in sources :

Example 1 with FeaturePackDepsConfigBuilder

use of org.jboss.galleon.config.FeaturePackDepsConfigBuilder in project galleon by wildfly.

the class ProvisioningXmlParser30 method doReadFeaturePackDep.

private static void doReadFeaturePackDep(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> builder, boolean transitive) throws XMLStreamException {
    FeaturePackLocation location = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i).getLocalPart());
        switch(attribute) {
            case LOCATION:
                location = parseFpl(reader, i);
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    if (location == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.LOCATION));
    }
    location = resolveUniverse(builder, location);
    String origin = null;
    final FeaturePackConfig.Builder depBuilder = transitive ? FeaturePackConfig.transitiveBuilder(location) : FeaturePackConfig.builder(location);
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                {
                    try {
                        builder.addFeaturePackDep(origin, depBuilder.build());
                    } catch (ProvisioningDescriptionException e) {
                        final StringBuilder buf = new StringBuilder();
                        buf.append("Failed to add ").append(location).append(" as a ");
                        if (transitive) {
                            buf.append("transitive ");
                        }
                        buf.append(" feature-pack dependency");
                        throw new XMLStreamException(ParsingUtils.error(buf.toString(), reader.getLocation()), e);
                    }
                    return;
                }
            case XMLStreamConstants.START_ELEMENT:
                {
                    final Element element = Element.of(reader.getName().getLocalPart());
                    switch(element) {
                        case PACKAGES:
                            try {
                                FeaturePackPackagesConfigParser10.readPackages(reader, depBuilder);
                            } catch (ProvisioningDescriptionException e) {
                                throw new XMLStreamException("Failed to parse " + Element.PACKAGES.getLocalName() + ": " + e.getLocalizedMessage(), reader.getLocation(), e);
                            }
                            break;
                        case ORIGIN:
                            origin = reader.getElementText();
                            break;
                        case DEFAULT_CONFIGS:
                            ProvisioningXmlParser30.parseDefaultConfigs(reader, depBuilder);
                            break;
                        case CONFIG:
                            final ConfigModel.Builder config = ConfigModel.builder();
                            ConfigXml.readConfig(reader, config);
                            try {
                                depBuilder.addConfig(config.build());
                            } catch (ProvisioningDescriptionException e) {
                                throw new XMLStreamException("Failed to parse config element", reader.getLocation(), e);
                            }
                            break;
                        case PATCHES:
                            readPatches(reader, depBuilder, builder);
                            break;
                        default:
                            throw ParsingUtils.unexpectedContent(reader);
                    }
                    break;
                }
            default:
                {
                    throw ParsingUtils.unexpectedContent(reader);
                }
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FeaturePackDepsConfigBuilder(org.jboss.galleon.config.FeaturePackDepsConfigBuilder) ConfigCustomizationsBuilder(org.jboss.galleon.config.ConfigCustomizationsBuilder) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) ProvisioningDescriptionException(org.jboss.galleon.ProvisioningDescriptionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)1 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)1 ConfigCustomizationsBuilder (org.jboss.galleon.config.ConfigCustomizationsBuilder)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 FeaturePackDepsConfigBuilder (org.jboss.galleon.config.FeaturePackDepsConfigBuilder)1 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)1