001/*
002 * Copyright 2002-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 *      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.jca.cci.object;
018
019import javax.resource.cci.ConnectionFactory;
020import javax.resource.cci.InteractionSpec;
021
022import org.springframework.beans.factory.InitializingBean;
023import org.springframework.jca.cci.core.CciTemplate;
024import org.springframework.util.Assert;
025
026/**
027 * Base class for EIS operation objects that work with the CCI API.
028 * Encapsulates a CCI ConnectionFactory and a CCI InteractionSpec.
029 *
030 * <p>Works with a CciTemplate instance underneath. EIS operation objects
031 * are an alternative to working with a CciTemplate directly.
032 *
033 * @author Juergen Hoeller
034 * @since 1.2
035 * @see #setConnectionFactory
036 * @see #setInteractionSpec
037 */
038public abstract class EisOperation implements InitializingBean {
039
040        private CciTemplate cciTemplate = new CciTemplate();
041
042        private InteractionSpec interactionSpec;
043
044
045        /**
046         * Set the CciTemplate to be used by this operation.
047         * Alternatively, specify a CCI ConnectionFactory.
048         * @see #setConnectionFactory
049         */
050        public void setCciTemplate(CciTemplate cciTemplate) {
051                Assert.notNull(cciTemplate, "CciTemplate must not be null");
052                this.cciTemplate = cciTemplate;
053        }
054
055        /**
056         * Return the CciTemplate used by this operation.
057         */
058        public CciTemplate getCciTemplate() {
059                return this.cciTemplate;
060        }
061
062        /**
063         * Set the CCI ConnectionFactory to be used by this operation.
064         */
065        public void setConnectionFactory(ConnectionFactory connectionFactory) {
066                this.cciTemplate.setConnectionFactory(connectionFactory);
067        }
068
069        /**
070         * Set the CCI InteractionSpec for this operation.
071         */
072        public void setInteractionSpec(InteractionSpec interactionSpec) {
073                this.interactionSpec = interactionSpec;
074        }
075
076        /**
077         * Return the CCI InteractionSpec for this operation.
078         */
079        public InteractionSpec getInteractionSpec() {
080                return this.interactionSpec;
081        }
082
083
084        @Override
085        public void afterPropertiesSet() {
086                this.cciTemplate.afterPropertiesSet();
087
088                if (this.interactionSpec == null) {
089                        throw new IllegalArgumentException("InteractionSpec is required");
090                }
091        }
092
093}