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