View Javadoc

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