1 18 package org.apache.tools.ant.types.resources; 19 20 import java.util.Iterator ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 24 import org.apache.tools.ant.types.Resource; 25 import org.apache.tools.ant.types.ResourceCollection; 26 import org.apache.tools.ant.types.resources.selectors.ResourceSelector; 27 import org.apache.tools.ant.types.resources.selectors.ResourceSelectorContainer; 28 29 35 public class Restrict 36 extends ResourceSelectorContainer implements ResourceCollection { 37 38 private BaseResourceCollectionWrapper w = new BaseResourceCollectionWrapper() { 39 43 protected Collection getCollection() { 44 ArrayList result = new ArrayList (); 45 outer: for (Iterator ri = w.getResourceCollection().iterator(); ri.hasNext();) { 46 Resource r = (Resource) ri.next(); 47 for (Iterator i = getSelectors(); i.hasNext();) { 48 if (!((ResourceSelector) (i.next())).isSelected(r)) { 49 continue outer; 50 } 51 } 52 result.add(r); 53 } 54 return result; 55 } 56 }; 57 58 62 public synchronized void add(ResourceCollection c) { 63 if (isReference()) { 64 throw noChildrenAllowed(); 65 } 66 if (c == null) { 67 return; 68 } 69 w.add(c); 70 } 71 72 76 public synchronized void setCache(boolean b) { 77 w.setCache(b); 78 } 79 80 84 public synchronized boolean isCache() { 85 return w.isCache(); 86 } 87 88 92 public synchronized void add(ResourceSelector s) { 93 if (s == null) { 94 return; 95 } 96 super.add(s); 97 FailFast.invalidate(this); 98 } 99 100 104 public final synchronized Iterator iterator() { 105 if (isReference()) { 106 return ((Restrict) getCheckedRef()).iterator(); 107 } 108 dieOnCircularReference(); 109 return w.iterator(); 110 } 111 112 116 public synchronized int size() { 117 if (isReference()) { 118 return ((Restrict) getCheckedRef()).size(); 119 } 120 dieOnCircularReference(); 121 return w.size(); 122 } 123 124 128 public synchronized boolean isFilesystemOnly() { 129 if (isReference()) { 130 return ((Restrict) getCheckedRef()).isFilesystemOnly(); 131 } 132 dieOnCircularReference(); 133 return w.isFilesystemOnly(); 134 } 135 136 140 public synchronized String toString() { 141 if (isReference()) { 142 return getCheckedRef().toString(); 143 } 144 dieOnCircularReference(); 145 return w.toString(); 146 } 147 148 } 149 | Popular Tags |