KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Binder;
4 import jfun.yan.Component;
5 import jfun.yan.xml.nuts.DelegatingNut;
6 /**
7  * This Nut class instantiates a proxy object that implements
8  * a given interface.
9  * <p>
10  * Return values of the methods defined in this interface are
11  * subject to automatic dependency injection.
12  * </p>
13  * <p>
14  * The injection logic is defined by the "binder" attribute that
15  * references a {@link jfun.yan.Binder} object.
16  * </p>
17  * <p>
18  * @author Ben Yu
19  * Nov 10, 2005 12:17:26 AM
20  */

21 public class InjectNut extends DelegatingNut {
22   private Class JavaDoc itf;
23   private Class JavaDoc injectee;
24   private Binder injection;
25   
26   public Class JavaDoc getInjectee() {
27     checkMandatory("injectee", injectee);
28     return injectee;
29   }
30
31   public void setInjectee(Class JavaDoc injectee) {
32     this.injectee = injectee;
33   }
34
35   public Binder getInjection() {
36     checkMandatory("injection", injection);
37     return injection;
38   }
39
40   public void setInjection(Binder injection) {
41     this.injection = injection;
42   }
43
44   public Class JavaDoc getType() {
45     checkMandatory("type", itf);
46     return itf;
47   }
48
49   public void setType(Class JavaDoc itf) {
50     this.itf = itf;
51   }
52
53   public Component eval(){
54     final Component proxied = getMandatory();
55     return InjectorNut.helper
56     .getProxyComponentReturningInjected(getComponentClassLoader(),
57         itf, proxied, injectee, injection);
58   }
59 }
60
Popular Tags