View Javadoc

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