package jfun.yan.xml.nuts.optional;
import jfun.yan.Component;
import jfun.yan.Map;
import jfun.yan.util.ReflectionUtil;
import jfun.yan.xml.nuts.DelegatingNut;
/**
* A nut class to determine if the instance instantiated by a
* Component is of a certain type.
* <p>
* @author Ben Yu
* Nov 23, 2005 11:29:33 PM
*/
public class InstanceOfNut extends DelegatingNut {
private Class of;
public void setClass(Class of) {
this.of = of;
}
public Component eval() throws Exception {
checkMandatory("class", of);
final Component cc = getMandatory();
return cc.map(new Map(){
public Object map(Object obj){
return Boolean.valueOf(ReflectionUtil.isInstance(of, obj));
}
}).cast(boolean.class);
}
}