Search in sources :

Example 1 with ConfigurationReader

use of org.infinispan.commons.configuration.io.ConfigurationReader in project infinispan by infinispan.

the class CacheParser method parseProperties.

public static Properties parseProperties(final ConfigurationReader reader, String outerElement, String collectionElement, String itemElement) {
    Properties properties = new Properties();
    while (reader.hasNext()) {
        ConfigurationReader.ElementType type = reader.nextElement();
        String element = reader.getLocalName();
        if (element.equals(collectionElement)) {
            // JSON/YAML map properties to attributes
            for (int i = 0; i < reader.getAttributeCount(); i++) {
                properties.setProperty(reader.getAttributeName(i), reader.getAttributeValue(i));
            }
        } else if (element.equals(itemElement)) {
            if (type == ConfigurationReader.ElementType.START_ELEMENT) {
                parseProperty(reader, properties);
            }
        } else if (type == ConfigurationReader.ElementType.END_ELEMENT && reader.getLocalName().equals(outerElement)) {
            return properties;
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
    }
    return properties;
}
Also used : Properties(java.util.Properties) ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader)

Example 2 with ConfigurationReader

use of org.infinispan.commons.configuration.io.ConfigurationReader in project infinispan by infinispan.

the class ParserRegistry method parse.

public ConfigurationBuilderHolder parse(InputStream is, ConfigurationBuilderHolder holder, ConfigurationResourceResolver resourceResolver, MediaType mediaType) {
    ConfigurationReader reader = ConfigurationReader.from(is).withResolver(resourceResolver).withType(mediaType).withProperties(properties).withNamingStrategy(NamingStrategy.KEBAB_CASE).build();
    parse(reader, holder);
    // Fire all parsingComplete events if any
    holder.fireParserListeners();
    return holder;
}
Also used : ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader)

Example 3 with ConfigurationReader

use of org.infinispan.commons.configuration.io.ConfigurationReader in project infinispan by infinispan.

the class CounterConfigurationParser method parseConfigurations.

/**
 * Reads a list of counter's configuration from an {@link InputStream}.
 *
 * @param is the {@link InputStream} to read.
 * @return a {@link List} of {@link AbstractCounterConfiguration} read.
 */
public Map<String, AbstractCounterConfiguration> parseConfigurations(InputStream is) throws IOException {
    BufferedInputStream input = new BufferedInputStream(is);
    ConfigurationReader reader = ConfigurationReader.from(input).build();
    CounterManagerConfigurationBuilder builder = new CounterManagerConfigurationBuilder(null);
    try {
        reader.require(ConfigurationReader.ElementType.START_DOCUMENT);
        reader.nextElement();
        reader.require(ConfigurationReader.ElementType.START_ELEMENT);
        Element element = Element.forName(reader.getLocalName());
        if (element != Element.COUNTERS) {
            throw ParseUtils.unexpectedElement(reader);
        }
        parseCountersElement(reader, builder);
    } finally {
        Util.close(reader);
    }
    return builder.create().counters();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader)

Example 4 with ConfigurationReader

use of org.infinispan.commons.configuration.io.ConfigurationReader in project infinispan by infinispan.

the class XmlConfiguration method setup.

@Override
public void setup() {
    final File configFile = getConfigurationSource().getFile();
    try (InputStream configStream = Files.newInputStream(configFile.toPath())) {
        ConfigurationReader reader = ConfigurationReader.from(configStream).withProperties(System.getProperties()).withReplacer((string, props) -> getStrSubstitutor().replace(string)).withType(MediaType.APPLICATION_XML).build();
        reader.require(ConfigurationReader.ElementType.START_DOCUMENT);
        reader.nextElement();
        reader.require(ConfigurationReader.ElementType.START_ELEMENT, null, "Configuration");
        parseConfiguration(reader);
        while (reader.nextElement() != ConfigurationReader.ElementType.END_DOCUMENT) {
        // consume remaining parsing events
        }
    } catch (IOException e) {
        throw new CacheConfigurationException(e);
    }
    if (status.size() > 0) {
        for (final Status s : status) {
            LOGGER.error("Error processing element {} ({}): {}", s.name, s.element, s.errorType);
        }
        return;
    }
}
Also used : InputStream(java.io.InputStream) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) IOException(java.io.IOException) File(java.io.File) ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader)

Example 5 with ConfigurationReader

use of org.infinispan.commons.configuration.io.ConfigurationReader in project infinispan by infinispan.

the class CounterResource method createCounterConfiguration.

private CounterConfiguration createCounterConfiguration(String json) {
    try (ConfigurationReader reader = ConfigurationReader.from(json).withType(APPLICATION_JSON).build()) {
        ConfigurationBuilderHolder holder = invocationHelper.getParserRegistry().parse(reader, new ConfigurationBuilderHolder());
        CounterManagerConfigurationBuilder counterModule = holder.getGlobalConfigurationBuilder().module(CounterManagerConfigurationBuilder.class);
        CounterManagerConfiguration configuration = counterModule.create();
        return ConvertUtil.parsedConfigToConfig(configuration.counters().values().iterator().next());
    }
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) CounterManagerConfigurationBuilder(org.infinispan.counter.configuration.CounterManagerConfigurationBuilder) ConfigurationReader(org.infinispan.commons.configuration.io.ConfigurationReader) CounterManagerConfiguration(org.infinispan.counter.configuration.CounterManagerConfiguration)

Aggregations

ConfigurationReader (org.infinispan.commons.configuration.io.ConfigurationReader)5 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)1 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)1 CounterManagerConfiguration (org.infinispan.counter.configuration.CounterManagerConfiguration)1 CounterManagerConfigurationBuilder (org.infinispan.counter.configuration.CounterManagerConfigurationBuilder)1