1 package jfun.yan.xml.nuts.optional; 2 3 import java.util.List ; 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 19 public class InjectionTypeCaseNut extends EntriesNut { 20 21 public InjectionTypeCaseNut() { 22 super.setKey_type(Class .class); 23 } 25 public void addCase(InjectionCase entry){ 26 super.addEntry(entry); 27 } 28 public Component eval() throws Exception { 29 final List 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 [] types = new Class [keylist.size()]; 36 keylist.toArray(types); 37 return Components.array(injections, Injection.class) 38 .map(new jfun.yan.Map(){ 39 public Object map(Object obj){ 40 final Injection[] injs = (Injection[])obj; 41 return new TypeCaseInjection(types, injs); 42 } 43 }).cast(Injection.class); 44 } 45 } 46 | Popular Tags |