View Javadoc

1   /*
2    * $Id: MapPayloadExpressionEvaluator.java 11834 2008-05-22 12:06:47Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.util.expression;
12  
13  import org.mule.api.transport.MessageAdapter;
14  
15  import java.util.Map;
16  
17  /**
18   * If the message payload is a map this extractor will look up the property value in
19   * the map
20   */
21  public class MapPayloadExpressionEvaluator implements ExpressionEvaluator
22  {
23      public static final String NAME = "map-payload";
24      
25      public Object evaluate(String expression, Object message)
26      {
27          Object payload = message;
28          if (message instanceof MessageAdapter)
29          {
30              payload = ((MessageAdapter) message).getPayload();
31          }
32          if (payload instanceof Map)
33          {
34              return ((Map) payload).get(expression);
35          }
36          return null;
37      }
38  
39      /** {@inheritDoc} */
40      public String getName()
41      {
42          return NAME;
43      }
44  
45      /** {@inheritDoc} */
46      public void setName(String name)
47      {
48          throw new UnsupportedOperationException("setName");
49      }
50  
51  }