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.support; 018 019import java.util.Timer; 020 021import javax.resource.spi.BootstrapContext; 022import javax.resource.spi.UnavailableException; 023import javax.resource.spi.XATerminator; 024import javax.resource.spi.work.WorkContext; 025import javax.resource.spi.work.WorkManager; 026import javax.transaction.TransactionSynchronizationRegistry; 027 028import org.springframework.lang.Nullable; 029import org.springframework.util.Assert; 030 031/** 032 * Simple implementation of the JCA 1.7 {@link javax.resource.spi.BootstrapContext} 033 * interface, used for bootstrapping a JCA ResourceAdapter in a local environment. 034 * 035 * <p>Delegates to the given WorkManager and XATerminator, if any. Creates simple 036 * local instances of {@code java.util.Timer}. 037 * 038 * @author Juergen Hoeller 039 * @since 2.0.3 040 * @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext) 041 * @see ResourceAdapterFactoryBean 042 */ 043public class SimpleBootstrapContext implements BootstrapContext { 044 045 @Nullable 046 private WorkManager workManager; 047 048 @Nullable 049 private XATerminator xaTerminator; 050 051 @Nullable 052 private TransactionSynchronizationRegistry transactionSynchronizationRegistry; 053 054 055 /** 056 * Create a new SimpleBootstrapContext for the given WorkManager, 057 * with no XATerminator available. 058 * @param workManager the JCA WorkManager to use (may be {@code null}) 059 */ 060 public SimpleBootstrapContext(@Nullable WorkManager workManager) { 061 this.workManager = workManager; 062 } 063 064 /** 065 * Create a new SimpleBootstrapContext for the given WorkManager and XATerminator. 066 * @param workManager the JCA WorkManager to use (may be {@code null}) 067 * @param xaTerminator the JCA XATerminator to use (may be {@code null}) 068 */ 069 public SimpleBootstrapContext(@Nullable WorkManager workManager, @Nullable XATerminator xaTerminator) { 070 this.workManager = workManager; 071 this.xaTerminator = xaTerminator; 072 } 073 074 /** 075 * Create a new SimpleBootstrapContext for the given WorkManager, XATerminator 076 * and TransactionSynchronizationRegistry. 077 * @param workManager the JCA WorkManager to use (may be {@code null}) 078 * @param xaTerminator the JCA XATerminator to use (may be {@code null}) 079 * @param transactionSynchronizationRegistry the TransactionSynchronizationRegistry 080 * to use (may be {@code null}) 081 * @since 5.0 082 */ 083 public SimpleBootstrapContext(@Nullable WorkManager workManager, @Nullable XATerminator xaTerminator, 084 @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry) { 085 086 this.workManager = workManager; 087 this.xaTerminator = xaTerminator; 088 this.transactionSynchronizationRegistry = transactionSynchronizationRegistry; 089 } 090 091 092 @Override 093 public WorkManager getWorkManager() { 094 Assert.state(this.workManager != null, "No WorkManager available"); 095 return this.workManager; 096 } 097 098 @Override 099 @Nullable 100 public XATerminator getXATerminator() { 101 return this.xaTerminator; 102 } 103 104 @Override 105 public Timer createTimer() throws UnavailableException { 106 return new Timer(); 107 } 108 109 @Override 110 public boolean isContextSupported(Class<? extends WorkContext> workContextClass) { 111 return false; 112 } 113 114 @Override 115 @Nullable 116 public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { 117 return this.transactionSynchronizationRegistry; 118 } 119 120}