/** * A ConfigObject is a tree structure consisting of nested maps. This flattens the maps into * a single level structure like a properties file */ public Map flatten() { return flatten(null); }
/** * Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehand * * @return A java.util.Properties instance */ public Properties toProperties() { Properties props = new Properties(); flatten(props); props = convertValuesToString(props); return props; }
/** * A ConfigObject is a tree structure consisting of nested maps. This flattens the maps into * a single level structure like a properties file */ public Map flatten() { return flatten(null); }
@SuppressWarnings("unchecked") private GroovyScriptResourceBundle(@Nonnull ConfigObject config, @Nonnull String source) { this.config = requireNonNull(config, "Argument 'config' must not be null"); this.source = source; keys.addAll(this.config.flatten(new LinkedHashMap<>()).keySet()); }
@SuppressWarnings("unchecked") public static Object instantiateFromConfig(ConfigObject config, String configKey, String defaultClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException, LinkageError { return instantiateFromFlatConfig(config.flatten(), configKey, defaultClassName); }
public EventTriggeringInterceptor(HibernateDatastore datastore, ConfigObject co) { super(datastore); Object failOnErrorConfig = co.flatten().get("grails.gorm.failOnError"); if (failOnErrorConfig instanceof List) { failOnError = true; failOnErrorPackages = (List<?>)failOnErrorConfig; } else { failOnError = DefaultTypeTransformation.castToBoolean(failOnErrorConfig); } }
/** * Converts this ConfigObject into a the java.util.Properties format, flattening the tree structure beforehand * * @return A java.util.Properties instance */ public Properties toProperties() { Properties props = new Properties(); flatten(props); props = convertValuesToString(props); return props; }
ConfigObject config = new ConfigSlurper().parse(new File("configuration").toURL()); Map flattenedConfig = config.flatten(); String oracleHost = (String) flattenedConfig.get("datastore.oracle.host");
public void properties(Closure<Properties> closure) { ConfigObject config = new ConfigObject(); closure.setResolveStrategy(Closure.DELEGATE_ONLY); closure.setDelegate(config); closure.call(); config.flatten(this.properties); }
private static void createFlatConfig(ConfigObject currentConfigObject, Map<String, Object> rootConfig, String prefix) { Set keySet = currentConfigObject.keySet(); for (Object key : keySet) { Object value = currentConfigObject.get(key); if(value instanceof ConfigObject) { ConfigObject sub = ((ConfigObject) value).clone(); String fullPath = prefix + key; if(!sub.isEmpty()) { Map flattened = sub.flatten(); sub.putAll(flattened); createFlatConfig(sub, rootConfig, fullPath + "."); if(!rootConfig.containsKey(fullPath)) { rootConfig.put(fullPath, sub); } } } else { rootConfig.put(prefix + key, value); } } }
if(co == null || co.flatten().isEmpty()){ throw new ConnectorException(MessageFormat.format("No properties read from classpath with prefix [{0}] ",prefix));
if(co == null || co.flatten().isEmpty()){ throw new ConnectorException(MessageFormat.format("No properties read from classpath with prefix [{0}] ",prefix));
if(co == null || co.flatten().isEmpty()){ throw new ConnectorException(MessageFormat.format("No properties read from classpath with prefix [{0}] ",prefix));
ConfigObject configObject = configSlurper.parse(properties); ConfigObject flatConfigObject = new ConfigObject(); configObject.flatten(flatConfigObject); flatConfigObject.merge(configObject); propertySources.addFirst(new ConfigObjectPropertySource(DATASTORE_CONFIG + i, configObject));