KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > MbindComponent


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 21, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

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

24 final class MbindComponent<From,To> extends Component<To> {
25   private final Creator<From> c1;
26   private final ComponentBinder<From,To> binder;
27   
28   MbindComponent(final Creator<From> c1, final ComponentBinder<From,To> binder) {
29     this.c1 = c1;
30     this.binder = binder;
31   }
32   
33   public Class JavaDoc<To> getType() {
34     return binder.bindType(c1.getType());
35   }
36   public boolean isConcrete(){
37     return false;
38   }
39   public To create(Dependency dep){
40     final From v1 = c1.create(dep);
41     return run_binder(binder, v1).create(dep);
42   }
43   public Class JavaDoc<To> verify(Dependency dep){
44     return binder.verify(c1.verify(dep)).verify(dep);
45   }
46   
47   public boolean equals(Object JavaDoc obj) {
48     if(obj instanceof MbindComponent){
49       final MbindComponent dc2 = (MbindComponent)obj;
50       return c1.equals(dc2.c1) && binder.equals(dc2.binder);
51     }
52     else return false;
53   }
54   public int hashCode() {
55     return c1.hashCode() * 31 + binder.hashCode();
56   }
57   public String JavaDoc toString() {
58     return "(" + c1 + ") >>= (" + binder + ")";
59   }
60   private Creator<To> run_binder(Binder<From,To> binder, From v){
61     try{
62       return binder.bind(v);
63     }
64     catch(Error JavaDoc e){
65       throw e;
66     }
67     catch(YanException e){
68       throw e;
69     }
70     catch(Throwable JavaDoc e){
71       throw new jfun.yan.ComponentInstantiationException(e);
72     }
73   }
74   public boolean isSingleton(){
75     return false;
76   }
77 }
78
Popular Tags