001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.webservices.saaj; 018 019 import java.util.LinkedList; 020 021 import org.apache.commons.logging.Log; 022 import org.apache.commons.logging.LogFactory; 023 024 public class SAAJUniverse { 025 026 private static final Log LOG = LogFactory.getLog(SAAJUniverse.class); 027 028 enum Type { DEFAULT, AXIS1, AXIS2, SUN } 029 030 public static final Type DEFAULT = Type.DEFAULT; 031 public static final Type SUN = Type.SUN; 032 public static final Type AXIS1 = Type.AXIS1; 033 public static final Type AXIS2 = Type.AXIS2; 034 035 private static final ThreadLocal<LinkedList<Type>> currentUniverse = 036 new InheritableThreadLocal<LinkedList<Type>>(); 037 038 public void set(Type newUniverse) { 039 LinkedList<Type> universeList = currentUniverse.get(); 040 if (universeList == null) { 041 universeList = new LinkedList<Type>(); 042 currentUniverse.set(universeList); 043 } 044 universeList.add(newUniverse); 045 if (LOG.isDebugEnabled()) { 046 LOG.debug("Set universe: " + Thread.currentThread() + " " + newUniverse); 047 } 048 } 049 050 public void unset() { 051 LinkedList<Type> universeList = currentUniverse.get(); 052 if (universeList != null && !universeList.isEmpty()) { 053 universeList.removeLast(); 054 if (LOG.isDebugEnabled()) { 055 LOG.debug("Restored universe: " + Thread.currentThread()); 056 } 057 } 058 } 059 060 static Type getCurrentUniverse() { 061 LinkedList<Type> universeList = currentUniverse.get(); 062 if (universeList != null && !universeList.isEmpty()) { 063 return universeList.getLast(); 064 } else { 065 return null; 066 } 067 } 068 069 }