View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers.generic;
8   
9   import org.mule.util.StringUtils;
10  
11  import org.w3c.dom.Element;
12  import org.w3c.dom.Node;
13  
14  /**
15   * An extension to {@link ChildDefinitionParser} which recurses up the DOM
16   * tree until it finds a named parent.
17   */
18  public class DescendentDefinitionParser extends ChildDefinitionParser
19  {
20      public DescendentDefinitionParser(String setterMethod, Class clazz)
21      {
22          super(setterMethod, clazz);
23      }
24  
25      protected String getParentBeanName(Element element)
26      {
27          Node node = element;
28          while (null != node && node instanceof Element)
29          {
30              String name = super.getParentBeanName((Element) node);
31              if (!StringUtils.isBlank(name))
32              {
33                  return name;
34              }
35              node = element.getParentNode();
36          }
37          throw new IllegalStateException("Bean: " + element.getNodeName() + " has no grandparent");
38      }
39  }