1 16 package org.apache.commons.chain.web.portlet; 17 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.Enumeration ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import javax.portlet.PortletContext; 28 29 30 37 38 final class PortletInitParamMap implements Map { 39 40 41 public PortletInitParamMap(PortletContext context) { 42 this.context = context; 43 } 44 45 46 private PortletContext context = null; 47 48 49 public void clear() { 50 throw new UnsupportedOperationException (); 51 } 52 53 54 public boolean containsKey(Object key) { 55 return (context.getInitParameter(key(key)) != null); 56 } 57 58 59 public boolean containsValue(Object value) { 60 Iterator values = values().iterator(); 61 while (values.hasNext()) { 62 if (value.equals(values.next())) { 63 return (true); 64 } 65 } 66 return (false); 67 } 68 69 70 public Set entrySet() { 71 Set set = new HashSet (); 72 Enumeration keys = context.getInitParameterNames(); 73 while (keys.hasMoreElements()) { 74 set.add(context.getInitParameter((String ) keys.nextElement())); 75 } 76 return (set); 77 } 78 79 80 public boolean equals(Object o) { 81 return (context.equals(o)); 82 } 83 84 85 public Object get(Object key) { 86 return (context.getInitParameter(key(key))); 87 } 88 89 90 public int hashCode() { 91 return (context.hashCode()); 92 } 93 94 95 public boolean isEmpty() { 96 return (size() < 1); 97 } 98 99 100 public Set keySet() { 101 Set set = new HashSet (); 102 Enumeration keys = context.getInitParameterNames(); 103 while (keys.hasMoreElements()) { 104 set.add(keys.nextElement()); 105 } 106 return (set); 107 } 108 109 110 public Object put(Object key, Object value) { 111 throw new UnsupportedOperationException (); 112 } 113 114 115 public void putAll(Map map) { 116 throw new UnsupportedOperationException (); 117 } 118 119 120 public Object remove(Object key) { 121 throw new UnsupportedOperationException (); 122 } 123 124 125 public int size() { 126 int n = 0; 127 Enumeration keys = context.getInitParameterNames(); 128 while (keys.hasMoreElements()) { 129 keys.nextElement(); 130 n++; 131 } 132 return (n); 133 } 134 135 136 public Collection values() { 137 List list = new ArrayList (); 138 Enumeration keys = context.getInitParameterNames(); 139 while (keys.hasMoreElements()) { 140 list.add(context.getInitParameter((String ) keys.nextElement())); 141 } 142 return (list); 143 } 144 145 146 private String key(Object key) { 147 if (key == null) { 148 throw new IllegalArgumentException (); 149 } else if (key instanceof String ) { 150 return ((String ) key); 151 } else { 152 return (key.toString()); 153 } 154 } 155 156 157 } 158 | Popular Tags |