View Javadoc

1   /*
2    * $Id: OutboundAttachmentsAnnotationComponent.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.api.annotations.param;
12  
13  import org.mule.util.StringDataSource;
14  
15  import java.util.List;
16  import java.util.Map;
17  
18  import javax.activation.DataHandler;
19  
20  /**
21   * Tests various cases for how attachments can added to an outbound message through a generic map by injecting the
22   * map into a component invocation
23   */
24  public class OutboundAttachmentsAnnotationComponent
25  {
26      public Map<?, ?> processAttachments(@OutboundAttachments Map<String, DataHandler> attachments)
27      {
28          attachments.put("bar", new DataHandler(new StringDataSource("barValue")));
29          //Verify that we receive any outbound attachments already set on the message
30          if (attachments.containsKey("foo"))
31          {
32              //Overwrite the existing attachment to signal that we received it
33              attachments.put("foo", new DataHandler(new StringDataSource("fooValue")));
34          }
35          return attachments;
36      }
37  
38      //Can only use the {@link OutboundAttachments} annotation on Map parameters
39      public List<?> invalidParamType(@OutboundAttachments List<?> attachments)
40      {
41          return attachments;
42      }
43  }