Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DescendentDefinitionParser |
|
| 3.0;3 |
1 | /* | |
2 | * $Id: DescendentDefinitionParser.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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.util.StringUtils; | |
13 | ||
14 | import org.w3c.dom.Element; | |
15 | import org.w3c.dom.Node; | |
16 | ||
17 | /** | |
18 | * An extension to {@link ChildDefinitionParser} which recurses up the DOM | |
19 | * tree until it finds a named parent. | |
20 | */ | |
21 | public class DescendentDefinitionParser extends ChildDefinitionParser | |
22 | { | |
23 | public DescendentDefinitionParser(String setterMethod, Class clazz) | |
24 | { | |
25 | 0 | super(setterMethod, clazz); |
26 | 0 | } |
27 | ||
28 | protected String getParentBeanName(Element element) | |
29 | { | |
30 | 0 | Node node = element; |
31 | 0 | while (null != node && node instanceof Element) |
32 | { | |
33 | 0 | String name = super.getParentBeanName((Element) node); |
34 | 0 | if (!StringUtils.isBlank(name)) |
35 | { | |
36 | 0 | return name; |
37 | } | |
38 | 0 | node = element.getParentNode(); |
39 | 0 | } |
40 | 0 | throw new IllegalStateException("Bean: " + element.getNodeName() + " has no grandparent"); |
41 | } | |
42 | } |