1 16 17 package org.apache.commons.configuration.web; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 import javax.servlet.Servlet ; 22 import javax.servlet.ServletConfig ; 23 24 import org.apache.commons.collections.iterators.EnumerationIterator; 25 import org.apache.commons.configuration.AbstractConfiguration; 26 import org.apache.commons.configuration.PropertyConverter; 27 28 37 public class ServletConfiguration extends AbstractConfiguration 38 { 39 protected ServletConfig config; 40 41 47 public ServletConfiguration(Servlet servlet) 48 { 49 this(servlet.getServletConfig()); 50 } 51 52 57 public ServletConfiguration(ServletConfig config) 58 { 59 this.config = config; 60 } 61 62 public Object getProperty(String key) 63 { 64 Object value = config.getInitParameter(key); 65 List list = PropertyConverter.split((String ) value, getDelimiter()); 66 67 return list.size() > 1 ? list : value; 68 } 69 70 76 protected void addPropertyDirect(String key, Object obj) 77 { 78 throw new UnsupportedOperationException ("Read only configuration"); 79 } 80 81 public boolean isEmpty() 82 { 83 return !getKeys().hasNext(); 84 } 85 86 public boolean containsKey(String key) 87 { 88 return getProperty(key) != null; 89 } 90 91 97 public void clearProperty(String key) 98 { 99 throw new UnsupportedOperationException ("Read only configuration"); 100 } 101 102 public Iterator getKeys() 103 { 104 return new EnumerationIterator(config.getInitParameterNames()); 105 } 106 107 } 108 | Popular Tags |