View Javadoc

1   /*
2    * $Id: MessageEnricherDefinitionParser.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.generic.ChildDefinitionParser;
14  import org.mule.enricher.MessageEnricher.EnrichExpressionPair;
15  import org.mule.util.StringUtils;
16  
17  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
18  import org.springframework.beans.factory.support.GenericBeanDefinition;
19  import org.springframework.beans.factory.support.ManagedList;
20  import org.springframework.beans.factory.xml.ParserContext;
21  import org.w3c.dom.Element;
22  
23  public class MessageEnricherDefinitionParser extends ChildDefinitionParser
24  {
25  
26      public MessageEnricherDefinitionParser(String setterMethod, Class clazz)
27      {
28          super(setterMethod, clazz);
29      }
30  
31      @Override
32      protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
33      {
34          if (!StringUtils.isEmpty(element.getAttribute("source")) || !StringUtils.isEmpty(element.getAttribute("target")))
35          {
36              GenericBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition();
37              objectFactoryBeanDefinition.setBeanClass(EnrichExpressionPair.class);
38              objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("source",
39                  element.getAttribute("source"));
40              objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("target",
41                  element.getAttribute("target"));
42              ManagedList<GenericBeanDefinition> list = new ManagedList<GenericBeanDefinition>();
43              list.add(objectFactoryBeanDefinition);
44              builder.addPropertyValue("enrichExpressionPairs", list);
45          }
46  
47          super.parseChild(element, parserContext, builder);
48      }
49  }