1 18 package org.apache.tools.ant.types.resources.selectors; 19 20 import java.util.Stack ; 21 import java.util.Vector ; 22 import java.util.Iterator ; 23 import java.util.Collections ; 24 25 import org.apache.tools.ant.Project; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.types.DataType; 28 29 33 public class ResourceSelectorContainer extends DataType { 34 35 private Vector v = new Vector (); 36 37 40 public ResourceSelectorContainer() { 41 } 42 43 47 public ResourceSelectorContainer(ResourceSelector[] r) { 48 for (int i = 0; i < r.length; i++) { 49 add(r[i]); 50 } 51 } 52 53 57 public void add(ResourceSelector s) { 58 if (isReference()) { 59 throw noChildrenAllowed(); 60 } 61 if (s == null) { 62 return; 63 } 64 v.add(s); 65 setChecked(false); 66 } 67 68 72 public boolean hasSelectors() { 73 if (isReference()) { 74 return ((ResourceSelectorContainer) getCheckedRef()).hasSelectors(); 75 } 76 dieOnCircularReference(); 77 return !v.isEmpty(); 78 } 79 80 84 public int selectorCount() { 85 if (isReference()) { 86 return ((ResourceSelectorContainer) getCheckedRef()).selectorCount(); 87 } 88 dieOnCircularReference(); 89 return v.size(); 90 } 91 92 96 public Iterator getSelectors() { 97 if (isReference()) { 98 return ((ResourceSelectorContainer) getCheckedRef()).getSelectors(); 99 } 100 dieOnCircularReference(); 101 return Collections.unmodifiableList(v).iterator(); 102 } 103 104 110 protected void dieOnCircularReference(Stack stk, Project p) 111 throws BuildException { 112 if (isChecked()) { 113 return; 114 } 115 if (isReference()) { 116 super.dieOnCircularReference(stk, p); 117 } else { 118 for (Iterator i = v.iterator(); i.hasNext();) { 119 Object o = i.next(); 120 if (o instanceof DataType) { 121 stk.push(o); 122 invokeCircularReferenceCheck((DataType) o, stk, p); 123 } 124 } 125 setChecked(true); 126 } 127 } 128 129 } 130 | Popular Tags |