1 package jfun.yan.xml.nuts; 2 3 import java.lang.reflect.Constructor ; 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 17 public class ConstructorNut extends ArgumentsAndPropertiesNut 18 implements LifecycleDeclaration{ 19 20 private Class type; 21 private boolean private_access = false; 22 public void setClass(Class type){ 23 this.type = type; 24 } 25 28 public Class 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 42 protected Component evaluateNoLifecycle(){ 43 checkMandatory("class", type); 44 final Constructor ctor = lookupConstructor(); 45 Component result = Components.fun(Functions.ctor(ctor)); 46 return decorateComponent(result); 47 } 48 private Constructor lookupConstructor(){ 49 final Class [] param_types = getParameterTypes(); 50 if(param_types==null){ 51 final int argcount = getMaxArgsCount(); 52 if(argcount<0){ 53 if(this.getParameterAutowireMode()==null){ 55 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 initializer; 74 private String starter; 75 private String stopper; 76 private String disposer; 77 public String getInitializer() { 78 return initializer; 79 } 80 81 public void setInitializer(String initializer) { 82 this.initializer = initializer; 83 } 84 85 public String getStarter() { 86 return starter; 87 } 88 89 public void setStarter(String starter) { 90 this.starter = starter; 91 } 92 93 public String getStopper() { 94 return stopper; 95 } 96 public void setStopper(String stopper) { 97 this.stopper = stopper; 98 } 99 100 public String getDisposer() { 101 return disposer; 102 } 103 104 public void setDisposer(String disposer) { 105 this.disposer = disposer; 106 } 107 108 } 109 | Popular Tags |