1 18 19 package org.apache.jmeter.testelement.property; 20 21 import java.util.Map ; 22 23 import org.apache.jmeter.testelement.TestElement; 24 25 28 public class MapProperty extends MultiProperty 29 { 30 Map value; 31 Map savedValue = null; 32 33 public MapProperty(String name, Map value) 34 { 35 super(name); 36 log.info("map = " + value); 37 this.value = normalizeMap(value); 38 log.info("normalized map = " + this.value); 39 } 40 41 public MapProperty() 42 { 43 super(); 44 } 45 46 public boolean equals(Object o) 47 { 48 if (o instanceof MapProperty) 49 { 50 if (value != null) 51 { 52 return value.equals(((JMeterProperty) o).getObjectValue()); 53 } 54 } 55 return false; 56 } 57 58 public void setObjectValue(Object v) 59 { 60 if (v instanceof Map ) 61 { 62 setMap((Map ) v); 63 } 64 } 65 66 public void addProperty(JMeterProperty prop) 67 { 68 addProperty(prop.getName(), prop); 69 } 70 71 public JMeterProperty get(String key) 72 { 73 return (JMeterProperty) value.get(key); 74 } 75 76 81 protected Class getPropertyType() 82 { 83 if (value.size() > 0) 84 { 85 return valueIterator().next().getClass(); 86 } 87 else 88 { 89 return NullProperty.class; 90 } 91 } 92 93 96 public String getStringValue() 97 { 98 return value.toString(); 99 } 100 101 104 public Object getObjectValue() 105 { 106 return value; 107 } 108 109 112 public Object clone() 113 { 114 MapProperty prop = (MapProperty) super.clone(); 115 prop.value = cloneMap(); 116 return prop; 117 } 118 119 private Map cloneMap() 120 { 121 try 122 { 123 Map newCol = (Map ) value.getClass().newInstance(); 124 PropertyIterator iter = valueIterator(); 125 while (iter.hasNext()) 126 { 127 JMeterProperty item = iter.next(); 128 newCol.put(item.getName(), item.clone()); 129 } 130 return newCol; 131 } 132 catch (Exception e) 133 { 134 log.error("Couldn't clone map", e); 135 return value; 136 } 137 } 138 139 public PropertyIterator valueIterator() 140 { 141 return getIterator(value.values()); 142 } 143 144 public void addProperty(String name, JMeterProperty prop) 145 { 146 if (!value.containsKey(name)) 147 { 148 value.put(name, prop); 149 } 150 } 151 152 public void setMap(Map newMap) 153 { 154 value = normalizeMap(newMap); 155 } 156 157 160 public void recoverRunningVersion(TestElement owner) 161 { 162 if (savedValue != null) 163 { 164 value = savedValue; 165 } 166 recoverRunningVersionOfSubElements(owner); 167 } 168 169 public void clear() 170 { 171 value.clear(); 172 } 173 174 177 public PropertyIterator iterator() 178 { 179 return valueIterator(); 180 } 181 182 185 public void setRunningVersion(boolean running) 186 { 187 super.setRunningVersion(running); 188 if (running) 189 { 190 savedValue = value; 191 } 192 else 193 { 194 savedValue = null; 195 } 196 } 197 } 198 | Popular Tags |