1 54 55 package org.jboss.axis.encoding.ser; 56 57 import org.jboss.axis.utils.JavaUtils; 58 import org.jboss.logging.Logger; 59 60 import java.lang.reflect.Constructor ; 61 import java.util.ArrayList ; 62 import java.util.List ; 63 64 71 public class DeferredBeanConstruction 72 { 73 private static Logger log = Logger.getLogger(DeferredBeanConstruction.class.getName()); 74 75 private Constructor ctor; 76 77 private Class [] ctorParamTypes; 78 79 private List ctorParams = new ArrayList (); 80 81 public DeferredBeanConstruction(Constructor ctor) 82 { 83 this.ctor = ctor; 84 this.ctorParamTypes = ctor.getParameterTypes(); 85 } 86 87 public Constructor getConstructor() 88 { 89 return ctor; 90 } 91 92 public Object newBeanInstance(Object ctorArg) 93 { 94 try 95 { 96 log.debug("Add constructor argument: " + ctorArg); 97 98 int index = ctorParams.size(); 99 Class paramType = ctorParamTypes[index]; 100 if (JavaUtils.isConvertable(ctorArg, paramType) == false) 101 { 102 log.debug("Ignoring parameter [" + ctorArg + "], given value is not convertable to " + paramType.getName()); 103 ctorArg = null; 104 } 105 else 106 { 107 ctorArg = JavaUtils.convert(ctorArg, paramType); 108 } 109 110 ctorParams.add(ctorArg); 111 112 if (ctorParamTypes.length == ctorParams.size()) 113 { 114 log.debug("Attempt to make bean with: " + toString()); 115 Object bean = ctor.newInstance(ctorParams.toArray()); 116 return bean; 117 } 118 else 119 { 120 log.debug("Waiting for more constructor arguments"); 121 return null; 122 } 123 } 124 catch (Exception e) 125 { 126 throw new IllegalStateException ("Cannot construct target object with: " + ctorParams); 127 } 128 } 129 130 public String toString() 131 { 132 return "[ctor=" + ctor + ",args=" + ctorParams + "]"; 133 } 134 } | Popular Tags |