01: /*
02: * $Id: NestedListDefinitionParser.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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
32: AbstractSingleParentFamilyDefinitionParser {
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,
39: String attribute) {
40: addDelegate(new ChildSingletonMapDefinitionParser(mapSetter))
41: .registerPreProcessor(
42: new AddAttribute(HIDDEN_KEY, mapKey))
43: .addCollection(mapSetter)
44: .setIgnoredDefault(true)
45: .addAlias(HIDDEN_KEY, MapEntryCombiner.KEY)
46: .removeIgnored(HIDDEN_KEY)
47: .addIgnored(
48: AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
49: addChildDelegate(
50: new ChildListEntryDefinitionParser(HIDDEN_VALUE,
51: attribute)).addAlias(HIDDEN_VALUE,
52: MapEntryCombiner.VALUE).addCollection(HIDDEN_VALUE);
53: }
54:
55: }
|