01: /*
02: * $Id: ChildListEntryDefinitionParser.java 10494 2008-01-23 21:09:56Z acooke $
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.collection;
12:
13: import org.mule.config.spring.parsers.assembly.BeanAssembler;
14: import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
15: import org.mule.config.spring.util.SpringXMLUtils;
16:
17: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
18: import org.springframework.beans.factory.xml.ParserContext;
19: import org.w3c.dom.Element;
20:
21: /**
22: * Process an element as a value that is appended to a list in the parent object (the
23: * enclosing XML element).
24: */
25: public class ChildListEntryDefinitionParser extends
26: ChildDefinitionParser {
27:
28: public static final String VALUE = "value";
29: private boolean fromText = true;
30:
31: /**
32: * Takes value from enclosed text
33: *
34: * @param propertyName
35: */
36: public ChildListEntryDefinitionParser(String propertyName) {
37: super (propertyName, ListEntry.class);
38: setIgnoredDefault(true);
39: }
40:
41: /**
42: * Takes value from attribute
43: *
44: * @param propertyName
45: * @param attributeName
46: */
47: public ChildListEntryDefinitionParser(String propertyName,
48: String attributeName) {
49: this (propertyName);
50: addAlias(attributeName, VALUE);
51: removeIgnored(attributeName);
52: fromText = false;
53: }
54:
55: protected void postProcess(ParserContext context,
56: BeanAssembler assembler, Element element) {
57: if (fromText) {
58: assembler.extendBean(VALUE, SpringXMLUtils
59: .getTextChild(element), false);
60: }
61: super .postProcess(context, assembler, element);
62: }
63:
64: protected void parseChild(Element element,
65: ParserContext parserContext, BeanDefinitionBuilder builder) {
66: super .parseChild(element, parserContext, builder); //To change body of overridden methods use File | Settings | File Templates.
67: }
68:
69: public static class ListEntry {
70:
71: private Object value;
72:
73: public ListEntry() {
74: super ();
75: }
76:
77: public ListEntry(Object proxied) {
78: this ();
79: value = proxied;
80: }
81:
82: public Object getValue() {
83: return value;
84: }
85:
86: public void setValue(Object value) {
87: this.value = value;
88: }
89: }
90:
91: }
|