KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > MappedComponent3


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  * Codehaus.org.
19  *
20  * @author Ben Yu
21  *
22  */

23 final class MappedComponent3<A,B,C,R> extends Component<R> {
24   private final Map3<A,B,C,R> m;
25   private final Creator<A> c1;
26   private final Creator<B> c2;
27   private final Creator<C> c3;
28   public boolean isConcrete(){
29     return false;
30   }
31   /**
32    * @param cc
33    */

34   public MappedComponent3(Creator<A> c1, Creator<B> c2, Creator<C> c3, Map3<A,B,C,R> m) {
35     this.c1 = c1;
36     this.c2 = c2;
37     this.c3 = c3;
38     this.m = m;
39   }
40   public Class JavaDoc<R> getType(){
41     return null;
42   }
43   public R create(Dependency dep){
44     return run_map(c1.create(dep), c2.create(dep), c3.create(dep));
45   }
46   public Class JavaDoc verify(Dependency dep){
47     c1.verify(dep);
48     c2.verify(dep);
49     c3.verify(dep);
50     return Object JavaDoc.class;
51   }
52   
53   public boolean equals(Object JavaDoc obj) {
54     if(obj instanceof MappedComponent3){
55       final MappedComponent3 mc2 = (MappedComponent3)obj;
56       return m.equals(mc2.m) && c1.equals(mc2.c1) && c2.equals(mc2.c2)
57       && c3.equals(mc2.c3);
58     }
59     else return false;
60   }
61   public int hashCode(){
62     return 31*(c1.hashCode()*31 + c2.hashCode()) + c3.hashCode();
63   }
64   public String JavaDoc toString(){
65     return "map (" + c1.toString() + "," + c2.toString() + "," + c3 + ")";
66   }
67   private R run_map(A o1, B o2, C o3){
68     try{
69       return m.map(o1, o2, o3);
70     }
71     catch(Error JavaDoc e){
72       throw e;
73     }
74     catch(YanException e){
75       throw e;
76     }
77     catch(Throwable JavaDoc e){
78       throw new jfun.yan.ComponentInstantiationException(e);
79     }
80   }
81   public boolean isSingleton(){
82     return false;
83   }
84 }
85
Popular Tags