View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.parsers;
8   
9   import org.mule.api.annotations.meta.Evaluator;
10  import org.mule.api.annotations.param.OutboundHeaders;
11  import org.mule.api.expression.ExpressionAnnotationParser;
12  import org.mule.expression.ExpressionConfig;
13  import org.mule.expression.transformers.ExpressionArgument;
14  
15  import java.lang.annotation.Annotation;
16  import java.util.Map;
17  
18  /**
19   * Responsible for parsing the {@link org.mule.api.annotations.param.OutboundHeaders} annotation.  This is an iBeans
20   * framework class and cannot be used in any other context.
21   */
22  public class OutboundHeadersAnnotationParser implements ExpressionAnnotationParser
23  {
24      public ExpressionArgument parse(Annotation annotation, Class<?> parameterType)
25      {
26          if(!Map.class.isAssignableFrom(parameterType))
27          {
28              throw new IllegalArgumentException("The @OutboundHeaders annotation can only be set on a java.util.Map parameter");
29          }
30          Evaluator evaluator = annotation.annotationType().getAnnotation(Evaluator.class);
31          if (evaluator != null)
32          {
33              return new ExpressionArgument(null, new ExpressionConfig("", evaluator.value(), null), false);
34          }
35          else
36          {
37              throw new IllegalArgumentException("The @Evaluator annotation must be set on an Expression Annotation");
38          }
39      }
40  
41      public boolean supports(Annotation annotation)
42      {
43          return annotation instanceof OutboundHeaders;
44      }
45  }