001/*
002 * Copyright 2001-2004 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.apache.log4j;
018
019import java.util.Hashtable;
020import java.util.Map;
021
022public class MDC {
023
024    public static void put(String key, String value) {
025        org.slf4j.MDC.put(key, value);
026    }
027
028    public static void put(String key, Object value) {
029        if (value != null) {
030            put(key, value.toString());
031        } else {
032            put(key, null);
033        }
034    }
035
036    public static Object get(String key) {
037        return org.slf4j.MDC.get(key);
038    }
039
040    public static void remove(String key) {
041        org.slf4j.MDC.remove(key);
042    }
043
044    public static void clear() {
045        org.slf4j.MDC.clear();
046    }
047
048    /** 
049     * This method is not part of the Log4J public API. However it 
050     * has been called by other projects. This method is here temporarily  
051     * until projects who are depending on this method release fixes. 
052     * 
053     * @return a copy of the underlying map returned as a Hashtable
054     */
055    @SuppressWarnings({ "rawtypes", "unchecked" })
056    @Deprecated
057    public static Hashtable getContext() {
058        Map map = org.slf4j.MDC.getCopyOfContextMap();
059
060        if (map != null) {
061            return new Hashtable(map);
062        } else {
063            return new Hashtable();
064        }
065    }
066}