1 28 29 package com.idaremedia.antx.flowcontrol.wrap; 30 31 import java.util.Collections ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 36 import org.apache.tools.ant.BuildException; 37 import org.apache.tools.ant.Location; 38 import org.apache.tools.ant.Project; 39 40 import com.idaremedia.antx.AntX; 41 import com.idaremedia.antx.AntXFixture; 42 import com.idaremedia.antx.AssertableTask; 43 import com.idaremedia.antx.apis.Nameable; 44 import com.idaremedia.antx.apis.Requester; 45 46 47 92 93 public final class Locals extends AssertableTask implements Nameable 94 { 95 99 public Locals() 100 { 101 super(AntX.flow+"Locals:"); 102 } 103 104 105 106 113 final void setBlocking(boolean denied) 114 { 115 m_isDenied = denied; 116 } 117 118 119 120 124 boolean isBlocking() 125 { 126 return m_isDenied; 127 } 128 129 130 131 138 public void setName(String name) 139 { 140 require_(name!=null,"setName- nonzro name"); 141 m_name = name; 142 } 143 144 145 149 public final String getName() 150 { 151 return m_name; 152 } 153 154 155 156 162 public void setInherit(boolean inherit) 163 { 164 m_inherit = inherit ? Boolean.TRUE : Boolean.FALSE; 165 } 166 167 168 169 173 public final Boolean getInheritFlag() 174 { 175 return m_inherit; 176 } 177 178 179 180 185 public final Boolean getInheritFlag(ConditionalLocal local) 186 { 187 Boolean f = local.getInheritFlag(); 188 if (f==null) { 189 f = getInheritFlag(); 190 } 191 return f; 192 } 193 194 195 196 200 public Object createProperty() 201 { 202 if (m_propertyItems==null) { 203 m_propertyItems = AntXFixture.newList(); 204 } 205 return newItem(m_propertyItems); 206 } 207 208 209 210 214 public Object createVariable() 215 { 216 if (m_variableItems==null) { 217 m_variableItems = AntXFixture.newList(); 218 } 219 return newItem(m_variableItems); 220 } 221 222 223 224 228 public final Object createVar() 229 { 230 return createVariable(); 231 } 232 233 234 235 240 protected void verifyCanExecute_(String calr) 241 { 242 super.verifyCanExecute_(calr); 243 try { 244 verifyNamed(m_propertyItems); 245 verifyNamed(m_variableItems); 246 } catch(BuildException bX) { 248 log(bX.getMessage(),Project.MSG_ERR); 249 if (bX.getLocation()==Location.UNKNOWN_LOCATION) { 250 bX = new BuildException(bX,getLocation()); 251 } 252 throw bX; 253 } 254 } 255 256 257 266 public void execute() 267 { 268 verifyCanExecute_("exec"); 269 270 Map ht = getProject().getReferences(); 271 synchronized(ht) { 272 if (ht.containsKey(getName())) { 273 String error = getAntXMsg("flow.locals.exists",getName()); 274 log(error,Project.MSG_ERR); 275 throw new BuildException(error,getLocation()); 276 } 277 ht.put(getName(),this); 278 } 279 } 280 281 282 283 291 public final boolean uninstall(Requester clnt) 292 { 293 boolean ok=true; 294 Map ht = getProject().getReferences(); 295 synchronized(ht) { 296 Object o = ht.get(getName()); 297 if (o==this) { 298 ht.remove(getName()); 299 } else { 300 String warning = getAntXMsg("flow.locals.not.installed",getName()); 301 clnt.problem(warning,Project.MSG_WARN); 302 ok = false; 303 } 304 } 305 return ok; 306 } 307 308 309 310 List getProperties() 311 { 312 return m_propertyItems; 313 } 314 315 316 List getVariableNames() 317 { 318 return getItemNames(m_variableItems); 319 } 320 321 322 List getVariables() 323 { 324 return m_variableItems; 325 } 326 327 328 boolean hasVariables() 329 { 330 return m_variableItems!=null; 331 } 332 333 334 private ConditionalLocal newItem(List list) 335 { 336 ConditionalLocal item = new ConditionalLocal(); 337 list.add(item); 338 return item; 339 } 340 341 342 private List getItemNames(List from) 343 { 344 List l = Collections.EMPTY_LIST; 345 if (from!=null) { 346 synchronized(from) { 347 l = AntXFixture.newList(from.size()); 348 for (int i=0,N=from.size();i<N;i++) { 349 ConditionalLocal local = (ConditionalLocal)from.get(i); 350 if (local.isEnabled()) { 351 l.add(local.getName()); 352 } 353 } 354 } 355 } 356 return l; 357 } 358 359 360 private void verifyNamed(List from) 361 { 362 if (from!=null) { 363 synchronized(from) { 364 Iterator itr= from.iterator(); 365 while (itr.hasNext()) { 366 ConditionalLocal local = (ConditionalLocal)itr.next(); 367 local.verifyNamed(); 368 } 369 } 370 } 371 } 372 373 374 private String m_name = "_macrolocals_"; 375 private boolean m_isDenied; 376 private List m_propertyItems,m_variableItems; 377 private Boolean m_inherit; 378 } 379 380 | Popular Tags |