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.endpoint;
8   
9   import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
10  import org.mule.config.spring.parsers.assembly.MapEntryCombiner;
11  import org.mule.config.spring.parsers.collection.ChildSingletonMapDefinitionParser;
12  import org.mule.config.spring.parsers.delegate.AbstractSingleParentFamilyChildDefinitionParser;
13  import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
14  import org.mule.config.spring.parsers.processors.AddAttribute;
15  
16  /**
17   * This parser parses nested endpoint elements adding the resulting beans to the map
18   * of properties on the EndpointBuilder rather than attempting to inject them on the
19   * EndpointBuilder itself.
20   */
21  public class EndpointPropertyElementDefinitionParser extends AbstractSingleParentFamilyChildDefinitionParser
22  {
23      public static final String ENDPOINT_PROPERTIES_ATTRIBUTE = "properties";
24  
25      public EndpointPropertyElementDefinitionParser(String propertyKey, Class beanClass)
26      {
27          setReturnFirstResult(false);
28          addDelegate(new ChildSingletonMapDefinitionParser(ENDPOINT_PROPERTIES_ATTRIBUTE)).registerPreProcessor(
29              new AddAttribute(MapEntryCombiner.KEY, propertyKey))
30              .addCollection(ENDPOINT_PROPERTIES_ATTRIBUTE)
31              .setIgnoredDefault(true)
32              .removeIgnored(MapEntryCombiner.KEY)
33              .addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
34          addChildDelegate(new ChildDefinitionParser(MapEntryCombiner.VALUE, beanClass)).addIgnored(
35              AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME).addIgnored(MapEntryCombiner.KEY);
36      }
37  }