View Javadoc

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