View Javadoc

1   /*
2    * $Id: SimpleServiceDefinitionParser.java 21307 2011-02-17 15:35:44Z dfeist $
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  
11  package org.mule.config.spring.parsers.specific;
12  
13  import org.mule.config.spring.factories.SimpleServiceFactoryBean;
14  import org.mule.config.spring.parsers.processors.CheckExclusiveAttributes;
15  import org.mule.config.spring.parsers.processors.CheckExclusiveAttributesAndChildren;
16  import org.mule.util.StringUtils;
17  
18  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
19  import org.springframework.beans.factory.xml.ParserContext;
20  import org.w3c.dom.Element;
21  
22  public class SimpleServiceDefinitionParser extends AbstractFlowConstructDefinitionParser
23  {
24      private static final String COMPONENT_CLASS_ATTRIBUTE = "component-class";
25      private static final String COMPONENT_REF_ATTRIBUTE = "component-ref";
26      private static final String COMPONENT_CHILD_TYPE = "componentType";
27      private static final String ABSTRACT_ATTRIBUTE = "abstract";
28  
29      public SimpleServiceDefinitionParser()
30      {
31          super.addAlias("endpoint", "endpointBuilder");
32          
33          super.registerPreProcessor(new CheckExclusiveAttributes(new String[][]{
34              new String[]{ADDRESS_ATTRIBUTE}, new String[]{ENDPOINT_REF_ATTRIBUTE}}));
35          
36          super.registerPreProcessor(new CheckExclusiveAttributes(new String[][]{
37              new String[]{COMPONENT_CLASS_ATTRIBUTE}, new String[]{COMPONENT_REF_ATTRIBUTE}}));
38          
39          super.registerPreProcessor(new CheckExclusiveAttributesAndChildren(new String[]{
40              ENDPOINT_REF_ATTRIBUTE, ADDRESS_ATTRIBUTE, TRANSFORMER_REFS_ATTRIBUTE,
41              RESPONSE_TRANSFORMER_REFS_ATTRIBUTE}, new String[]{INBOUND_ENDPOINT_CHILD}));
42  
43          // We cannot support component element inheritance because components are singletons
44          super.registerPreProcessor(new CheckExclusiveAttributesAndChildren(new String[]{
45              ABSTRACT_ATTRIBUTE}, new String[]{COMPONENT_CHILD_TYPE}));
46  
47      }
48  
49      @Override
50      protected Class<?> getBeanClass(Element element)
51      {
52          return SimpleServiceFactoryBean.class;
53      }
54  
55      @Override
56      protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
57      {
58          final String componentRefAttribute = element.getAttribute(COMPONENT_REF_ATTRIBUTE);
59          if (StringUtils.isNotBlank(componentRefAttribute))
60          {
61              builder.addPropertyValue("componentBeanName", componentRefAttribute);
62          }
63          element.removeAttribute(COMPONENT_REF_ATTRIBUTE);
64  
65          super.doParse(element, parserContext, builder);
66      }
67  }