All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mule.routing.MapSplitter Maven / Gradle / Ivy

There is a newer version: 3.9.0
Show newest version
/*
 * $Id: MapSplitter.java 21128 2011-01-27 02:51:53Z dfeist $
 * --------------------------------------------------------------------------------------
 * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

package org.mule.routing;

import org.mule.DefaultMuleMessage;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;
import org.mule.config.i18n.CoreMessages;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

/**
 * Splits a message that has a map payload invoking the next message processor one
 * for each item in the map in order. The Map entry value is used as the new payload
 * and the map key is set as a message property with the following property name
 * 'key'.
 * 

* EIP Reference: http://www * .eaipatterns.com/Sequencer.html */ public class MapSplitter extends AbstractSplitter { public static String MAP_ENTRY_KEY = "key"; protected List splitMessage(MuleEvent event) { MuleMessage message = event.getMessage(); if (message.getPayload() instanceof Map) { List list = new LinkedList(); Set> set = ((Map) message.getPayload()).entrySet(); for (Entry entry : set) { MuleMessage splitMessage = new DefaultMuleMessage(entry.getValue(), muleContext); splitMessage.setInvocationProperty(MAP_ENTRY_KEY, entry.getKey()); list.add(splitMessage); } return list; } else { throw new IllegalArgumentException(CoreMessages.objectNotOfCorrectType( message.getPayload().getClass(), Map.class).getMessage()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy