Package jfun.yan.xml.nuts.optional

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

package jfun.yan.xml.nuts.optional;

import java.util.Map;

import jfun.util.Misc;
import jfun.yan.Component;
import jfun.yan.Components;
import jfun.yan.xml.nuts.DelegatingNut;
/**
* Nut class for getting a value from a map.
*
* <p>
* @author Ben Yu
* Nov 9, 2005 11:57:47 PM
*/
public class GetKeyNut extends DelegatingNut {
  private Object key;
 
  public Object getKey() {
    return key;
  }

  public void setKey(Object key) {
    this.key = key;
  }

  public Component eval(){
    final Component cc = getComponent();
    checkMandatory("key", key);
    checkMandatory("component", cc);
    final Class type = cc.getType();
    if(type!=null &&
        !jfun.yan.util.Utils.isCompatible(Map.class, cc)
    ){
      throw raise("cannot call get against "+
          Misc.getTypeName(type));
    }
    return Components.get(cc, key);
  }

}
TOP

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

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.