use of org.alien4cloud.tosca.model.definitions.ListPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method getFromPath.
private static AbstractPropertyValue getFromPath(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, Map<String, AbstractPropertyValue> properties, String propertyPath) {
if (propertyPath.contains(".")) {
String propertyName = propertyPath.split("\\.")[0];
AbstractPropertyValue propertyValue = properties.get(propertyName);
if (!(propertyValue instanceof PropertyValue)) {
// if the value is not a property value resolve it first
propertyValue = tryResolveValue(evaluatorContext, targetTemplate, properties, propertyValue);
if (propertyValue == null) {
return null;
}
}
// now it is a property value
Object value = MapUtil.get(((PropertyValue) propertyValue).getValue(), propertyPath.substring(propertyName.length() + 1));
if (value == null) {
return null;
} else if (value instanceof String) {
return new ScalarPropertyValue((String) value);
} else if (value instanceof List) {
return new ListPropertyValue((List<Object>) value);
} else if (value instanceof Map) {
return new ComplexPropertyValue((Map<String, Object>) value);
}
throw new IllegalArgumentException("The value of a property must be a scalar, a list or a map.");
}
return safe(properties).get(propertyPath);
}
Aggregations