1 28 29 package com.idaremedia.antx; 30 31 import java.util.ArrayList ; 32 import java.util.Collection ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.Map ; 36 import java.util.Properties ; 37 38 import com.idaremedia.antx.apis.ProblemHandler; 39 40 69 70 public final class ExportedProperties implements FixtureCore, FixtureAdministrator 71 { 72 private static final String IAM_ = "ExportableProperties:"; 73 74 75 76 81 public ExportedProperties() 82 { 83 } 84 85 86 87 91 public PropertyHandle getProperty(String name) 92 { 93 AntX.require_(name!=null,IAM_,"get- nonzro name"); 94 95 synchronized(m_handles) { 96 PropertyHandle ph = (PropertyHandle)m_handles.get(name); 97 if (ph==null) { 98 ph = new PropertyHandle(); 99 m_handles.put(name, ph); 100 } 101 return ph; 102 } 103 } 104 105 106 107 113 public void putProperty(String name, Object valu) 114 { 115 PropertyHandle ph = getProperty(name); 116 ph.set(valu); 117 } 118 119 120 121 127 public boolean knowsProperty(String name) 128 { 129 AntX.require_(name!=null,IAM_,"check- nonzro name"); 130 131 synchronized(m_handles) { 132 return m_handles.containsKey(name); 133 } 134 } 135 136 137 138 146 public Object readProperty(String name, Object dflt) 147 { 148 AntX.require_(name!=null,IAM_,"read- nonzro name"); 149 150 synchronized(m_handles) { 151 PropertyHandle ph= (PropertyHandle)m_handles.get(name); 152 return (ph!=null) ? ph.get() : dflt; 153 } 154 } 155 156 157 158 164 public PropertyHandle removeProperty(String name) 165 { 166 AntX.require_(name!=null,IAM_,"remove- nonzro name"); 167 168 synchronized(m_handles) { 169 return (PropertyHandle)m_handles.remove(name); 170 } 171 } 172 173 174 175 181 public void removeProperties(Collection names) 182 { 183 AntX.require_(names!=null,IAM_,"remove- nonzro names"); 184 185 synchronized(m_handles) { 186 m_handles.keySet().removeAll(names); 187 } 188 } 189 190 191 192 199 public void retainProperties(Collection names) 200 { 201 AntX.require_(names!=null,IAM_,"retain- nonzro names"); 202 203 synchronized(m_handles) { 204 m_handles.keySet().retainAll(names); 205 } 206 } 207 208 209 210 217 public Properties copyOfProperties(Properties existingP) 218 { 219 if (existingP==null) { 220 existingP= new Properties (); 221 } 222 synchronized(m_handles) { 223 Iterator itr = m_handles.entrySet().iterator(); 224 while (itr.hasNext()) { 225 Map.Entry mE= (Map.Entry )itr.next(); 226 PropertyHandle ph= (PropertyHandle)mE.getValue(); 227 existingP.put(mE.getKey(),String.valueOf(ph.get())); } 229 } 230 return existingP; 231 } 232 233 234 235 242 public Collection copyOfPropertyNames() 243 { 244 synchronized(m_handles) { 245 return new ArrayList (m_handles.keySet()); 246 } 247 } 248 249 250 251 257 void clearProperties() 258 { 259 synchronized(m_handles) { 260 m_handles.clear(); 261 m_handles = new HashMap (111,0.8f); 262 } 263 } 264 265 266 269 private HashMap m_handles= new HashMap (111,0.8f); 270 271 272 273 277 278 283 public static final Properties copy(Properties fillin) 284 { 285 return Iteration.exportableProperties().copyOfProperties(fillin); 286 } 287 288 289 295 public static final boolean has(String name) 296 { 297 return Iteration.exportableProperties().knowsProperty(name); 298 } 299 300 301 305 public static final PropertyHandle get(String name) 306 { 307 return Iteration.exportableProperties().getProperty(name); 308 } 309 310 311 315 public static final void set(String name, Object valu) 316 { 317 Iteration.exportableProperties().putProperty(name,valu); 318 } 319 320 321 328 public static final void unset(String name) 329 { 330 Iteration.exportableProperties().putProperty(name,null); 331 } 332 333 334 339 public static final Object read(String name, Object dflt) 340 { 341 return Iteration.exportableProperties().readProperty(name,dflt); 342 } 343 344 345 350 public static final String readstring(String name, String dflt) 351 { 352 return (String )Iteration.exportableProperties().readProperty(name,dflt); 353 } 354 355 356 361 public static final Object read(String name) 362 { 363 return Iteration.exportableProperties().readProperty(name,null); 364 } 365 366 367 372 public static final String readstring(String name) 373 { 374 return (String )Iteration.exportableProperties().readProperty(name,null); 375 } 376 377 378 382 public static final void delete(String name) 383 { 384 Iteration.exportableProperties().removeProperty(name); 385 } 386 387 388 393 public static final void delete(Collection names) 394 { 395 Iteration.exportableProperties().removeProperties(names); 396 } 397 398 399 406 public static final void retain(Collection names) 407 { 408 Iteration.exportableProperties().retainProperties(names); 409 } 410 411 412 416 420 static { 421 AntXFixture.setKillMethod 422 (FixtureIds.VARIABLES_ADMINISTRATION, 423 new String []{"variables","exportedproperties"}, 424 new KillMethod() { 425 public boolean kill(ProblemHandler from) { 426 427 Iteration.exportableProperties().clearProperties(); 428 return true; 429 } 430 public boolean kill(String target, ProblemHandler from) { 431 return kill(from); 432 } 433 } 434 ); 435 } 436 } 437 438 439 | Popular Tags |