use of org.springframework.beans.factory.config.ConstructorArgumentValues in project hudson-2.x by hudson.
the class DefaultBeanConfiguration method createBeanDefinition.
protected AbstractBeanDefinition createBeanDefinition() {
AbstractBeanDefinition bd;
if (constructorArgs.size() > 0) {
ConstructorArgumentValues cav = new ConstructorArgumentValues();
for (Object constructorArg : constructorArgs) {
cav.addGenericArgumentValue(constructorArg);
}
if (StringUtils.isBlank(parentName)) {
bd = new RootBeanDefinition(clazz, cav, null);
} else {
bd = new ChildBeanDefinition(parentName, clazz, cav, null);
}
bd.setSingleton(singleton);
} else {
if (StringUtils.isBlank(parentName)) {
bd = new RootBeanDefinition(clazz, singleton);
} else {
bd = new ChildBeanDefinition(parentName, clazz, null, null);
bd.setSingleton(singleton);
}
}
wrapper = new BeanWrapperImpl(bd);
return bd;
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues in project redisson by redisson.
the class RedissonMultiLockDefinitionParser method parseNested.
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
bd.setDependsOn(element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
List<Element> childElements = DomUtils.getChildElements(element);
for (Element elt : childElements) {
String localName = elt.getLocalName();
if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(localName)) {
//parsed elsewhere
continue;
}
String id;
if (BeanDefinitionParserDelegate.REF_ELEMENT.equals(localName)) {
id = elt.getAttribute(BeanDefinitionParserDelegate.BEAN_REF_ATTRIBUTE);
} else {
if (!elt.hasAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE)) {
helper.setAttribute(elt, RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE, element.getAttribute(RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
}
helper.populateIdAttribute(elt, builder, parserContext);
parserContext.getDelegate().parseCustomElement(elt, bd);
id = elt.getAttribute(RedissonNamespaceParserSupport.ID_ATTRIBUTE);
}
ConstructorArgumentValues args = builder.getRawBeanDefinition().getConstructorArgumentValues();
if (args.getArgumentCount() > 0) {
ConstructorArgumentValues.ValueHolder value = args.getIndexedArgumentValues().get(0);
ManagedList list;
if (value.getValue() instanceof ManagedList) {
list = (ManagedList) value.getValue();
} else {
list = new ManagedList();
list.add(value.getValue());
value.setValue(list);
value.setType(ManagedList.class.getName());
}
list.add(new RuntimeBeanReference(id));
} else {
builder.addConstructorArgReference(id);
}
}
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues in project redisson by redisson.
the class RedissonNamespaceParserSupport method addConstructorArgs.
public void addConstructorArgs(Object value, Class type, BeanDefinition bd) {
ConstructorArgumentValues.ValueHolder vHolder = new ConstructorArgumentValues.ValueHolder(value, type.getName());
ConstructorArgumentValues args = bd.getConstructorArgumentValues();
args.addIndexedArgumentValue(args.getArgumentCount(), vHolder);
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-framework by spring-projects.
the class ConfigBeanDefinitionParser method createAdviceDefinition.
/**
* Creates the RootBeanDefinition for a POJO advice bean. Also causes pointcut
* parsing to occur so that the pointcut may be associate with the advice bean.
* This same pointcut is also configured as the pointcut for the enclosing
* Advisor definition using the supplied MutablePropertyValues.
*/
private AbstractBeanDefinition createAdviceDefinition(Element adviceElement, ParserContext parserContext, String aspectName, int order, RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) {
RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext));
adviceDefinition.setSource(parserContext.extractSource(adviceElement));
adviceDefinition.getPropertyValues().add(ASPECT_NAME_PROPERTY, aspectName);
adviceDefinition.getPropertyValues().add(DECLARATION_ORDER_PROPERTY, order);
if (adviceElement.hasAttribute(RETURNING)) {
adviceDefinition.getPropertyValues().add(RETURNING_PROPERTY, adviceElement.getAttribute(RETURNING));
}
if (adviceElement.hasAttribute(THROWING)) {
adviceDefinition.getPropertyValues().add(THROWING_PROPERTY, adviceElement.getAttribute(THROWING));
}
if (adviceElement.hasAttribute(ARG_NAMES)) {
adviceDefinition.getPropertyValues().add(ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES));
}
ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues();
cav.addIndexedArgumentValue(METHOD_INDEX, methodDef);
Object pointcut = parsePointcutProperty(adviceElement, parserContext);
if (pointcut instanceof BeanDefinition) {
cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut);
beanDefinitions.add((BeanDefinition) pointcut);
} else if (pointcut instanceof String) {
RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut);
cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef);
beanReferences.add(pointcutRef);
}
cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef);
return adviceDefinition;
}
use of org.springframework.beans.factory.config.ConstructorArgumentValues in project spring-framework by spring-projects.
the class PropertiesBeanDefinitionReader method registerBeanDefinition.
/**
* Get all property values, given a prefix (which will be stripped)
* and add the bean they define to the factory with the given name
* @param beanName name of the bean to define
* @param map Map containing string pairs
* @param prefix prefix of each entry, which will be stripped
* @param resourceDescription description of the resource that the
* Map came from (for logging purposes)
* @throws BeansException if the bean definition could not be parsed or registered
*/
protected void registerBeanDefinition(String beanName, Map<?, ?> map, String prefix, String resourceDescription) throws BeansException {
String className = null;
String parent = null;
String scope = GenericBeanDefinition.SCOPE_SINGLETON;
boolean isAbstract = false;
boolean lazyInit = false;
ConstructorArgumentValues cas = new ConstructorArgumentValues();
MutablePropertyValues pvs = new MutablePropertyValues();
for (Map.Entry<?, ?> entry : map.entrySet()) {
String key = StringUtils.trimWhitespace((String) entry.getKey());
if (key.startsWith(prefix + SEPARATOR)) {
String property = key.substring(prefix.length() + SEPARATOR.length());
if (CLASS_KEY.equals(property)) {
className = StringUtils.trimWhitespace((String) entry.getValue());
} else if (PARENT_KEY.equals(property)) {
parent = StringUtils.trimWhitespace((String) entry.getValue());
} else if (ABSTRACT_KEY.equals(property)) {
String val = StringUtils.trimWhitespace((String) entry.getValue());
isAbstract = TRUE_VALUE.equals(val);
} else if (SCOPE_KEY.equals(property)) {
// Spring 2.0 style
scope = StringUtils.trimWhitespace((String) entry.getValue());
} else if (SINGLETON_KEY.equals(property)) {
// Spring 1.2 style
String val = StringUtils.trimWhitespace((String) entry.getValue());
scope = ((val == null || TRUE_VALUE.equals(val) ? GenericBeanDefinition.SCOPE_SINGLETON : GenericBeanDefinition.SCOPE_PROTOTYPE));
} else if (LAZY_INIT_KEY.equals(property)) {
String val = StringUtils.trimWhitespace((String) entry.getValue());
lazyInit = TRUE_VALUE.equals(val);
} else if (property.startsWith(CONSTRUCTOR_ARG_PREFIX)) {
if (property.endsWith(REF_SUFFIX)) {
int index = Integer.parseInt(property.substring(1, property.length() - REF_SUFFIX.length()));
cas.addIndexedArgumentValue(index, new RuntimeBeanReference(entry.getValue().toString()));
} else {
int index = Integer.parseInt(property.substring(1));
cas.addIndexedArgumentValue(index, readValue(entry));
}
} else if (property.endsWith(REF_SUFFIX)) {
// This isn't a real property, but a reference to another prototype
// Extract property name: property is of form dog(ref)
property = property.substring(0, property.length() - REF_SUFFIX.length());
String ref = StringUtils.trimWhitespace((String) entry.getValue());
// It doesn't matter if the referenced bean hasn't yet been registered:
// this will ensure that the reference is resolved at runtime.
Object val = new RuntimeBeanReference(ref);
pvs.add(property, val);
} else {
// It's a normal bean property.
pvs.add(property, readValue(entry));
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Registering bean definition for bean name '" + beanName + "' with " + pvs);
}
// backwards compatibility reasons.
if (parent == null && className == null && !beanName.equals(this.defaultParentBean)) {
parent = this.defaultParentBean;
}
try {
AbstractBeanDefinition bd = BeanDefinitionReaderUtils.createBeanDefinition(parent, className, getBeanClassLoader());
bd.setScope(scope);
bd.setAbstract(isAbstract);
bd.setLazyInit(lazyInit);
bd.setConstructorArgumentValues(cas);
bd.setPropertyValues(pvs);
getRegistry().registerBeanDefinition(beanName, bd);
} catch (ClassNotFoundException ex) {
throw new CannotLoadBeanClassException(resourceDescription, beanName, className, ex);
} catch (LinkageError err) {
throw new CannotLoadBeanClassException(resourceDescription, beanName, className, err);
}
}
Aggregations