01: /*
02: * $Id: MapPayloadExpressionEvaluator.java 11231 2008-03-06 21:17:37Z rossmason $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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
22: ExpressionEvaluator {
23: public static final String NAME = "map";
24:
25: public Object evaluate(String name, Object message) {
26: Object payload = message;
27: if (message instanceof MessageAdapter) {
28: payload = ((MessageAdapter) message).getPayload();
29: }
30: if (payload instanceof Map) {
31: return ((Map) payload).get(name);
32: }
33: return null;
34: }
35:
36: /** {@inheritDoc} */
37: public String getName() {
38: return NAME;
39: }
40:
41: /** {@inheritDoc} */
42: public void setName(String name) {
43: throw new UnsupportedOperationException("setName");
44: }
45:
46: }
|