01: /*
02: * $Id: NestedMapWithAttributesDefinitionParser.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.generic.AttributePropertiesDefinitionParser;
18: import org.mule.config.spring.parsers.processors.AddAttribute;
19:
20: /**
21: * This generates a nested map (an element of the parent map, with the key "mapKey", which is a map itself)
22: * and then adds any attributes as name/value pairs. Embedded elements can then insert further entries using
23: * {@link org.mule.config.spring.parsers.collection.ChildSingletonMapDefinitionParser} or, if the entry is
24: * just a simple value, {@link org.mule.config.spring.parsers.specific.properties.SimplePropertyDefinitionParser}.
25: * The target setter is {@link org.mule.config.spring.parsers.assembly.MapEntryCombiner#VALUE}.
26: */
27: public class NestedMapWithAttributesDefinitionParser extends
28: AbstractSingleParentFamilyDefinitionParser {
29:
30: public NestedMapWithAttributesDefinitionParser(String mapSetter,
31: String mapKey) {
32: addDelegate(new ChildSingletonMapDefinitionParser(mapSetter))
33: .addCollection(mapSetter).setIgnoredDefault(true)
34: .removeIgnored(MapEntryCombiner.KEY)
35: .registerPreProcessor(
36: new AddAttribute(MapEntryCombiner.KEY, mapKey));
37: addChildDelegate(
38: new AttributePropertiesDefinitionParser(
39: MapEntryCombiner.VALUE)).addIgnored(
40: AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME)
41: .addIgnored(MapEntryCombiner.KEY);
42: }
43:
44: }
|