1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.*; 25 26 import org.jboss.beans.info.spi.BeanInfo; 27 import org.jboss.beans.metadata.spi.*; 28 import org.jboss.kernel.plugins.config.Configurator; 29 import org.jboss.kernel.spi.config.KernelConfigurator; 30 import org.jboss.kernel.spi.dependency.KernelControllerContext; 31 import org.jboss.reflect.spi.ClassInfo; 32 import org.jboss.reflect.spi.ConstructorInfo; 33 import org.jboss.reflect.spi.MethodInfo; 34 import org.jboss.util.JBossObject; 35 import org.jboss.util.JBossStringBuilder; 36 37 43 public class AbstractConstructorMetaData extends AbstractFeatureMetaData implements ConstructorMetaData 44 { 45 48 protected List<ParameterMetaData> parameters; 49 50 53 protected ValueMetaData value; 54 55 58 protected ValueMetaData factory; 59 60 63 protected String factoryClassName; 64 65 68 protected String factoryMethod; 69 70 73 public AbstractConstructorMetaData() 74 { 75 } 76 77 82 public void setParameters(List<ParameterMetaData> parameters) 83 { 84 this.parameters = parameters; 85 flushJBossObjectCache(); 86 } 87 88 93 public void setValue(ValueMetaData value) 94 { 95 this.value = value; 96 flushJBossObjectCache(); 97 } 98 99 104 public void setFactory(ValueMetaData factory) 105 { 106 this.factory = factory; 107 flushJBossObjectCache(); 108 } 109 110 115 public void setFactoryClass(String name) 116 { 117 this.factoryClassName = name; 118 flushJBossObjectCache(); 119 } 120 121 126 public void setFactoryMethod(String name) 127 { 128 this.factoryMethod = name; 129 flushJBossObjectCache(); 130 } 131 132 public List<ParameterMetaData> getParameters() 133 { 134 return parameters; 135 } 136 137 public ValueMetaData getValue() 138 { 139 return value; 140 } 141 142 public ValueMetaData getFactory() 143 { 144 return factory; 145 } 146 147 public String getFactoryClass() 148 { 149 return factoryClassName; 150 } 151 152 public String getFactoryMethod() 153 { 154 return factoryMethod; 155 } 156 157 protected void addChildren(Set<MetaDataVisitorNode> children) 158 { 159 super.addChildren(children); 160 if (parameters != null) 161 children.addAll(parameters); 162 if (value != null) 163 children.add(value); 164 if (factory != null) 165 children.add(factory); 166 } 167 168 public Class getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable 169 { 170 if (factory != null || factoryClassName != null) 171 { 172 KernelControllerContext context = visitor.getControllerContext(); 173 ClassLoader cl = Configurator.getClassLoader(context.getBeanMetaData()); 174 KernelConfigurator configurator = context.getKernel().getConfigurator(); 175 ClassInfo classInfo; 176 if (factory != null) 177 { 178 Object target = factory.getValue(null, cl); 179 classInfo = configurator.getClassInfo(target.getClass()); 180 } 181 else 182 { 183 classInfo = configurator.getClassInfo(factoryClassName, cl); 184 } 185 ParameterMetaData parameter = (ParameterMetaData) previous; 187 String [] parameterTypes = Configurator.getParameterTypes(false, parameters); 188 MethodInfo methodInfo = Configurator.findMethodInfo(classInfo, factoryMethod, parameterTypes, factoryClassName != null, true); 189 return applyCollectionOrMapCheck(methodInfo.getParameterTypes()[parameter.getIndex()].getType()); 190 } 191 else 192 { 193 KernelControllerContext context = visitor.getControllerContext(); 194 BeanInfo beanInfo = context.getBeanInfo(); 195 if (previous instanceof ParameterMetaData) 197 { 198 ParameterMetaData parameter = (ParameterMetaData) previous; 199 String [] paramTypes = Configurator.getParameterTypes(false, parameters); 200 ConstructorInfo ci = Configurator.findConstructorInfo(beanInfo.getClassInfo(), paramTypes); 201 return applyCollectionOrMapCheck(ci.getParameterTypes()[parameter.getIndex()].getType()); 202 } 203 else 204 { 205 Class type = beanInfo.getClassInfo().getType(); 208 log.warn("Constructing bean from injection value: results in multiple beans with same class type - " + type); 209 return type; 210 230 } 231 } 232 } 233 234 public void toString(JBossStringBuilder buffer) 235 { 236 buffer.append("parameters="); 237 JBossObject.list(buffer, parameters); 238 if (value != null) 239 buffer.append(" value=").append(value); 240 if (factory != null) 241 buffer.append(" factory=").append(factory); 242 if (factoryClassName != null) 243 buffer.append(" factoryClass=").append(factoryClassName); 244 if (factoryMethod != null) 245 buffer.append(" factoryMethod=").append(factoryMethod); 246 super.toString(buffer); 247 } 248 } 249 | Popular Tags |