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