Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TextDefinitionParser |
|
| 2.0;2 |
1 | /* | |
2 | * $Id: TextDefinitionParser.java 11777 2008-05-15 18:58:47Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | package org.mule.config.spring.parsers.generic; | |
11 | ||
12 | import org.mule.config.spring.parsers.assembly.BeanAssembler; | |
13 | import org.mule.util.StringUtils; | |
14 | ||
15 | import org.springframework.beans.factory.xml.ParserContext; | |
16 | import org.w3c.dom.Element; | |
17 | import org.w3c.dom.Node; | |
18 | ||
19 | /** | |
20 | * Grabs the text from an element and injects it into the parent, for example: | |
21 | * | |
22 | * <foo> | |
23 | * <bar-text>A bunch of text.</bar-text> | |
24 | * </foo> | |
25 | * | |
26 | * registerBeanDefinitionParser("foo", new OrphanDefinitionParser(Foo.class)); | |
27 | * registerBeanDefinitionParser("bar-text", new TextDefinitionParser("barText")); | |
28 | * | |
29 | * will result in a call to Foo.setBarText("A bunch of text.") | |
30 | */ | |
31 | public class TextDefinitionParser extends ChildDefinitionParser | |
32 | { | |
33 | public TextDefinitionParser(String setterMethod) | |
34 | { | |
35 | 0 | super(setterMethod, String.class); |
36 | 0 | } |
37 | ||
38 | //@Override | |
39 | protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) | |
40 | { | |
41 | 0 | Node node = element.getFirstChild(); |
42 | 0 | if (node != null) |
43 | { | |
44 | 0 | String value = node.getNodeValue(); |
45 | 0 | if (!StringUtils.isBlank(value)) |
46 | { | |
47 | 0 | assembler.getTarget().getPropertyValues().addPropertyValue(setterMethod, value); |
48 | } | |
49 | } | |
50 | 0 | } |
51 | } |