01: /*
02: * $Id: MessageAttachmentExpressionEvaluator.java 11286 2008-03-09 11:33:50Z 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 javax.activation.DataHandler;
16:
17: /**
18: * Looks up an attachment with the given name.
19: *
20: * @see org.mule.util.expression.MessageAttachmentsListExpressionEvaluator
21: * @see org.mule.util.expression.MessageAttachmentsExpressionEvaluator
22: * @see org.mule.util.expression.ExpressionEvaluator
23: * @see org.mule.util.expression.ExpressionEvaluatorManager
24: */
25: public class MessageAttachmentExpressionEvaluator implements
26: ExpressionEvaluator {
27: public static final String NAME = "attachment";
28:
29: public Object evaluate(String name, Object message) {
30: if (message instanceof MessageAdapter) {
31: DataHandler dh = ((MessageAdapter) message)
32: .getAttachment(name);
33: return dh;
34: }
35: return null;
36: }
37:
38: /** {@inheritDoc} */
39: public String getName() {
40: return NAME;
41: }
42:
43: /** {@inheritDoc} */
44: public void setName(String name) {
45: throw new UnsupportedOperationException("setName");
46: }
47: }
|