001/*
002 * Copyright 2012-2017 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 *      http://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.boot.jta.atomikos;
018
019import org.springframework.beans.factory.BeanNameAware;
020import org.springframework.beans.factory.DisposableBean;
021import org.springframework.beans.factory.InitializingBean;
022import org.springframework.boot.context.properties.ConfigurationProperties;
023import org.springframework.util.StringUtils;
024
025/**
026 * Spring friendly version of {@link com.atomikos.jms.AtomikosConnectionFactoryBean}.
027 *
028 * @author Phillip Webb
029 * @author Andy Wilkinson
030 * @since 1.2.0
031 */
032@SuppressWarnings("serial")
033@ConfigurationProperties(prefix = "spring.jta.atomikos.connectionfactory")
034public class AtomikosConnectionFactoryBean
035                extends com.atomikos.jms.AtomikosConnectionFactoryBean
036                implements BeanNameAware, InitializingBean, DisposableBean {
037
038        private String beanName;
039
040        @Override
041        public void setBeanName(String name) {
042                this.beanName = name;
043        }
044
045        @Override
046        public void afterPropertiesSet() throws Exception {
047                if (!StringUtils.hasLength(getUniqueResourceName())) {
048                        setUniqueResourceName(this.beanName);
049                }
050                init();
051        }
052
053        @Override
054        public void destroy() throws Exception {
055                close();
056        }
057
058}