KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > UsePropertyComponent


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 /**
18  * Zephyr Business Solution
19  *
20  * @author Ben Yu
21  *
22  */

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