001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.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    }