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;
}
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;
}
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();
}
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;
}
}
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());
}
}
Aggregations