KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > BeanBinder


1 /*****************************************************************************
2  * Copyright (C) Codehaus.org. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Mar 7, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.yan;
15
16
17 /**
18  * Codehaus.org.
19  *
20  * @author Ben Yu
21  *
22  */

23 final class BeanBinder<T>
24 implements ComponentBinder<T,T>{
25   private final PropertiesInjector injector;
26   private final String JavaDoc name;
27   
28   BeanBinder(String JavaDoc name, PropertiesInjector injector) {
29     this.injector = injector;
30     this.name = name;
31   }
32   public Creator<T> bind(final T r){
33     return new Creator<T>(){
34       public T create(Dependency dep){
35         injector.injectProperties(r, dep);
36         return r;
37       }
38       public Class JavaDoc verify(Dependency dep){
39         final Class JavaDoc t = r==null?null:r.getClass();
40         injector.verifyProperties(t, dep);
41         return t;
42       }
43       public Class JavaDoc getType(){
44         return r.getClass();
45       }
46       public boolean isConcrete(){
47         return true;
48       }
49       public boolean isSingleton(){
50         return false;
51       }
52     };
53   }
54   public Verifiable verify(final Class JavaDoc t){
55     return new Verifiable(){
56       public Class JavaDoc verify(Dependency dep){
57         injector.verifyProperties(t, dep);
58         return t;
59       }
60     };
61   }
62   public Class JavaDoc bindType(Class JavaDoc t){
63     return void.class;
64   }
65   public String JavaDoc toString(){
66     return name;
67   }
68 }
69
Popular Tags