1 /*
2 * Copyright 2005-2010 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.ws.transport.context;
18
19 /**
20 * Simple holder class that associates a <code>TransportContext</code> instance with the current thread. The
21 * <code>TransportContext</code> will be inherited by any child threads spawned by the current thread.
22 *
23 * @author Arjen Poutsma
24 * @see TransportContext
25 * @since 1.0.0
26 */
27 public abstract class TransportContextHolder {
28
29 private static final ThreadLocal<TransportContext> transportContextHolder = new TransportThreadLocal();
30
31 /**
32 * Associate the given <code>TransportContext</code> with the current thread.
33 *
34 * @param transportContext the current transport context, or <code>null</code> to reset the thread-bound context
35 */
36 public static void setTransportContext(TransportContext transportContext) {
37 transportContextHolder.set(transportContext);
38 }
39
40 /**
41 * Return the <code>TransportContext</code> associated with the current thread, if any.
42 *
43 * @return the current transport context, or <code>null</code> if none
44 */
45 public static TransportContext getTransportContext() {
46 return transportContextHolder.get();
47 }
48
49 private static class TransportThreadLocal extends ThreadLocal<TransportContext> {
50
51 public String toString() {
52 return "Transport State";
53 }
54 }
55 }