KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Binder;
4 import jfun.yan.Component;
5 import jfun.yan.etc.InjectorHelper;
6 import jfun.yan.xml.nut.ComponentNut;
7
8 /**
9  * This Nut class instantiates an injector object that implements
10  * a given interface.
11  * <p>
12  * The injection logic is defined by the "binder" attribute that
13  * references a {@link jfun.yan.Binder} object.
14  * </p>
15  * <p>
16  * @author Ben Yu
17  * Nov 10, 2005 12:17:26 AM
18  */

19 public class InjectorNut extends ComponentNut {
20   public static final InjectorHelper helper = new InjectorHelper();
21   private Class JavaDoc itf;
22   private Binder injection;
23   
24   public Binder getInjection() {
25     checkMandatory("injection", injection);
26     return injection;
27   }
28
29   public void setInjection(Binder injection) {
30     this.injection = injection;
31   }
32   /*
33   public void set(Binder[] binders){
34     checkSingleChild(binders);
35     checkDuplicate("injection", injection);
36     this.injection = binders[0];
37   }*/

38   public void add(Binder binder){
39     checkDuplicate("injection", this.injection);
40     this.injection = binder;
41   }
42   public Class JavaDoc getType() {
43     checkMandatory("type", itf);
44     return itf;
45   }
46
47   public void setType(Class JavaDoc itf) {
48     this.itf = itf;
49   }
50
51   public Component eval(){
52     return helper.getInjectorComponent(getType(),
53         getInjection());
54   }
55
56 }
57
Popular Tags