KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > UseArgumentComponent


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

15 package jfun.yan;
16
17 import jfun.yan.function.Signature;
18
19 /**
20  * Zephyr Business Solution
21  *
22  * @author Ben Yu
23  *
24  */

25 final class UseArgumentComponent<T> extends Component<T> {
26   private final Signature sig;
27   private final int key;
28   private final Class JavaDoc<T> type;
29   public boolean isConcrete(){
30     return false;
31   }
32   UseArgumentComponent(final Signature sig, final int key, final Class JavaDoc<T> type) {
33     this.sig = sig;
34     this.key = key;
35     this.type = type;
36   }
37   public Class JavaDoc<T> getType() {
38     return type;
39   }
40   public T create(Dependency pp){
41     return (T)findDependency(pp).getArgument(sig, key, type);
42   }
43   public Class JavaDoc verify(Dependency pp){
44     return findDependency(pp).verifyArgument(sig, key, type);
45   }
46   
47   public boolean equals(Object JavaDoc obj) {
48     if(obj instanceof UseArgumentComponent){
49       final UseArgumentComponent other = (UseArgumentComponent)obj;
50       return sig.equals(other.sig) && key == other.key && type.equals(other.type);
51     }
52     else return false;
53   }
54   public int hashCode() {
55     return (key*31 + type.hashCode())*31+sig.hashCode();
56   }
57   public String JavaDoc toString() {
58     return "useArgument(" + sig.getName()+","+key + ","+jfun.util.Misc.getTypeName(type)+")";
59   }
60   private Dependency findDependency(Dependency dep){
61     final Dependency parent = dep.getParent();
62     if(parent == null)
63       throw new YanException("useArgument can only be used for parameter or property");
64     return parent;
65   }
66   public boolean isSingleton(){
67     return false;
68   }
69 }
70
Popular Tags