001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.transaction.config;
018
019import org.w3c.dom.Element;
020
021import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
022
023/**
024 * {@code NamespaceHandler} allowing for the configuration of
025 * declarative transaction management using either XML or using annotations.
026 *
027 * <p>This namespace handler is the central piece of functionality in the
028 * Spring transaction management facilities and offers two approaches
029 * to declaratively manage transactions.
030 *
031 * <p>One approach uses transaction semantics defined in XML using the
032 * {@code <tx:advice>} elements, the other uses annotations
033 * in combination with the {@code <tx:annotation-driven>} element.
034 * Both approached are detailed to great extent in the Spring reference manual.
035 *
036 * @author Rob Harrop
037 * @author Juergen Hoeller
038 * @since 2.0
039 */
040public class TxNamespaceHandler extends NamespaceHandlerSupport {
041
042        static final String TRANSACTION_MANAGER_ATTRIBUTE = "transaction-manager";
043
044        static final String DEFAULT_TRANSACTION_MANAGER_BEAN_NAME = "transactionManager";
045
046
047        static String getTransactionManagerName(Element element) {
048                return (element.hasAttribute(TRANSACTION_MANAGER_ATTRIBUTE) ?
049                                element.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE) : DEFAULT_TRANSACTION_MANAGER_BEAN_NAME);
050        }
051
052
053        @Override
054        public void init() {
055                registerBeanDefinitionParser("advice", new TxAdviceBeanDefinitionParser());
056                registerBeanDefinitionParser("annotation-driven", new AnnotationDrivenBeanDefinitionParser());
057                registerBeanDefinitionParser("jta-transaction-manager", new JtaTransactionManagerBeanDefinitionParser());
058        }
059
060}