use of org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder in project camel by apache.
the class BlueprintPropertiesParser method addPropertyPlaceholder.
/**
* Adds the given Blueprint property placeholder service with the given id
*
* @param id id of the Blueprint property placeholder service to add.
*/
public void addPropertyPlaceholder(String id) {
Object component = container.getComponentInstance(id);
if (component instanceof AbstractPropertyPlaceholder) {
AbstractPropertyPlaceholder placeholder = (AbstractPropertyPlaceholder) component;
placeholders.add(placeholder);
log.debug("Adding Blueprint PropertyPlaceholder: {}", id);
if (method == null) {
try {
method = AbstractPropertyPlaceholder.class.getDeclaredMethod("retrieveValue", String.class);
method.setAccessible(true);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Cannot add blueprint property placeholder: " + id + " as the method retrieveValue is not accessible", e);
}
}
}
}
use of org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder 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;
}
Aggregations