KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > SimpleComponent


1 package jfun.yan;
2
3 import jfun.yan.util.Utils;
4
5 /**
6  * This abstract class provides a convenient way to create Component implementations
7  * that do not have dependencies to resolve.
8  * <p>
9  * @author Ben Yu
10  * Nov 12, 2005 11:05:17 AM
11  */

12 public abstract class SimpleComponent<T> extends Component<T> {
13   private final Class JavaDoc type;
14   
15   public SimpleComponent(Class JavaDoc type) {
16     this.type = type;
17   }
18
19   public Class JavaDoc getType() {
20     return type;
21   }
22   public boolean isConcrete(){
23     return true;
24   }
25   public T create(Dependency dep){
26     try{
27       return create();
28     }
29     catch(Throwable JavaDoc e){
30       final YanException ye = Utils.wrapInstantiationException(e);
31       ye.push(this);
32       throw ye;
33     }
34   }
35
36   public Class JavaDoc verify(Dependency dep){
37     return type;
38   }
39   /**
40    * Subclasses can override this method to provide actual creation logic.
41    * @return the component instance.
42    * @throws Throwable any error can be thrown out of here.
43    */

44   public abstract T create()throws Throwable JavaDoc;
45   public String JavaDoc toString(){
46     return ""+type;
47   }
48   public boolean isSingleton(){
49     return false;
50   }
51 }
52
Popular Tags