01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.webservices.saaj;
17:
18: import java.util.LinkedList;
19:
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: public class SAAJUniverse {
24:
25: private static final Log LOG = LogFactory
26: .getLog(SAAJUniverse.class);
27:
28: enum Type {
29: DEFAULT, AXIS1, AXIS2, SUN
30: }
31:
32: public static final Type DEFAULT = Type.DEFAULT;
33: public static final Type SUN = Type.SUN;
34: public static final Type AXIS1 = Type.AXIS1;
35: public static final Type AXIS2 = Type.AXIS2;
36:
37: private static final ThreadLocal<LinkedList<Type>> currentUniverse = new InheritableThreadLocal<LinkedList<Type>>();
38:
39: public void set(Type newUniverse) {
40: LinkedList<Type> universeList = currentUniverse.get();
41: if (universeList == null) {
42: universeList = new LinkedList<Type>();
43: currentUniverse.set(universeList);
44: }
45: universeList.add(newUniverse);
46: if (LOG.isDebugEnabled()) {
47: LOG.debug("Set universe: " + Thread.currentThread() + " "
48: + newUniverse);
49: }
50: }
51:
52: public void unset() {
53: LinkedList<Type> universeList = currentUniverse.get();
54: if (universeList != null && !universeList.isEmpty()) {
55: universeList.removeLast();
56: if (LOG.isDebugEnabled()) {
57: LOG.debug("Restored universe: "
58: + Thread.currentThread());
59: }
60: }
61: }
62:
63: static Type getCurrentUniverse() {
64: LinkedList<Type> universeList = currentUniverse.get();
65: if (universeList != null && !universeList.isEmpty()) {
66: return universeList.getLast();
67: } else {
68: return null;
69: }
70: }
71:
72: }
|