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.spring.parsers.specific;
8   
9   import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
10  import org.mule.enricher.MessageEnricher.EnrichExpressionPair;
11  import org.mule.util.StringUtils;
12  
13  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
14  import org.springframework.beans.factory.support.GenericBeanDefinition;
15  import org.springframework.beans.factory.support.ManagedList;
16  import org.springframework.beans.factory.xml.ParserContext;
17  import org.w3c.dom.Element;
18  
19  public class MessageEnricherDefinitionParser extends ChildDefinitionParser
20  {
21  
22      public MessageEnricherDefinitionParser(String setterMethod, Class clazz)
23      {
24          super(setterMethod, clazz);
25      }
26  
27      @Override
28      protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
29      {
30          if (!StringUtils.isEmpty(element.getAttribute("source")) || !StringUtils.isEmpty(element.getAttribute("target")))
31          {
32              GenericBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition();
33              objectFactoryBeanDefinition.setBeanClass(EnrichExpressionPair.class);
34              objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("source",
35                  element.getAttribute("source"));
36              objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("target",
37                  element.getAttribute("target"));
38              ManagedList<GenericBeanDefinition> list = new ManagedList<GenericBeanDefinition>();
39              list.add(objectFactoryBeanDefinition);
40              builder.addPropertyValue("enrichExpressionPairs", list);
41          }
42  
43          super.parseChild(element, parserContext, builder);
44      }
45  }