01: /*
02: * $Id: ElementInNestedMapDefinitionParser.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.ChildSingletonMapDefinitionParser;
16: import org.mule.config.spring.parsers.delegate.AbstractSingleParentFamilyDefinitionParser;
17: import org.mule.config.spring.parsers.processors.AddAttribute;
18:
19: /**
20: * This constructs a nested map - keyed by "mapKey" - and then adds an entry in that
21: * named from the attribute "keyAttribute". Child elements can then set a value (or
22: * values, if it is a collection) on {@link org.mule.config.spring.parsers.assembly.MapEntryCombiner#VALUE}
23: */
24: public class ElementInNestedMapDefinitionParser extends
25: AbstractSingleParentFamilyDefinitionParser {
26:
27: public ElementInNestedMapDefinitionParser(String mapSetter,
28: String mapKey, String keyAttribute) {
29: // children (parameters) want to append to the inner map, not the outer one
30: setReturnFirstResult(false);
31: addDelegate(new ChildSingletonMapDefinitionParser(mapSetter))
32: .registerPreProcessor(
33: new AddAttribute(MapEntryCombiner.KEY, mapKey))
34: .addCollection(mapSetter)
35: .setIgnoredDefault(true)
36: .removeIgnored(MapEntryCombiner.KEY)
37: .addIgnored(
38: AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
39: addChildDelegate(
40: new ChildSingletonMapDefinitionParser(
41: MapEntryCombiner.VALUE)).addAlias(keyAttribute,
42: MapEntryCombiner.KEY).addCollection(
43: MapEntryCombiner.VALUE).addIgnored(
44: AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
45: }
46:
47: }
|