View Javadoc

1   /*
2    * $Id: TransactionDefinitionParser.java 10489 2008-01-23 17:53:38Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
32      public TransactionDefinitionParser()
33      {
34          commonInit(null);
35      }
36  
37      public TransactionDefinitionParser(Class factoryClass)
38      {
39          commonInit(factoryClass);
40          MuleDefinitionParser factoryParser = getDelegate(1);
41          // don't allow these if the class is specified in the constructor
42          factoryParser.registerPreProcessor(new BlockAttribute(new String[]{FACTORY_CLASS, FACTORY_REF}));
43      }
44  
45      private void commonInit(Class factoryClass)
46      {
47          addDelegate(new TransactionConfigDefinitionParser())
48                  .setIgnoredDefault(true)
49                  .removeIgnored(FACTORY_REF)
50                  .removeIgnored(ACTION)
51                  .removeIgnored(TIMEOUT);
52          addDelegateAsChild(new ChildDefinitionParser(FACTORY, factoryClass))
53                  .setIgnoredDefault(false)
54                  .addIgnored(FACTORY_REF)
55                  .addIgnored(ACTION)
56                  .addIgnored(TIMEOUT)
57                  .addAlias(FACTORY_CLASS, AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS)
58                  // the ref is set on the parent
59                  .registerPreProcessor(new BlockAttribute(FACTORY));
60          addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME);
61          addHandledException(BlockAttribute.BlockAttributeException.class);
62      }
63  
64  }