List of usage examples for org.apache.commons.configuration SubnodeConfiguration getSubnodeKey
public String getSubnodeKey()
From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java
private static String[] getStringArray(SubnodeConfiguration section, String key) { try {/*from ww w. j a va2 s . c om*/ return section.getStringArray(key); } catch (ConversionException e) { throw new ConversionException(String.format("Invalid value of '%s' for module (%s), skipping...", key, section.getSubnodeKey()), e); } }
From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java
private static Boolean getBoolean(SubnodeConfiguration section, String key, Boolean defaultValue) { try {//from w w w .jav a 2 s . co m return section.getBoolean(key, defaultValue); } catch (ConversionException e) { throw new ConversionException(String.format("Invalid value of '%s' for module (%s), skipping...", key, section.getSubnodeKey()), e); } }
From source file:ee.ria.xroad.signer.tokenmanager.module.ModuleConf.java
private static Set<Long> loadAllowedKeyUsageMechanisms(SubnodeConfiguration section, String key) { Set<Long> allowedMechanism = new HashSet<>(); String[] mechanisms = getStringArray(section, key); for (String m : mechanisms) { Long mechamism = SUPPORTED_KEY_ALLOWED_MECHANISMS.get(StringUtils.strip(m)); if (mechamism != null) { allowedMechanism.add(mechamism); } else {//from w w w. ja v a 2s . c o m throw new ConfigurationRuntimeException( String.format("Unsupported value '%s' of '%s' for module (%s), skipping...", m, key, section.getSubnodeKey())); } } return allowedMechanism; }
From source file:com.github.steveash.typedconfig.resolver.type.container.AbstractContainerValueResolverFactory.java
@Override public ValueResolver makeForThis(final ConfigBinding containerBinding, final HierarchicalConfiguration config, final ConfigFactoryContext context) { return new ValueResolver() { @Override//from w ww . j a v a2 s . c o m public Object resolve() { TypeToken<?> thisType = getContainedType(containerBinding.getDataType()); ConfigBinding childBinding = containerBinding.withKey("").withDataType(thisType) .withOptions(Option.EmptyOptions); ValueResolverFactory childFactory = context.getRegistry().lookup(childBinding); switch (childFactory.getValueType()) { case Simple: return makeForSimpleType(childBinding, childFactory); case Nested: return makeForNestedType(childBinding, childFactory); default: throw new InvalidProxyException("The proxy method returning " + containerBinding.getDataType() + " for configuration key " + containerBinding.getConfigKeyToLookup() + " uses a container type " + "which returns " + thisType + " which is also a container type. You can't have " + "containers of container types."); } } private Object makeForNestedType(ConfigBinding childBinding, ValueResolverFactory childFactory) { List<HierarchicalConfiguration> childConfigs = config .configurationsAt(containerBinding.getConfigKeyToLookup()); Collection<Object> values = makeEmptyCollection(childConfigs.size()); for (HierarchicalConfiguration childConfig : childConfigs) { SubnodeConfiguration childConfigAsSub = (SubnodeConfiguration) childConfig; ConfigBinding subBinding = childBinding.withKey(childConfigAsSub.getSubnodeKey()); ValueResolver r = childFactory.makeForThis(subBinding, childConfig, context); values.add(r.resolve()); } return makeReturnValueFrom(values, containerBinding); } private Object makeForSimpleType(ConfigBinding childBinding, ValueResolverFactory childFactory) { ValueResolver childResolver = childFactory.makeForThis(childBinding, config, context); List<Object> configValues = config.getList(containerBinding.getConfigKeyToLookup()); Collection<Object> containedValues = makeEmptyCollection(configValues.size()); for (Object o : configValues) { if (!(o instanceof String)) throw new IllegalArgumentException( "Can only use Configuration instances which return string " + "representations of the values which we will then convert. XMLConfiguration does this"); containedValues.add(childResolver.convertDefaultValue((String) o)); } return makeReturnValueFrom(containedValues, containerBinding); } @Override public Object convertDefaultValue(String defaultValue) { throw new IllegalStateException("cannot specify a defaults for container types"); } @Override public String configurationKeyToLookup() { return containerBinding.getConfigKeyToLookup(); } }; }
From source file:com.github.steveash.typedconfig.ConfigFactoryContext.java
/** * Produces a resolver that knows how to deal with the given binding for the given config; does not * use any decorators or anything just the binding and the value type for the factory that is chosen * by the registry//www.jav a2 s.com * * * @param config * @param newMethodBinding *@param parentBinding @return */ public ValueResolver makeResolverForBinding(HierarchicalConfiguration config, ConfigBinding newMethodBinding, ConfigBinding parentBinding) { ValueResolverFactory factory = getRegistry().lookup(newMethodBinding); switch (factory.getValueType()) { case Container: case Simple: return factory.makeForThis(newMethodBinding, config, this); case Nested: Preconditions.checkNotNull(parentBinding); // config points to the location of the nested context SubnodeConfiguration subConfig = config.configurationAt(newMethodBinding.getConfigKeyToLookup(), true); ConfigBinding subBinding = newMethodBinding.withKey(subConfig.getSubnodeKey()); return factory.makeForThis(subBinding, subConfig, this); default: throw new IllegalArgumentException("dont know how to handle value type: " + factory.getValueType()); } }