Package org.constretto.model

Examples of org.constretto.model.ConfigurationValue


        }
        return null != value ? value : defaultValue;
    }

    public <T> T evaluateWith(GenericConverter<T> converter, String expression) {
        ConfigurationValue value = findElementOrThrowException(expression);
        return converter.fromValue(value.value());
    }
View Full Code Here


        return findElementOrThrowException(expression).value();
    }

    @SuppressWarnings("unchecked")
    public <K> List<K> evaluateToList(Class<K> targetClass, String expression) {
        ConfigurationValue value = findElementOrThrowException(expression);
        return (List<K>) ValueConverterRegistry.convert(targetClass, targetClass, value.value());
    }
View Full Code Here

        return (List<K>) ValueConverterRegistry.convert(targetClass, targetClass, value.value());
    }

    @SuppressWarnings("unchecked")
    public <K, V> Map<K, V> evaluateToMap(Class<K> keyClass, Class<V> valueClass, String expression) {
        ConfigurationValue value = findElementOrThrowException(expression);
        return (Map<K, V>) ValueConverterRegistry.convert(valueClass, keyClass, value.value());
    }
View Full Code Here

    }

    public Map<String, String> asMap() {
        Map<String, String> properties = new HashMap<String, String>();
        for (Map.Entry<String, List<ConfigurationValue>> entry : configuration.entrySet()) {
            ConfigurationValue value = findElementOrNull(entry.getKey());
            if (value != null){
                properties.put(entry.getKey(), value.value().toString());
            }
        }
        return properties;
    }
View Full Code Here

    protected ConfigurationValue findElementOrThrowException(String expression) {
        if (!configuration.containsKey(expression)) {
            throw new ConstrettoExpressionException(expression, currentTags);
        }
        List<ConfigurationValue> values = configuration.get(expression);
        ConfigurationValue resolvedNode = resolveMatch(values);
        if (resolvedNode == null) {
            throw new ConstrettoExpressionException(expression, currentTags);
        }
        if (resolvedNode.value().containsVariables()) {
            for (String key : resolvedNode.value().referencedKeys()) {
                resolvedNode.value().replace(key, evaluateToString(key));
            }
        }
        return resolvedNode;
    }
View Full Code Here

    protected ConfigurationValue findElementOrNull(String expression) {
        if (!configuration.containsKey(expression)) {
            return null;
        }
        List<ConfigurationValue> values = configuration.get(expression);
        ConfigurationValue resolvedNode = resolveMatch(values);
        if (resolvedNode == null) {
            return null;
        }
        if (resolvedNode.value().containsVariables()) {
            for (String key : resolvedNode.value().referencedKeys()) {
                resolvedNode.value().replace(key, evaluateToString(key));
            }
        }
        return resolvedNode;
    }
View Full Code Here

        return resolvedNode;
    }

    @SuppressWarnings("unchecked")
    private <T> T processAndConvert(Class<T> clazz, String expression) throws ConstrettoException {
        ConfigurationValue value = findElementOrThrowException(expression);
        return (T) ValueConverterRegistry.convert(clazz, clazz, value.value());
    }
View Full Code Here

        ConfigurationValue value = findElementOrThrowException(expression);
        return (T) ValueConverterRegistry.convert(clazz, clazz, value.value());
    }

    private ConfigurationValue resolveMatch(List<ConfigurationValue> values) {
        ConfigurationValue bestMatch = null;
        for (ConfigurationValue configurationNode : values) {
            if (ConfigurationValue.DEFAULT_TAG.equals(configurationNode.tag())) {
                if (bestMatch == null || bestMatch.tag().equals(ConfigurationValue.DEFAULT_TAG)) {
                    bestMatch = configurationNode;
                }
            } else if (currentTags.contains(configurationNode.tag())) {
                if (bestMatch == null) {
                    bestMatch = configurationNode;
                } else {
                    int previousFoundPriority =
                            ConfigurationValue.DEFAULT_TAG.equals(bestMatch.tag()) ?
                                    Integer.MAX_VALUE : currentTags.indexOf(bestMatch.tag());
                    if (currentTags.indexOf(configurationNode.tag()) <= previousFoundPriority) {
                        bestMatch = configurationNode;
                    }
                }
            } else if (ConfigurationValue.ALL_TAG.equals(configurationNode.tag())) {
View Full Code Here

                        Configuration configurationAnnotation = field.getAnnotation(Configuration.class);
                        String expression = "".equals(configurationAnnotation.value()) ? field.getName() : configurationAnnotation.value();
                        field.setAccessible(true);
                        Class<?> fieldType = field.getType();
                        if (hasValue(expression)) {
                            ConfigurationValue node = findElementOrThrowException(expression);
                            if (fieldType.isAssignableFrom(List.class)) {
                                field.set(objectToConfigure, evaluateToList(getCollectionFieldType(field), expression));
                            } else if (fieldType.isAssignableFrom(Map.class)) {
                                field.set(objectToConfigure, evaluateToMap(getMapKeyFieldType(field), getMapValueFieldType(field), expression));
                            } else {
View Full Code Here

TOP

Related Classes of org.constretto.model.ConfigurationValue

Copyright © 2018 www.massapicom. 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.