View Javadoc

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