KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > optional > InstanceOfNut


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Component;
4 import jfun.yan.Map;
5 import jfun.yan.util.ReflectionUtil;
6 import jfun.yan.xml.nuts.DelegatingNut;
7
8 /**
9  * A nut class to determine if the instance instantiated by a
10  * Component is of a certain type.
11  * <p>
12  * @author Ben Yu
13  * Nov 23, 2005 11:29:33 PM
14  */

15 public class InstanceOfNut extends DelegatingNut {
16   private Class JavaDoc of;
17
18   public void setClass(Class JavaDoc of) {
19     this.of = of;
20   }
21
22   public Component eval() throws Exception JavaDoc {
23     checkMandatory("class", of);
24     final Component cc = getMandatory();
25     return cc.map(new Map(){
26       public Object JavaDoc map(Object JavaDoc obj){
27         return Boolean.valueOf(ReflectionUtil.isInstance(of, obj));
28       }
29     }).cast(boolean.class);
30   }
31 }
32
Popular Tags