View Javadoc

1   /*
2    * $Id: MuleBeanDefinitionDocumentReader.java 11469 2008-03-21 19:57:46Z dfeist $
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  
11  package org.mule.config.spring;
12  
13  import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
14  import org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader;
15  import org.springframework.beans.factory.xml.XmlReaderContext;
16  import org.springframework.util.StringUtils;
17  import org.w3c.dom.Element;
18  
19  /**
20   * Allows us to hook in our own Hierarchical Parser delegate. this enables the
21   * parsing of custom spring bean elements nested within each other
22   */
23  public class MuleBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocumentReader
24  {
25  
26      protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root)
27      {
28          BeanDefinitionParserDelegate delegate = new MuleHierarchicalBeanDefinitionParserDelegate(readerContext, this);
29          delegate.initDefaults(root);
30          return delegate;
31      }
32  
33      /**
34       * Override to reject configuration files with no namespace, e.g. mule legacy
35       * configuration file.
36       */
37      protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate)
38      {
39          if (!StringUtils.hasLength(root.getNamespaceURI()))
40          {
41              getReaderContext().error("Unable to locate NamespaceHandler for namespace [null]", root);
42          }
43          else
44          {
45              super.parseBeanDefinitions(root, delegate);
46          }
47      }
48  
49  }