01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.jca.support;
18:
19: import java.util.Timer;
20:
21: import javax.resource.spi.BootstrapContext;
22: import javax.resource.spi.UnavailableException;
23: import javax.resource.spi.XATerminator;
24: import javax.resource.spi.work.WorkManager;
25:
26: /**
27: * Simple implementation of the JCA 1.5 {@link javax.resource.spi.BootstrapContext}
28: * interface, used for bootstrapping a JCA ResourceAdapter in a local environment.
29: *
30: * <p>Delegates to the given WorkManager and XATerminator, if any. Creates simple
31: * local instances of <code>java.util.Timer</code>.
32: *
33: * @author Juergen Hoeller
34: * @since 2.0.3
35: * @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext)
36: * @see ResourceAdapterFactoryBean
37: */
38: public class SimpleBootstrapContext implements BootstrapContext {
39:
40: private WorkManager workManager;
41:
42: private XATerminator xaTerminator;
43:
44: /**
45: * Create a new SimpleBootstrapContext for the given WorkManager,
46: * with no XATerminator available.
47: * @param workManager the JCA WorkManager to use (may be <code>null</code>)
48: */
49: public SimpleBootstrapContext(WorkManager workManager) {
50: this .workManager = workManager;
51: }
52:
53: /**
54: * Create a new SimpleBootstrapContext for the given WorkManager and XATerminator.
55: * @param workManager the JCA WorkManager to use (may be <code>null</code>)
56: * @param xaTerminator the JCA XATerminator to use (may be <code>null</code>)
57: */
58: public SimpleBootstrapContext(WorkManager workManager,
59: XATerminator xaTerminator) {
60: this .workManager = workManager;
61: this .xaTerminator = xaTerminator;
62: }
63:
64: public WorkManager getWorkManager() {
65: if (this .workManager == null) {
66: throw new IllegalStateException("No WorkManager available");
67: }
68: return this .workManager;
69: }
70:
71: public XATerminator getXATerminator() {
72: return this .xaTerminator;
73: }
74:
75: public Timer createTimer() throws UnavailableException {
76: return new Timer();
77: }
78:
79: }
|