List of usage examples for org.springframework.beans.factory.config ConstructorArgumentValues addGenericArgumentValue
public void addGenericArgumentValue(Object value, String type)
From source file:com.griddynamics.banshun.config.xml.ExportBeanDefinitionParser.java
/** * Creates arguments definition for the {@link Registry#export(ExportRef) export()} method * of the registry bean.// w w w . j a v a 2 s . co m * * @param exportRef The definition of the {@link ExportRef} bean. */ private ConstructorArgumentValues defineExportMethodArgs(BeanDefinition exportRef) { ConstructorArgumentValues holder = new ConstructorArgumentValues(); holder.addGenericArgumentValue(exportRef, ExportRef.class.getName()); return holder; }
From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java
/** * Register jms listener definition//from w ww . java2 s. c om */ private void registerJmsDefinition(Element element, ParserContext parserContext) { GenericBeanDefinition definition = new GenericBeanDefinition(); MutablePropertyValues propertyValues = definition.getPropertyValues(); definition = new GenericBeanDefinition(); definition.setBeanClass(CacheKeyTypeVersionUpdateListener.class); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("cacheItemConfigManager", new RuntimeBeanReference(cacheItemConfigManager)); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(definition, "keyTypeVersionUpdateListener"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(SingleCacheRemoveListener.class); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("cacheClientFactory", new RuntimeBeanReference(DEFAULT_CACHE_CLIENT_FACTORY_ID)); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(definition, "singleCacheRemoveListener"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(CacheConfigurationUpdateListener.class); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("cacheClientFactory", new RuntimeBeanReference(DEFAULT_CACHE_CLIENT_FACTORY_ID)); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(definition, "cacheConfigUpdateListener"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(CacheKeyConfigUpdateListener.class); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("cacheItemConfigManager", new RuntimeBeanReference(cacheItemConfigManager)); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(definition, "cacheKeyConfigUpdateListener"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(MessageReceiver.class); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("mappingList[0]", new RuntimeBeanReference("keyTypeVersionUpdateListener")); propertyValues.addPropertyValue("mappingList[1]", new RuntimeBeanReference("singleCacheRemoveListener")); propertyValues.addPropertyValue("mappingList[2]", new RuntimeBeanReference("cacheConfigUpdateListener")); propertyValues.addPropertyValue("mappingList[3]", new RuntimeBeanReference("cacheKeyConfigUpdateListener")); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(definition, "dispatchMessageListener"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(MongoMQService.class); ConstructorArgumentValues constructorArgumentValues = definition.getConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue("${avatar-cache.swallow.url}", "java.lang.String"); BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(definition, "MQService"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); definition.setBeanClass(Destination.class); definition.setFactoryMethodName(DEFAULT_CACHE_JMS_MODE); constructorArgumentValues = definition.getConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(DEFAULT_CACHE_JMS_TOPIC_NAME, "java.lang.String"); BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(definition, "CacheDestination"), parserContext.getRegistry()); definition = new GenericBeanDefinition(); // definition.setBeanClass(MongoMessageConsumer.class); definition.setFactoryBeanName("MQService"); definition.setFactoryMethodName("createConsumer"); constructorArgumentValues = definition.getConstructorArgumentValues(); //TODO where to get the DEFAULT_CACHE_JMS_TOPIC_NAME constructorArgumentValues.addGenericArgumentValue(new RuntimeBeanReference("CacheDestination")); propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("messageListener", new RuntimeBeanReference("dispatchMessageListener")); BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(definition, "cacheConsumer"), parserContext.getRegistry()); }
From source file:org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.java
/** * Parse a constructor-arg element.// w ww . ja va 2s. c om */ protected void parseConstructorArgElement(Element ele, String beanName, ConstructorArgumentValues cargs) throws BeanDefinitionStoreException { Object val = parsePropertyValue(ele, beanName, null); String indexAttr = ele.getAttribute(INDEX_ATTRIBUTE); String typeAttr = ele.getAttribute(TYPE_ATTRIBUTE); if (StringUtils.hasLength(indexAttr)) { try { int index = Integer.parseInt(indexAttr); if (index < 0) { throw new BeanDefinitionStoreException(getResource(), beanName, "'index' cannot be lower than 0"); } if (StringUtils.hasLength(typeAttr)) { cargs.addIndexedArgumentValue(index, val, typeAttr); } else { cargs.addIndexedArgumentValue(index, val); } } catch (NumberFormatException ex) { throw new BeanDefinitionStoreException(getResource(), beanName, "Attribute 'index' of tag 'constructor-arg' must be an integer"); } } else { if (StringUtils.hasLength(typeAttr)) { cargs.addGenericArgumentValue(val, typeAttr); } else { cargs.addGenericArgumentValue(val); } } }