KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > MappedComponent2


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 MappedComponent2<A,B,R> extends Component<R> {
24   private final Map2<A,B,R> m;
25   private final Creator<A> c1;
26   private final Creator<B> c2;
27   public boolean isConcrete(){
28     return false;
29   }
30   /**
31    * @param cc
32    */

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