View Javadoc

1   /*
2    * $Id: MessageAttachmentExpressionEvaluator.java 11286 2008-03-09 11:33:50Z 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 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 ExpressionEvaluator
26  {
27      public static final String NAME = "attachment";
28  
29      public Object evaluate(String name, Object message)
30      {
31          if (message instanceof MessageAdapter)
32          {
33              DataHandler dh = ((MessageAdapter) message).getAttachment(name);
34              return dh;
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  }