001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.messaging.proxy;
016    
017    import com.liferay.portal.kernel.util.AutoResetThreadLocal;
018    
019    import java.util.Collections;
020    import java.util.HashMap;
021    import java.util.Map;
022    
023    /**
024     * @author Tina Tian
025     */
026    public class MessageValuesThreadLocal {
027    
028            public static Object getValue(String key) {
029                    Map<String, Object> messageValues = _messageValuesThreadLocal.get();
030    
031                    if (messageValues == null) {
032                            return null;
033                    }
034    
035                    return messageValues.get(key);
036            }
037    
038            public static Map<String, Object> getValues() {
039                    Map<String, Object> messageValues = _messageValuesThreadLocal.get();
040    
041                    if (messageValues == null) {
042                            return Collections.EMPTY_MAP;
043                    }
044    
045                    return messageValues;
046            }
047    
048            public static void setValue(String key, Object value) {
049                    Map<String, Object> messageValues = _messageValuesThreadLocal.get();
050    
051                    if (messageValues == null) {
052                            messageValues = new HashMap<String, Object>();
053    
054                            _messageValuesThreadLocal.set(messageValues);
055                    }
056    
057                    messageValues.put(key, value);
058            }
059    
060            private static ThreadLocal<Map<String, Object>> _messageValuesThreadLocal =
061                    new AutoResetThreadLocal<Map<String, Object>>(
062                            MessageValuesThreadLocal.class.getName());
063    
064    }