use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class SimpleRegistryBootstrap method registerTransformers.
@Override
protected void registerTransformers() throws MuleException {
MuleRegistryHelper registry = (MuleRegistryHelper) ((MuleContextWithRegistries) muleContext).getRegistry();
Map<String, Converter> converters = registry.lookupByType(Converter.class);
for (Converter converter : converters.values()) {
registry.notifyTransformerResolvers(converter, TransformerResolver.RegistryAction.ADDED);
}
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class MuleRegistryHelper method lookupTransformers.
/**
* {@inheritDoc}
*/
@Override
public List<Transformer> lookupTransformers(DataType source, DataType result) {
// To maintain the previous behaviour, we don't want to consider the result mimeType when resolving a transformer
// and only find transformers with a targetType the same as or a super class of the expected one.
// The same could be done for the source but since if the source expected by the transformer is more generic that
// the provided, it will be found.
result = builder(result).mediaType(ANY).charset((Charset) null).build();
final String dataTypePairHash = getDataTypeSourceResultPairHash(source, result);
List<Transformer> results = (List<Transformer>) transformerListCache.get(dataTypePairHash);
if (results != null) {
return results;
}
results = new ArrayList<>(2);
Lock readLock = transformersLock.readLock();
readLock.lock();
try {
for (Transformer transformer : transformers) {
// going to find it here
if (!(transformer instanceof Converter)) {
continue;
}
if (result.isCompatibleWith(transformer.getReturnDataType()) && transformer.isSourceDataTypeSupported(source)) {
results.add(transformer);
}
}
} finally {
readLock.unlock();
}
List<Transformer> concurrentlyAddedTransformers = (List<Transformer>) transformerListCache.putIfAbsent(dataTypePairHash, results);
if (concurrentlyAddedTransformers != null) {
return concurrentlyAddedTransformers;
} else {
return results;
}
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class PriorityWeightingConverterFilter method getTransformerWeightings.
private List<TransformerWeighting> getTransformerWeightings(List<Converter> converters, Class input, Class output) {
List<TransformerWeighting> weightings = new LinkedList<>();
for (Converter converter : converters) {
TransformerWeighting current = new TransformerWeighting(input, output, converter);
weightings.add(current);
}
Collections.sort(weightings);
return weightings;
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class ExtendedTransformationService method canSkipTransformer.
private boolean canSkipTransformer(Message message, List<? extends Transformer> transformers, int index) {
Transformer transformer = transformers.get(index);
boolean skipConverter = false;
if (transformer instanceof Converter) {
if (index == transformers.size() - 1) {
try {
checkTransformerReturnClass(transformer, message.getPayload().getValue());
skipConverter = true;
} catch (TransformerException e) {
// Converter cannot be skipped
}
} else {
skipConverter = true;
}
}
if (skipConverter) {
logger.debug("Skipping converter: " + transformer);
}
return skipConverter;
}
Aggregations