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.properties;
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.AbstractSingleParentFamilyDefinitionParser;
13  import org.mule.config.spring.parsers.processors.AddAttribute;
14  
15  /**
16   * This extends a map that is itself a property (with key mapKey).  It does not have any
17   * container element.
18   */
19  public class NestedMapDefinitionParser extends AbstractSingleParentFamilyDefinitionParser
20  {
21  
22      // we use this so that "key" can be used as the attribute name!
23      public static final String HIDDEN_KEY = "hiddenKey";
24  
25      public NestedMapDefinitionParser(String mapSetter, String mapKey)
26      {
27          addDelegate(new ChildSingletonMapDefinitionParser(mapSetter))
28                  .registerPreProcessor(new AddAttribute(HIDDEN_KEY, mapKey))
29                  .addCollection(mapSetter)
30                  .setIgnoredDefault(true)
31                  .addAlias(HIDDEN_KEY, MapEntryCombiner.KEY)
32                  .removeIgnored(HIDDEN_KEY)
33                  .addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
34          addChildDelegate(new SimplePropertyDefinitionParser())
35                  .addIgnored(HIDDEN_KEY)
36                  .addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
37      }
38  
39  }