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