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.module.ognl.config;
8   
9   import org.mule.config.spring.parsers.assembly.BeanAssembler;
10  import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
11  import org.mule.config.spring.parsers.specific.FilterDefinitionParser;
12  import org.mule.module.ognl.filters.OGNLFilter;
13  
14  import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
15  import org.springframework.beans.factory.xml.ParserContext;
16  import org.w3c.dom.Element;
17  
18  /**
19   * Registers Bean Definition Parsers for the "ognl" namespace.
20   */
21  public class OGNLNamespaceHandler extends NamespaceHandlerSupport
22  {
23  
24      public void init()
25      {
26          registerBeanDefinitionParser("filter", new FilterDefinitionParser(OGNLFilter.class));
27          registerBeanDefinitionParser("expression", new CDATABeanDefinitionParser("expression", String.class));
28      }
29  
30      private static class CDATABeanDefinitionParser extends
31                                                     ChildDefinitionParser
32      {
33          private CDATABeanDefinitionParser(String setterMethod, Class clazz)
34          {
35              super(setterMethod, clazz);
36          }
37  
38          protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
39          {
40              assembler.extendTarget(setterMethod, element.getFirstChild().getNodeValue(), false);
41          }
42      }
43  }