View Javadoc

1   /*
2    * $Id: NestedListDefinitionParser.java 20321 2010-11-24 15:21:24Z dfeist $
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.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.ChildListEntryDefinitionParser;
16  import org.mule.config.spring.parsers.collection.ChildSingletonMapDefinitionParser;
17  import org.mule.config.spring.parsers.delegate.AbstractSingleParentFamilyDefinitionParser;
18  import org.mule.config.spring.parsers.processors.AddAttribute;
19  
20  /**
21   * This extends a list that is itself a property (with key mapKey).  It does not have any
22   * container element.
23   *
24   * This could also be achieved with
25   * new ChildSingletonMapDefinitionParser("properties")
26   * .registerPreProcessor(new AddAttribute(MapEntryCombiner.KEY, "soap11Transports"))
27   * .addCollection(MapEntryCombiner.VALUE)
28   * .addCollection("properties");
29   * I think, but the following avoids worries about special attribute names.
30   */
31  public class NestedListDefinitionParser extends AbstractSingleParentFamilyDefinitionParser
32  {
33  
34      // we use this so that they can be used as the attribute name!
35      public static final String HIDDEN_KEY = "hiddenKey";
36      public static final String HIDDEN_VALUE = "hiddenValue";
37  
38      public NestedListDefinitionParser(String mapSetter, String mapKey, String attribute)
39      {
40          addDelegate(new ChildSingletonMapDefinitionParser(mapSetter))
41                  .registerPreProcessor(new AddAttribute(HIDDEN_KEY, mapKey))
42                  .addCollection(mapSetter)
43                  .setIgnoredDefault(true)
44                  .addAlias(HIDDEN_KEY, MapEntryCombiner.KEY)
45                  .removeIgnored(HIDDEN_KEY)
46                  .addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
47          addChildDelegate(new ChildListEntryDefinitionParser(HIDDEN_VALUE, attribute))
48                  .addAlias(HIDDEN_VALUE, MapEntryCombiner.VALUE)
49                  .addCollection(HIDDEN_VALUE);
50      }
51  
52  }