View Javadoc

1   /*
2    * $Id: PayloadAnnotationParser.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  package org.mule.config.parsers;
11  
12  import org.mule.api.annotations.meta.Evaluator;
13  import org.mule.api.annotations.param.Payload;
14  import org.mule.api.expression.ExpressionAnnotationParser;
15  import org.mule.expression.ExpressionConfig;
16  import org.mule.expression.transformers.ExpressionArgument;
17  
18  import java.lang.annotation.Annotation;
19  
20  /**
21   * Responsible for parsing the {@link org.mule.api.annotations.param.Payload} annotation.  This is an iBeans
22   * framework class and cannot be used in any other context.
23   */
24  public class PayloadAnnotationParser implements ExpressionAnnotationParser
25  {
26      public ExpressionArgument parse(Annotation annotation, Class<?> parameterType)
27      {
28          Evaluator evaluator = annotation.annotationType().getAnnotation(Evaluator.class);
29          if (evaluator != null)
30          {
31              return new ExpressionArgument(null, new ExpressionConfig(parameterType.getName(), evaluator.value(), null), false, parameterType);
32          }
33          else
34          {
35              throw new IllegalArgumentException("The @Evaluator annotation must be set on an Expression Annotation");
36          }
37      }
38  
39      public boolean supports(Annotation annotation)
40      {
41          return annotation instanceof Payload;
42      }
43  }