1 16 21 package org.apache.jetspeed.portal.portlets; 22 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Set ; 28 29 import org.apache.velocity.context.Context; 30 31 48 49 56 public class GenericMVCContext implements Context 57 { 58 59 private HashMap data; 60 private HashSet additionalContexts; 61 62 63 public GenericMVCContext() 64 { 65 data = new HashMap (); 66 additionalContexts = new HashSet (); 67 68 } 69 70 77 public GenericMVCContext(Collection contexts) 78 { 79 this(); 80 additionalContexts.addAll(contexts); 81 } 82 83 90 public GenericMVCContext(Context context) 91 { 92 this(); 93 additionalContexts.add(context); 94 } 95 96 97 public boolean containsKey(java.lang.Object key) 98 { 99 boolean found = data.containsKey(key); 100 if (!found) 101 { 102 Iterator itr = additionalContexts.iterator(); 103 while (itr.hasNext() && !found) 104 { 105 found = ((Context) itr.next()).containsKey(key); 106 } 107 } 108 109 return found; 110 } 111 112 public Object get(java.lang.String key) 113 { 114 Object value = data.get(key); 115 116 if (value == null) 118 { 119 Iterator itr = additionalContexts.iterator(); 120 while (itr.hasNext() && value == null) 121 { 122 value = ((Context) itr.next()).get(key); 123 } 124 } 125 126 return value; 127 } 128 129 public Object [] getKeys() 130 { 131 Set keySet = data.keySet(); 132 133 Iterator itr = additionalContexts.iterator(); 134 135 while (itr.hasNext()) 136 { 137 Object [] keys = ((Context) itr.next()).getKeys(); 138 for (int i = 0; i < keys.length; i++) 139 { 140 keySet.add(keys[i]); 141 } 142 } 143 144 return data.keySet().toArray(); 146 } 147 148 public Object put(java.lang.String key, java.lang.Object value) 149 { 150 151 return data.put(key, value); 152 } 153 154 public Object remove(java.lang.Object key) 155 { 156 Object obj = data.remove(key); 157 if (obj == null) 158 { 159 Iterator itr = additionalContexts.iterator(); 160 while (itr.hasNext() && obj == null) 161 { 162 obj = ((Context) itr.next()).remove(key); 163 } 164 } 165 166 return obj; 167 } 168 169 174 public void addContext(Context context) 175 { 176 additionalContexts.add(context); 177 } 178 179 187 public Collection getChainedContexts() 188 { 189 return additionalContexts; 190 } 191 192 } 193 | Popular Tags |