View Javadoc

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