001    /**
002     * Copyright (c) 2000-2010 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.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            public Set<Entry<String, Object>> entrySet() {
032                    throw new UnsupportedOperationException();
033            }
034    
035            public Object get(Object key) {
036                    return _servletContext.getAttribute(key.toString());
037            }
038    
039            public Object put(String key, Object value) {
040                    Object previousValue = get(key);
041    
042                    _servletContext.setAttribute(key.toString(), value);
043    
044                    return previousValue;
045            }
046    
047            public Object remove(Object key) {
048                    Object value = null;
049    
050                    if (key != null) {
051                            value = get(key);
052    
053                            _servletContext.removeAttribute(key.toString());
054                    }
055    
056                    return value;
057            }
058    
059            private ServletContext _servletContext;
060    
061    }