View Javadoc

1   /*
2    * $Id: TransactionDefinitionParser.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  
11  package org.mule.config.spring.parsers.specific;
12  
13  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
14  import org.mule.config.spring.parsers.MuleDefinitionParser;
15  import org.mule.config.spring.parsers.delegate.AbstractSingleParentFamilyDefinitionParser;
16  import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
17  import org.mule.config.spring.parsers.processors.BlockAttribute;
18  
19  /**
20   * Generates a transaction config with embedded factory.  If no factory is defined, it's taken from the
21   * factory-class or factory-ref attributes.
22   */
23  public class TransactionDefinitionParser extends AbstractSingleParentFamilyDefinitionParser
24  {
25  
26      public static final String FACTORY = "factory";
27      public static final String FACTORY_REF = FACTORY + "-ref";
28      public static final String FACTORY_CLASS = FACTORY + "-" + AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS;
29      public static final String ACTION = "action";
30      public static final String TIMEOUT = "timeout";
31      public static final String INTERACT_WTH_EXTERNAL = "interactWithExternal";
32  
33      public TransactionDefinitionParser()
34      {
35          commonInit(null);
36      }
37  
38      public TransactionDefinitionParser(Class factoryClass)
39      {
40          commonInit(factoryClass);
41          MuleDefinitionParser factoryParser = getDelegate(1);
42          // don't allow these if the class is specified in the constructor
43          factoryParser.registerPreProcessor(new BlockAttribute(new String[]{FACTORY_CLASS, FACTORY_REF}));
44      }
45  
46      private void commonInit(Class factoryClass)
47      {
48          addDelegate(new TransactionConfigDefinitionParser())
49                  .setIgnoredDefault(true)
50                  .removeIgnored(FACTORY_REF)
51                  .removeIgnored(ACTION)
52                  .removeIgnored(TIMEOUT)
53                  .removeIgnored(INTERACT_WTH_EXTERNAL);
54          addDelegateAsChild(new ChildDefinitionParser(FACTORY, factoryClass))
55                  .setIgnoredDefault(false)
56                  .addIgnored(FACTORY_REF)
57                  .addIgnored(ACTION)
58                  .addIgnored(TIMEOUT)
59                  .addIgnored(INTERACT_WTH_EXTERNAL)
60                  .addAlias(FACTORY_CLASS, AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS)
61                  // the ref is set on the parent
62                  .registerPreProcessor(new BlockAttribute(FACTORY));
63          addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
64          addHandledException(BlockAttribute.BlockAttributeException.class);
65      }
66  
67  }