Search in sources :

Example 1 with PropertyPlaceholder

use of org.apache.aries.blueprint.ext.PropertyPlaceholder in project camel by apache.

the class BlueprintPropertiesParser method parseProperty.

@Override
public String parseProperty(String key, String value, Properties properties) {
    log.trace("Parsing property key: {} with value: {}", key, value);
    String answer = null;
    // service to lookup otherwise
    if (key != null && propertiesComponent.getOverrideProperties() != null) {
        answer = (String) propertiesComponent.getOverrideProperties().get(key);
    }
    // lookup key in blueprint and return its value
    if (answer == null && key != null) {
        for (AbstractPropertyPlaceholder placeholder : placeholders) {
            boolean isDefault = false;
            if (placeholders.size() > 1) {
                // is not the default placeholder if there is multiple keys
                if (placeholder instanceof PropertyPlaceholder) {
                    Map map = ((PropertyPlaceholder) placeholder).getDefaultProperties();
                    isDefault = map != null && map.containsKey(key);
                }
                log.trace("Blueprint property key: {} is part of default properties: {}", key, isDefault);
            }
            try {
                String candidate = (String) ObjectHelper.invokeMethod(method, placeholder, key);
                if (candidate != null) {
                    if (answer == null || !isDefault) {
                        log.trace("Blueprint parsed candidate property key: {} as value: {}", key, answer);
                        answer = candidate;
                    }
                }
            } catch (Exception ex) {
            // Here we just catch the exception and try to use other candidate
            }
        }
        log.debug("Blueprint parsed property key: {} as value: {}", key, answer);
    }
    // need to decrypt values
    if (delegate != null) {
        String delegateAnswer = delegate.parseProperty(key, answer != null ? answer : value, properties);
        if (delegateAnswer != null) {
            answer = delegateAnswer;
            log.debug("Delegate property parser parsed the property key: {} as value: {}", key, answer);
        }
    }
    log.trace("Returning parsed property key: {} as value: {}", key, answer);
    return answer;
}
Also used : PropertyPlaceholder(org.apache.aries.blueprint.ext.PropertyPlaceholder) AbstractPropertyPlaceholder(org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder) AbstractPropertyPlaceholder(org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 AbstractPropertyPlaceholder (org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder)1 PropertyPlaceholder (org.apache.aries.blueprint.ext.PropertyPlaceholder)1