KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > TheFactoryComponent


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solution. 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 /*
10  * Created on Apr 15, 2005
11  *
12  * Author Ben Yu
13  * ZBS
14  */

15 package jfun.yan;
16
17 import jfun.yan.factory.Factory;
18
19 /**
20  * Every component is a factory.
21  * TheFactoryComponent adapts a Component that creates the product
22  * to a Component that creates the product factory.
23  * <p>
24  * Zephyr Business Solution
25  *
26  * @author Ben Yu
27  *
28  */

29 final class TheFactoryComponent<T> extends Component<Factory<T>> {
30   private final Creator<T> cc;
31   private final String JavaDoc text;
32   private interface SerializableFactory<T> extends Factory<T>, java.io.Serializable JavaDoc{}
33   TheFactoryComponent(final Creator<T> cc, String JavaDoc text) {
34     this.cc = cc;
35     this.text = text;
36   }
37   
38   public Class JavaDoc<Factory<T>> getType() {
39     return (Class JavaDoc)Factory.class;
40   }
41   public boolean isConcrete(){
42     return true;
43   }
44   public Factory<T> create(final Dependency dep){
45     return new SerializableFactory<T>(){
46       public T create(){
47         return cc.create(dep);
48       }
49       public String JavaDoc toString(){
50         return text;
51       }
52     };
53   }
54   public Class JavaDoc verify(final Dependency dep){
55     cc.verify(dep);
56     return getType();
57   }
58   public boolean equals(Object JavaDoc obj) {
59     if(obj instanceof TheFactoryComponent){
60       final TheFactoryComponent other = (TheFactoryComponent)obj;
61       return cc.equals(other.cc);
62     }
63     else return false;
64   }
65   public int hashCode() {
66     return cc.hashCode();
67   }
68   public String JavaDoc toString() {
69     //return "<"+cc + "> : " + factory_class.getName();
70
return text;
71   }
72   public boolean isSingleton(){
73     return false;
74   }
75 }
76
Popular Tags