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.config.spring.util.SpringXMLUtils;
10  
11  import org.springframework.beans.factory.support.AbstractBeanDefinition;
12  import org.springframework.beans.factory.xml.ParserContext;
13  import org.w3c.dom.Element;
14  
15  /**
16   * A parser for direct children of the <mule> element.
17   */
18  public class MuleOrphanDefinitionParser extends OrphanDefinitionParser
19  {
20      /**
21       * This constructor assumes that the class name will be explicitly specified as
22       * an attribute on the element.
23       */
24      public MuleOrphanDefinitionParser(boolean singleton)
25      {
26          super(singleton);
27      }
28  
29      public MuleOrphanDefinitionParser(Class<?> beanClass, boolean singleton)
30      {
31          super(beanClass, singleton);
32      }
33  
34      @Override
35      protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext)
36      {
37          assertMuleParent(element);
38          return super.parseInternal(element, parserContext);
39      }
40  
41      protected void assertMuleParent(Element element)
42      {
43          if (!isTopLevel(element))
44          {
45              throw new IllegalStateException("This element should be embedded inside the Mule <"
46                      + ROOT_ELEMENT + "> element: " + SpringXMLUtils.elementToString(element));
47          }
48      }
49  }