001 package org.crsh.util;
002
003 import javax.servlet.ServletContext;
004 import java.util.Enumeration;
005 import java.util.Iterator;
006
007 /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */
008 public class ServletContextMap extends SimpleMap<String, Object> {
009
010 /** . */
011 private final ServletContext context;
012
013 public ServletContextMap(ServletContext context) {
014 this.context = context;
015 }
016
017 @Override
018 protected Iterator<String> keys() {
019 return new Iterator<String>() {
020 Enumeration<String> e = context.getAttributeNames();
021 public boolean hasNext() {
022 return e.hasMoreElements();
023 }
024 public String next() {
025 return e.nextElement();
026 }
027 public void remove() {
028 throw new UnsupportedOperationException();
029 }
030 };
031 }
032
033 @Override
034 public Object get(Object key) {
035 if (key instanceof String) {
036 return context.getAttribute((String)key);
037 } else {
038 return null;
039 }
040 }
041 }