use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DynamicDataTypeConverterResolverTestCase method doesNotFailWhenThereIsNoDataTypeResolution.
@Test
public void doesNotFailWhenThereIsNoDataTypeResolution() throws TransformerException {
when(muleContext.getRegistry()).thenReturn(muleRegistry);
when(muleRegistry.lookupTransformer(Mockito.any(DataType.class), Mockito.any(DataType.class))).thenReturn(null);
DynamicDataTypeConversionResolver resolver = new DynamicDataTypeConversionResolver(muleContext);
List<DataType> targetValues = new ArrayList<>();
targetValues.add(DataType.STRING);
Transformer resolvedConverter = resolver.resolve(DataType.INPUT_STREAM, targetValues);
assertEquals(null, resolvedConverter);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class MVELExpressionLanguage method evaluate.
@Override
public TypedValue evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, BindingContext bindingContext) {
expression = removeExpressionMarker(expression);
Map<String, Object> bindingMap = bindingContext.identifiers().stream().collect(toMap(id -> id, id -> bindingContext.lookup(id).get().getValue()));
final Object value = evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, bindingMap);
if (value instanceof TypedValue) {
return (TypedValue) value;
} else {
final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
DataType dataType = event != null ? dataTypeResolver.resolve(value, (PrivilegedEvent) event, compiledExpression) : OBJECT;
return new TypedValue(value, dataType);
}
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class MvelDataTypeResolver method resolve.
/**
* Resolves expression data type
*
* @param value result of evaluating the expression on the given message
* @param event event under evaluation
* @param serializedExpression expression
* @return the data type corresponding to the given expression if there is an expression resolver able to resolved it. A default
* data type for the value if the expression was not resolved.
*/
public DataType resolve(Object value, PrivilegedEvent event, Serializable serializedExpression) {
DataType result = null;
if (serializedExpression instanceof CompiledExpression) {
CompiledExpression compiledExpression = (CompiledExpression) serializedExpression;
for (ExpressionDataTypeResolver resolver : resolvers) {
result = resolver.resolve(event, compiledExpression);
if (result != null) {
break;
}
}
}
if (result == null) {
Class<?> type = value == null ? Object.class : value.getClass();
result = DataType.fromType(type);
}
return result;
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TransformerWeighting method init.
private void init() {
inputWeighting = Integer.MAX_VALUE;
List<DataType> sourceTypes = transformer.getSourceDataTypes();
for (DataType type : sourceTypes) {
int weighting = getWeighting(-1, inputClass, type.getType());
if (weighting < inputWeighting && weighting != -1) {
inputWeighting = weighting;
}
}
outputWeighting = getWeighting(-1, outputClass, transformer.getReturnDataType().getType());
inputWeighting = (inputWeighting == Integer.MAX_VALUE ? -1 : inputWeighting);
outputWeighting = (outputWeighting == Integer.MAX_VALUE ? -1 : outputWeighting);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TransformationGraph method addConverter.
public void addConverter(Converter converter) {
if (registeredConverters.contains(converter)) {
if (logger.isDebugEnabled()) {
logger.debug("Attempting to register an already registered converter: " + converter);
}
return;
}
DataType returnDataType = converter.getReturnDataType();
if (!containsVertex(returnDataType)) {
addVertex(returnDataType);
}
for (DataType sourceDataType : converter.getSourceDataTypes()) {
if (!containsVertex(sourceDataType)) {
addVertex(sourceDataType);
}
addEdge(sourceDataType, returnDataType, new TransformationEdge(converter));
}
registeredConverters.add(converter);
}
Aggregations