View Javadoc

1   /*
2    * $Id: InvokerMessageProcessorDefinitionParser.java 20875 2011-01-04 16:09:25Z aperepel $
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.config.spring.parsers.specific;
12  
13  import org.mule.config.spring.parsers.assembly.BeanAssembler;
14  import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
15  import org.mule.processor.InvokerMessageProcessor;
16  import org.mule.util.StringUtils;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22  import org.springframework.beans.factory.xml.ParserContext;
23  import org.w3c.dom.Element;
24  
25  public class InvokerMessageProcessorDefinitionParser extends ChildDefinitionParser
26  {
27      private final Class<?> objectType;
28      private final String methodName;
29      private final String[] parameterNames;
30  
31      public InvokerMessageProcessorDefinitionParser(String setterMethod,
32                                           Class<?> objectType,
33                                           String methodName,
34                                           String[] parameterNames)
35      {
36          super(setterMethod, InvokerMessageProcessor.class);
37          this.objectType = objectType;
38          this.methodName = methodName;
39          this.parameterNames = parameterNames;
40      }
41  
42      @Override
43      protected Class<?> getBeanClass(Element element)
44      {
45          return InvokerMessageProcessor.class;
46      }
47  
48      @Override
49      protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
50      {
51          if (!StringUtils.isEmpty(element.getAttribute(getTargetPropertyConfiguration().getAttributeAlias(
52              "config-ref"))))
53          {
54              builder.addPropertyReference("object",
55                  element.getAttribute(getTargetPropertyConfiguration().getAttributeAlias("config-ref")));
56          }
57          else
58          {
59              builder.addPropertyValue("objectType", objectType);
60          }
61  
62          List<String> expressions = new ArrayList<String>();
63          if (parameterNames != null)
64          {
65              for (String parameterName : parameterNames)
66              {
67                  if (!StringUtils.isEmpty(element.getAttribute(parameterName)))
68                  {
69                      expressions.add(element.getAttribute(parameterName));
70                  }
71                  else
72                  {
73                      expressions.add(null);
74                  }
75              }
76          }
77          builder.addPropertyValue("arguments", expressions);
78          builder.addPropertyValue("methodName", methodName);
79  
80          BeanAssembler assembler = getBeanAssembler(element, builder);
81          postProcess(getParserContext(), assembler, element);
82      }
83  
84  }