KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts.optional;
2
3 import java.util.List JavaDoc;
4
5
6 import jfun.yan.Component;
7 import jfun.yan.Components;
8 import jfun.yan.etc.injection.Injection;
9 import jfun.yan.etc.injection.InjectionUtils;
10 import jfun.yan.etc.injection.TypeCaseInjection;
11 import jfun.yan.xml.nuts.EntriesNut;
12
13 /**
14  * The Nut class for type-casing on injection target types.
15  * <p>
16  * @author Ben Yu
17  * Dec 17, 2005 12:33:28 PM
18  */

19 public class InjectionTypeCaseNut extends EntriesNut {
20   
21   public InjectionTypeCaseNut() {
22     super.setKey_type(Class JavaDoc.class);
23     //super.setOf(Component.class);
24
}
25   public void addCase(InjectionCase entry){
26     super.addEntry(entry);
27   }
28   public Component eval() throws Exception JavaDoc {
29     final List JavaDoc keylist = super.getKeys();
30     final Component[] vals = super.getEntryComponents();
31     final Component[] injections = new Component[vals.length];
32     for(int i=0; i<vals.length; i++){
33       injections[i] = InjectionUtils.toInjection(vals[i]);
34     }
35     final Class JavaDoc[] types = new Class JavaDoc[keylist.size()];
36     keylist.toArray(types);
37     return Components.array(injections, Injection.class)
38     .map(new jfun.yan.Map(){
39       public Object JavaDoc map(Object JavaDoc obj){
40         final Injection[] injs = (Injection[])obj;
41         return new TypeCaseInjection(types, injs);
42       }
43     }).cast(Injection.class);
44   }
45 }
46
Popular Tags