KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > ConstructorNut


1 package jfun.yan.xml.nuts;
2
3 import java.lang.reflect.Constructor JavaDoc;
4
5 import jfun.yan.Component;
6 import jfun.yan.Components;
7 import jfun.yan.Functions;
8 import jfun.yan.util.ReflectionUtil;
9
10
11 /**
12  * Nut class for <ctor> tag.
13  * <p>
14  * @author Ben Yu
15  * Nov 9, 2005 11:41:35 PM
16  */

17 public class ConstructorNut extends ArgumentsAndPropertiesNut
18 implements LifecycleDeclaration{
19   
20   private Class JavaDoc type;
21   private boolean private_access = false;
22   public void setClass(Class JavaDoc type){
23     this.type = type;
24   }
25   /**
26    * Get the class that declares the constructor.
27    */

28   public Class JavaDoc getDeclaringClass(){
29     return type;
30   }
31   public boolean isPrivate_access() {
32     return private_access;
33   }
34
35   public void setPrivate_access(boolean private_access) {
36     this.private_access = private_access;
37   }
38   /**
39    * Evaluate the Component without applying life cycle.
40    * Subclass can call this method and apply customized lifecycle.
41    */

42   protected Component evaluateNoLifecycle(){
43     checkMandatory("class", type);
44     final Constructor JavaDoc ctor = lookupConstructor();
45     Component result = Components.fun(Functions.ctor(ctor));
46     return decorateComponent(result);
47   }
48   private Constructor JavaDoc lookupConstructor(){
49     final Class JavaDoc[] param_types = getParameterTypes();
50     if(param_types==null){
51       final int argcount = getMaxArgsCount();
52       if(argcount<0){
53         //no arg is specified, find any.
54
if(this.getParameterAutowireMode()==null){
55           //manual
56
return ReflectionUtil.getConstructor(type, null, private_access);
57         }
58         else return ReflectionUtil.getConstructor(type,
59             private_access);
60       }
61       else{
62         return ReflectionUtil.getConstructor(type, argcount,
63             private_access);
64       }
65     }
66     else{
67       return ReflectionUtil.getConstructor(type, param_types, private_access);
68     }
69   }
70   public Component eval(){
71     return Util.wrapLifecycle(evaluateNoLifecycle(), this);
72   }
73   private String JavaDoc initializer;
74   private String JavaDoc starter;
75   private String JavaDoc stopper;
76   private String JavaDoc disposer;
77   public String JavaDoc getInitializer() {
78     return initializer;
79   }
80
81   public void setInitializer(String JavaDoc initializer) {
82     this.initializer = initializer;
83   }
84
85   public String JavaDoc getStarter() {
86     return starter;
87   }
88
89   public void setStarter(String JavaDoc starter) {
90     this.starter = starter;
91   }
92
93   public String JavaDoc getStopper() {
94     return stopper;
95   }
96   public void setStopper(String JavaDoc stopper) {
97     this.stopper = stopper;
98   }
99
100   public String JavaDoc getDisposer() {
101     return disposer;
102   }
103
104   public void setDisposer(String JavaDoc disposer) {
105     this.disposer = disposer;
106   }
107
108 }
109
Popular Tags