01: /*
02: * $Id: AttributeListEntryDefinitionParser.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.AbstractChildDefinitionParser;
14: import org.mule.config.spring.util.SpringXMLUtils;
15: import org.mule.util.StringUtils;
16:
17: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
18: import org.springframework.beans.factory.xml.ParserContext;
19: import org.w3c.dom.Attr;
20: import org.w3c.dom.Element;
21:
22: public class AttributeListEntryDefinitionParser extends
23: AbstractChildDefinitionParser implements
24: DynamicAttributeDefinitionParser {
25:
26: private String setterMethod;
27: private String attributeName;
28:
29: /**
30: * Only for use with dynamic naming
31: */
32: public AttributeListEntryDefinitionParser(String setterMethod) {
33: this (setterMethod, null);
34: }
35:
36: public AttributeListEntryDefinitionParser(String setterMethod,
37: String attributeName) {
38: this .setterMethod = setterMethod;
39: setAttributeName(attributeName);
40: }
41:
42: public String getPropertyName(Element element) {
43: return setterMethod;
44: }
45:
46: protected Class getBeanClass(Element element) {
47: return ChildListEntryDefinitionParser.ListEntry.class;
48: }
49:
50: public void setAttributeName(String attributeName) {
51: this .attributeName = attributeName;
52: }
53:
54: protected void parseChild(Element element,
55: ParserContext parserContext, BeanDefinitionBuilder builder) {
56: Attr attribute = element.getAttributeNode(attributeName);
57: if (null == attribute
58: || StringUtils.isEmpty(attribute.getNodeValue())) {
59: throw new IllegalStateException("No value for "
60: + attributeName + " in "
61: + SpringXMLUtils.elementToString(element));
62: }
63: String value = attribute.getNodeValue();
64: builder.setSource(new ChildListEntryDefinitionParser.ListEntry(
65: value));
66: this.postProcess(parserContext, getBeanAssembler(element,
67: builder), element);
68: }
69:
70: }
|