KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts.optional;
2
3 import java.util.Map JavaDoc;
4
5 import jfun.util.Misc;
6 import jfun.yan.Component;
7 import jfun.yan.Components;
8 import jfun.yan.xml.nuts.DelegatingNut;
9 /**
10  * Nut class for getting a value from a map.
11  *
12  * <p>
13  * @author Ben Yu
14  * Nov 9, 2005 11:57:47 PM
15  */

16 public class GetKeyNut extends DelegatingNut {
17   private Object JavaDoc key;
18   
19   public Object JavaDoc getKey() {
20     return key;
21   }
22
23   public void setKey(Object JavaDoc key) {
24     this.key = key;
25   }
26
27   public Component eval(){
28     final Component cc = getComponent();
29     checkMandatory("key", key);
30     checkMandatory("component", cc);
31     final Class JavaDoc type = cc.getType();
32     if(type!=null &&
33         !jfun.yan.util.Utils.isCompatible(Map JavaDoc.class, cc)
34     ){
35       throw raise("cannot call get against "+
36           Misc.getTypeName(type));
37     }
38     return Components.get(cc, key);
39   }
40
41 }
42
Popular Tags