use of org.mule.runtime.internal.util.collection.ImmutableEntry in project mule by mulesoft.
the class EventToMessageSequenceSplittingStrategy method split.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public MessageSequence<?> split(CoreEvent event) {
if (expressionSplitterStrategy.hasDefaultExpression()) {
Message msg = event.getMessage();
Object payload = msg.getPayload().getValue();
if (payload instanceof MessageSequence<?>) {
return ((MessageSequence<?>) payload);
}
if (payload instanceof Iterator<?>) {
return new IteratorMessageSequence(((Iterator<Object>) payload));
}
if (payload instanceof Collection) {
return new CollectionMessageSequence(copyCollection((Collection) payload));
} else if (payload instanceof CursorIteratorProvider) {
return new IteratorMessageSequence(((CursorIteratorProvider) payload).openCursor());
} else if (payload instanceof Iterable<?>) {
return new IteratorMessageSequence(((Iterable<Object>) payload).iterator());
} else if (payload instanceof Object[]) {
return new ArrayMessageSequence((Object[]) payload);
} else if (payload instanceof NodeList) {
return new NodeListMessageSequence((NodeList) payload);
} else if (payload instanceof Map<?, ?>) {
List<Object> list = new LinkedList<>();
Set<Map.Entry<?, ?>> set = ((Map) payload).entrySet();
for (Map.Entry<?, ?> entry : set) {
list.add(new ImmutableEntry<>(entry));
}
return new CollectionMessageSequence(list);
}
}
try {
Iterator<TypedValue<?>> valueIterator = expressionSplitterStrategy.split(event);
if (hasMelExpression(expressionSplitterStrategy.getExpression())) {
List<Object> iteratorCollection = new ArrayList<>();
valueIterator.forEachRemaining(iteratorCollection::add);
return new CollectionMessageSequence<>(iteratorCollection);
}
return new IteratorMessageSequence(valueIterator);
} catch (ExpressionRuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalArgumentException(format("Could not split result of expression %s. The provided value is not instance of %s java " + "type or it's not a collection in any other format", expressionSplitterStrategy.getExpression(), new Class[] { Iterable.class, Iterator.class, MessageSequence.class, Collection.class }), e);
}
}
Aggregations