Package jfun.yan.xml.nuts.optional

Source Code of jfun.yan.xml.nuts.optional.InstanceOfNut

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);
  }
}
TOP

Related Classes of jfun.yan.xml.nuts.optional.InstanceOfNut

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.