| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.mock; |
| 17 | |
|
| 18 | |
import java.util.ArrayList; |
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.Enumeration; |
| 21 | |
import java.util.HashSet; |
| 22 | |
import java.util.Iterator; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.Map; |
| 25 | |
import java.util.Set; |
| 26 | |
|
| 27 | |
import javax.servlet.ServletContext; |
| 28 | |
|
| 29 | |
public class MockApplicationMap implements Map { |
| 30 | |
|
| 31 | 1341 | private ServletContext context_ = null; |
| 32 | |
|
| 33 | 1341 | public MockApplicationMap(ServletContext context) { |
| 34 | 1341 | context_ = context; |
| 35 | 1341 | } |
| 36 | |
|
| 37 | |
public void clear() { |
| 38 | 0 | Iterator keys = keySet().iterator(); |
| 39 | 0 | while (keys.hasNext()) { |
| 40 | 0 | context_.removeAttribute((String) keys.next()); |
| 41 | |
} |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
public boolean containsKey(Object key) { |
| 45 | 0 | return context_.getAttribute(key(key)) != null; |
| 46 | |
} |
| 47 | |
|
| 48 | |
public boolean containsValue(Object value) { |
| 49 | 0 | if (value == null) { |
| 50 | 0 | return false; |
| 51 | |
} |
| 52 | 0 | Enumeration keys = context_.getAttributeNames(); |
| 53 | 0 | while (keys.hasMoreElements()) { |
| 54 | 0 | Object next = context_.getAttribute((String) keys.nextElement()); |
| 55 | 0 | if (next == value) { |
| 56 | 0 | return true; |
| 57 | |
} |
| 58 | |
} |
| 59 | 0 | return false; |
| 60 | |
} |
| 61 | |
|
| 62 | |
public Set entrySet() { |
| 63 | 0 | Set set = new HashSet(); |
| 64 | 0 | Enumeration keys = context_.getAttributeNames(); |
| 65 | 0 | while (keys.hasMoreElements()) { |
| 66 | 0 | set.add(context_.getAttribute((String) keys.nextElement())); |
| 67 | |
} |
| 68 | 0 | return set; |
| 69 | |
} |
| 70 | |
|
| 71 | |
public boolean equals(Object o) { |
| 72 | 0 | return context_.equals(o); |
| 73 | |
} |
| 74 | |
|
| 75 | |
public Object get(Object key) { |
| 76 | 24 | return context_.getAttribute(key(key)); |
| 77 | |
} |
| 78 | |
|
| 79 | |
public int hashCode() { |
| 80 | 0 | return context_.hashCode(); |
| 81 | |
} |
| 82 | |
|
| 83 | |
public boolean isEmpty() { |
| 84 | 0 | return size() < 1; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public Set keySet() { |
| 88 | 0 | Set set = new HashSet(); |
| 89 | 0 | Enumeration keys = context_.getAttributeNames(); |
| 90 | 0 | while (keys.hasMoreElements()) { |
| 91 | 0 | set.add(keys.nextElement()); |
| 92 | |
} |
| 93 | 0 | return set; |
| 94 | |
} |
| 95 | |
|
| 96 | |
public Object put(Object key, Object value) { |
| 97 | 8 | if (value == null) { |
| 98 | 0 | return remove(key); |
| 99 | |
} |
| 100 | 8 | String skey = key(key); |
| 101 | 8 | Object previous = context_.getAttribute(skey); |
| 102 | 8 | context_.setAttribute(skey, value); |
| 103 | 8 | return previous; |
| 104 | |
} |
| 105 | |
|
| 106 | |
public void putAll(Map map) { |
| 107 | 0 | for (Iterator itr = map.entrySet().iterator(); itr.hasNext();) { |
| 108 | 0 | Map.Entry entry = (Entry) itr.next(); |
| 109 | 0 | String key = (String) entry.getKey(); |
| 110 | 0 | Object value = entry.getValue(); |
| 111 | 0 | context_.setAttribute(key, value); |
| 112 | |
} |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
public Object remove(Object key) { |
| 116 | 0 | String skey = key(key); |
| 117 | 0 | Object previous = context_.getAttribute(skey); |
| 118 | 0 | context_.removeAttribute(skey); |
| 119 | 0 | return previous; |
| 120 | |
} |
| 121 | |
|
| 122 | |
public int size() { |
| 123 | 0 | int n = 0; |
| 124 | 0 | Enumeration keys = context_.getAttributeNames(); |
| 125 | 0 | while (keys.hasMoreElements()) { |
| 126 | 0 | keys.nextElement(); |
| 127 | 0 | n++; |
| 128 | |
} |
| 129 | 0 | return n; |
| 130 | |
} |
| 131 | |
|
| 132 | |
public Collection values() { |
| 133 | 0 | List list = new ArrayList(); |
| 134 | 0 | Enumeration keys = context_.getAttributeNames(); |
| 135 | 0 | while (keys.hasMoreElements()) { |
| 136 | 0 | list.add(context_.getAttribute((String) keys.nextElement())); |
| 137 | |
} |
| 138 | 0 | return list; |
| 139 | |
} |
| 140 | |
|
| 141 | |
private String key(Object key) { |
| 142 | 32 | if (key == null) { |
| 143 | 0 | throw new IllegalArgumentException(); |
| 144 | 32 | } else if (key instanceof String) { |
| 145 | 32 | return (String) key; |
| 146 | |
} else { |
| 147 | 0 | return key.toString(); |
| 148 | |
} |
| 149 | |
} |
| 150 | |
|
| 151 | |
} |