View Javadoc
1 package xdoclet; 2 3 import org.apache.commons.collections.CollectionUtils; 4 import org.apache.commons.collections.Predicate; 5 6 import xdoclet.util.predicates.PredicateFactory; 7 import xdoclet.util.predicates.SimplePredicateFactory; 8 import xdoclet.beans.BeanContextSupportEx; 9 10 /*** 11 * Accept is an aggregator of predicates used to filter out certain classes. 12 * 13 * @see Predicate 14 * @see PredicateFactory 15 * 16 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a> 17 * @version $Revision: 1.6 $ 18 */ 19 public class Accept extends BeanContextSupportEx implements Predicate { 20 private static final PredicateFactory PREDICATE_FACTORY = new SimplePredicateFactory(); 21 22 /*** 23 * This method is here so that the predicate can be set from Ant. 24 * 25 * @param predicateType the name of the predicate to add. 26 * @return a Predicate 27 * @throws XDocletException if there is no registered Predicate class for the predicateType 28 */ 29 public Object createElement(String predicateType) 30 throws XDocletException { 31 if (getPredicate() != null) { 32 throw new XDocletException("Only one predicate allowed under accept"); 33 } 34 35 Predicate predicate = PREDICATE_FACTORY.createPredicate(predicateType); 36 37 setPredicate(predicate); 38 39 return predicate; 40 } 41 42 private Predicate getPredicate() { 43 return (Predicate) CollectionUtils.find(this, 44 new Predicate() { 45 public boolean evaluate(Object o) { 46 return o instanceof Predicate; 47 } 48 }); 49 } 50 51 /*** 52 * Sets the predicate to use. 53 * 54 * @param predicate the predicate to use. 55 */ 56 public void setPredicate(Predicate predicate) { 57 add(predicate); 58 } 59 60 /*** 61 * Evaluates the predicate. 62 * 63 * @return true if the predicate evaluates to true. 64 * @see #setPredicate 65 */ 66 public boolean evaluate(Object o) { 67 if (getPredicate() == null) { 68 throw new IllegalStateException("One predicate must be specified under accept"); 69 } 70 71 return getPredicate().evaluate(o); 72 } 73 }

This page was automatically generated by Maven