KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > etc > FilteredPropertyBinder


1 package jfun.yan.etc;
2
3 import jfun.yan.Creator;
4 import jfun.yan.PropertyBinder;
5
6 /**
7  * A PropertyBinder decorator that will return a Creator instance
8  * if the property satisfies a predicate. Otherwise, control is forwarded
9  * to an alternative PropertyBinder instance.
10  * <p>
11  * @author Ben Yu
12  * Jan 18, 2006 9:27:52 PM
13  */

14 public class FilteredPropertyBinder implements PropertyBinder {
15   private final PropertyBinder alternative;
16   private final PropertyPredicate pred;
17   private final Creator consequence;
18   public Creator bind(Class JavaDoc component_type, Object JavaDoc key, Class JavaDoc type) {
19     if(pred.isProperty(component_type, key, type)){
20       return consequence;
21     }
22     else{
23       return alternative.bind(component_type, key, type);
24     }
25   }
26   /**
27    * Create a FilteredPropertyBinder instance.
28    * @param pred the predicate.
29    * @param consequence the consequence.
30    * @param alternative the alternative.
31    */

32   public FilteredPropertyBinder(PropertyPredicate pred,
33       Creator consequence, PropertyBinder alternative) {
34     this.pred = pred;
35     this.consequence = consequence;
36     this.alternative = alternative;
37   }
38 }
39
Popular Tags