Examples of ConfigValue


Examples of com.typesafe.config.ConfigValue

        return getNumber(path).doubleValue();
    }

    @Override
    public String getString(String path) {
        ConfigValue v = find(path, ConfigValueType.STRING);
        return (String) v.unwrapped();
    }
View Full Code Here

Examples of com.typesafe.config.ConfigValue

        return getObject(path).toConfig();
    }

    @Override
    public Object getAnyRef(String path) {
        ConfigValue v = find(path, null);
        return v.unwrapped();
    }
View Full Code Here

Examples of com.typesafe.config.ConfigValue

    public Long getBytes(String path) {
        Long size = null;
        try {
            size = getLong(path);
        } catch (ConfigException.WrongType e) {
            ConfigValue v = find(path, ConfigValueType.STRING);
            size = parseBytes((String) v.unwrapped(),
                    v.origin(), path);
        }
        return size;
    }
View Full Code Here

Examples of com.typesafe.config.ConfigValue

        return getDuration(path, TimeUnit.NANOSECONDS);
    }

    @Override
    public long getDuration(String path, TimeUnit unit) {
        ConfigValue v = find(path, ConfigValueType.STRING);
        long result = unit.convert(
                       parseDuration((String) v.unwrapped(), v.origin(), path),
                       TimeUnit.NANOSECONDS);
        return result;
    }
View Full Code Here

Examples of com.typesafe.config.ConfigValue

    @Override
    public AbstractConfigValue withFallback(ConfigMergeable mergeable) {
        if (ignoresFallbacks()) {
            return this;
        } else {
            ConfigValue other = ((MergeableValue) mergeable).toFallbackValue();

            if (other instanceof Unmergeable) {
                return mergedWithTheUnmergeable((Unmergeable) other);
            } else if (other instanceof AbstractConfigObject) {
                return mergedWithObject((AbstractConfigObject) other);
View Full Code Here

Examples of com.typesafe.config.ConfigValue

        Class<?> expectedType = field.getType();
        String fieldName = field.getName();
        if ((config == null) || !config.hasPath(fieldName)) {
            return null;
        } else if (field.isArray()) { // check CodableFieldInfo instead of expectedType
            ConfigValue configValue = config.root().get(fieldName);
            if ((configValue.valueType() != ConfigValueType.LIST) &&
                field.autoArrayEnabled()) {
                Object singleArrayValue = hydrateField(expectedType, fieldName, config);
                Object wrappingArray    = Array.newInstance(expectedType, 1);
                Array.set(wrappingArray, 0, singleArrayValue);
                return wrappingArray;
View Full Code Here

Examples of com.typesafe.config.ConfigValue

    private <T> T hydrateObject(@Nullable CodableClassInfo info,
                                PluginMap pluginMap,
                                @Nullable Class<T> type,
                                ConfigObject configObject) {
        String classField = pluginMap.classField();
        ConfigValue typeValue = configObject.get(classField);
        String stype = null;
        if ((typeValue != null) && (typeValue.valueType() == ConfigValueType.STRING)) {
            stype = (String) typeValue.unwrapped();
        }
        // if otherwise doomed to fail, try supporting "type-value : {...}"  syntax
        if ((stype == null) && (configObject.size() == 1) &&
            ((type == null) || Modifier.isAbstract(type.getModifiers()) ||
             Modifier.isInterface(type.getModifiers()))) {
View Full Code Here

Examples of com.typesafe.config.ConfigValue

      
       Map<String, String> keys = new HashMap<>();
       Map<String, ExtractConfiguration> sub = new HashMap<>();
      
       private static List<String> getStringList(Config c, String key) {
         ConfigValue v = c.getValue(key);
         if (v.valueType() == ConfigValueType.LIST) {
           List<String> l = c.getStringList(key);
           if (l.isEmpty()) {
             throw new RuntimeException("Cannot be empty: " + key);
           }
           return l;
View Full Code Here

Examples of com.typesafe.config.ConfigValue

            // different from hasPath in that this will accept ConfigValueType.NULL
            return config.root().get(fieldName);
        } else if (!config.hasPath(fieldName)) {
            return null;
        } else if (field.isArray()) { // check CodableFieldInfo instead of expectedType
            ConfigValue configValue = config.root().get(fieldName);
            if ((configValue.valueType() != ConfigValueType.LIST) &&
                field.autoArrayEnabled()) {
                Object singleArrayValue = hydrateFieldComponent(expectedType, fieldName, config);
                Object wrappingArray    = Array.newInstance(expectedType, 1);
                Array.set(wrappingArray, 0, singleArrayValue);
                return wrappingArray;
View Full Code Here

Examples of com.typesafe.config.ConfigValue

            String singleKeyName = configObject.keySet().iterator().next();
            try {
                Class<T> singleKeyType = (Class<T>) pluginMap.getClass(singleKeyName);
                CodableClassInfo singleKeyInfo = getOrCreateClassInfo(singleKeyType);
                ConfigObject aliasDefaults = pluginMap.aliasDefaults(singleKeyName);
                ConfigValue configValue = configObject.get(singleKeyName);
                if (configValue.valueType() != ConfigValueType.OBJECT) {
                    if (aliasDefaults.get("_primary") != null) {
                        // if value is not an object, try supporting _primary syntax to derive one
                        configValue = configValue.atPath((String) aliasDefaults.get("_primary").unwrapped()).root();
                    } else if (ValueCodable.class.isAssignableFrom(singleKeyType)) {
                        // see if the resolved type is innately okay with non-objects
                        try {
                            T objectShell = singleKeyType.newInstance();
                            Config fieldDefaults = singleKeyInfo.getFieldDefaults();
                            // do not merge objects between global defaults and user defaults (incl. alias defaults)
                            ConfigObject mergedDefaults = aliasDefaults;
                            for (Map.Entry<String, ConfigValue> pair : fieldDefaults.entrySet()) {
                                if (!mergedDefaults.containsKey(pair.getKey())) {
                                    mergedDefaults = mergedDefaults.withValue(pair.getKey(), pair.getValue());
                                }
                            }
                            ((ValueCodable) objectShell).fromConfigValue(configValue, mergedDefaults);
                            return objectShell;
                        } catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
                            throw new ConfigException.BadValue(configValue.origin(), singleKeyType.getName(),
                                                               "exception during instantiation of a ValueCodable", ex);
                        }
                    } else {
                        throw new ConfigException.WrongType(configValue.origin(), singleKeyName,
                                                            "OBJECT", configValue.valueType().toString());
                    }
                }
                ConfigObject fieldValues = ((ConfigObject) configValue).withFallback(aliasDefaults);
                return createAndPopulate(singleKeyInfo, singleKeyType, fieldValues);
            } catch (ClassNotFoundException ignored) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.