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.util.bridges.jsf.sun;
016    
017    import java.util.AbstractMap;
018    import java.util.Set;
019    
020    import javax.servlet.ServletContext;
021    
022    /**
023     * @author Neil Griffin
024     */
025    public class LiferayApplicationMap extends AbstractMap<String, Object> {
026    
027            public LiferayApplicationMap(ServletContext servletContext) {
028                    _servletContext = servletContext;
029            }
030    
031            @Override
032            public Set<Entry<String, Object>> entrySet() {
033                    throw new UnsupportedOperationException();
034            }
035    
036            @Override
037            public Object get(Object key) {
038                    return _servletContext.getAttribute(key.toString());
039            }
040    
041            @Override
042            public Object put(String key, Object value) {
043                    Object previousValue = get(key);
044    
045                    _servletContext.setAttribute(key.toString(), value);
046    
047                    return previousValue;
048            }
049    
050            @Override
051            public Object remove(Object key) {
052                    Object value = null;
053    
054                    if (key != null) {
055                            value = get(key);
056    
057                            _servletContext.removeAttribute(key.toString());
058                    }
059    
060                    return value;
061            }
062    
063            private ServletContext _servletContext;
064    
065    }