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.openejb.server.webservices.saaj;
17:
18: import java.util.LinkedList;
19:
20: import org.apache.openejb.util.Logger;
21: import org.apache.openejb.util.LogCategory;
22:
23: public class SaajUniverse {
24: private static final Logger logger = Logger.getInstance(
25: LogCategory.OPENEJB_WS, SaajUniverse.class);
26:
27: static {
28: setProperty("javax.xml.soap.MessageFactory",
29: "org.apache.openejb.server.webservices.saaj.MessageFactoryImpl");
30: setProperty("javax.xml.soap.SOAPFactory",
31: "org.apache.openejb.server.webservices.saaj.SoapFactoryImpl");
32: setProperty("javax.xml.soap.SOAPConnectionFactory",
33: "org.apache.openejb.server.webservices.saaj.SoapConnectionFactoryImpl");
34: setProperty("javax.xml.soap.MetaFactory",
35: "org.apache.openejb.server.webservices.saaj.MetaFactoryImpl");
36: }
37:
38: private static void setProperty(String name, String value) {
39: if (System.getProperty(name) == null) {
40: System.setProperty(name, value);
41: }
42: }
43:
44: enum Type {
45: DEFAULT, AXIS1, AXIS2, SUN
46: }
47:
48: public static final Type DEFAULT = Type.DEFAULT;
49: public static final Type SUN = Type.SUN;
50: public static final Type AXIS1 = Type.AXIS1;
51: public static final Type AXIS2 = Type.AXIS2;
52:
53: private static final ThreadLocal<LinkedList<Type>> currentUniverse = new InheritableThreadLocal<LinkedList<Type>>();
54:
55: public void set(Type newUniverse) {
56: LinkedList<Type> universeList = currentUniverse.get();
57: if (universeList == null) {
58: universeList = new LinkedList<Type>();
59: currentUniverse.set(universeList);
60: }
61: universeList.add(newUniverse);
62: if (logger.isDebugEnabled()) {
63: logger.debug("Set universe: " + Thread.currentThread()
64: + " " + newUniverse);
65: }
66: }
67:
68: public void unset() {
69: LinkedList<Type> universeList = currentUniverse.get();
70: if (universeList != null && !universeList.isEmpty()) {
71: universeList.removeLast();
72: if (logger.isDebugEnabled()) {
73: logger.debug("Restored universe: "
74: + Thread.currentThread());
75: }
76: }
77: }
78:
79: static Type getCurrentUniverse() {
80: LinkedList<Type> universeList = currentUniverse.get();
81: if (universeList != null && !universeList.isEmpty()) {
82: return universeList.getLast();
83: } else {
84: return null;
85: }
86: }
87:
88: }
|