@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNames = beanFactory.getBeanDefinitionNames(); for (String curName : beanNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(curName); PropertyValue[] values = beanDefinition.getPropertyValues().getPropertyValues(); for (PropertyValue propertyValue : values) { Object value = propertyValue.getValue(); if(value instanceof RuntimeBeanReference) { RuntimeBeanReference ref = (RuntimeBeanReference) value; if(!beanFactory.containsBean(ref.getBeanName())) { AbstractBeanDefinition newBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(ref.getBeanName()).getBeanDefinition(); newBeanDefinition.setScope("step"); ((DefaultListableBeanFactory) beanFactory).registerBeanDefinition(ref.getBeanName(), newBeanDefinition); } } } } }
public void visitBeanDefinition(BeanDefinition beanDefinition) { String beanClassName = beanDefinition.getBeanClassName(); if(StepFactoryBean.class.getName().equals(beanClassName)) { PropertyValue [] values = beanDefinition.getPropertyValues().getPropertyValues(); for (PropertyValue propertyValue : values) { if(propertyValue.getName().equalsIgnoreCase("partitionReducer")) { RuntimeBeanReference ref = (RuntimeBeanReference) propertyValue.getValue(); beanFactory.getBeanDefinition(ref.getBeanName()).setLazyInit(true); } } } if(JsrPartitionHandler.class.getName().equals(beanClassName)) { PropertyValue [] values = beanDefinition.getPropertyValues().getPropertyValues(); for (PropertyValue propertyValue : values) { String propertyName = propertyValue.getName(); if(propertyName.equalsIgnoreCase("partitionMapper") || propertyName.equalsIgnoreCase("partitionAnalyzer")) { RuntimeBeanReference ref = (RuntimeBeanReference) propertyValue.getValue(); beanFactory.getBeanDefinition(ref.getBeanName()).setLazyInit(true); } } } } }
/** * Apply the given property value to the corresponding bean. */ protected void applyPropertyValue( ConfigurableListableBeanFactory factory, String beanName, String property, String value) { BeanDefinition bd = factory.getBeanDefinition(beanName); BeanDefinition bdToUse = bd; while (bd != null) { bdToUse = bd; bd = bd.getOriginatingBeanDefinition(); } PropertyValue pv = new PropertyValue(property, value); pv.setOptional(this.ignoreInvalidKeys); bdToUse.getPropertyValues().addPropertyValue(pv); }
/** * Copy constructor. * @param original the PropertyValue to copy (never {@code null}) */ public PropertyValue(PropertyValue original) { Assert.notNull(original, "Original must not be null"); this.name = original.getName(); this.value = original.getValue(); this.optional = original.isOptional(); this.converted = original.converted; this.convertedValue = original.convertedValue; this.conversionNecessary = original.conversionNecessary; this.resolvedTokens = original.resolvedTokens; setSource(original.getSource()); copyAttributesFrom(original); }
/** * Constructor that exposes a new value for an original value holder. * The original holder will be exposed as source of the new holder. * @param original the PropertyValue to link to (never {@code null}) * @param newValue the new value to apply */ public PropertyValue(PropertyValue original, @Nullable Object newValue) { Assert.notNull(original, "Original must not be null"); this.name = original.getName(); this.value = newValue; this.optional = original.isOptional(); this.conversionNecessary = original.conversionNecessary; this.resolvedTokens = original.resolvedTokens; setSource(original); copyAttributesFrom(original); }
componentNamePatternsSet.add(componentNamePatterns); AbstractBeanDefinition messageHistoryConfigurer = BeanDefinitionBuilder.genericBeanDefinition(MessageHistoryConfigurer.class) .addPropertyValue("componentNamePatternsSet", componentNamePatternsSet) .getBeanDefinition(); BeanDefinition beanDefinition = registry.getBeanDefinition(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME); PropertyValue propertyValue = beanDefinition .getPropertyValues().getPropertyValue("componentNamePatternsSet"); if (propertyValue != null) { @SuppressWarnings("unchecked") Set<Object> currentComponentNamePatternsSet = (Set<Object>) propertyValue.getValue(); Set<Object> componentNamePatternsSet = new ManagedSet<Object>(); componentNamePatternsSet.add(componentNamePatterns); beanDefinition.getPropertyValues().addPropertyValue("componentNamePatternsSet", componentNamePatternsSet);
private void copyProps(BeanDefinitionBuilder src, BeanDefinition def) { for (PropertyValue v : src.getBeanDefinition().getPropertyValues().getPropertyValues()) { if (!"bus".equals(v.getName())) { def.getPropertyValues().addPropertyValue(v.getName(), v.getValue()); } src.getBeanDefinition().getPropertyValues().removePropertyValue(v); } }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[i]); String beanClassName = beanDef.getBeanClassName(); if (FEIGN_FACTORY_CLASS.equals(beanClassName) == false) { continue; } MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); String client = String.valueOf(pv.getValue() == null ? "" : pv.getValue()); if (StringUtils.isNotBlank(client)) { this.transientClientSet.add(client); } } this.fireAfterPropertiesSet(); }
private String getConversionService(BeanDefinitionBuilder definitionBuilder) { RuntimeBeanReference conversionServiceReference = (RuntimeBeanReference) definitionBuilder.getBeanDefinition() .getPropertyValues().getPropertyValue(CONVERSION_SERVICE_PROPERTY).getValue(); return conversionServiceReference.getBeanName(); }
public Collection<BeanDefinition> parse(Element element, ParserContext parserContext) { String idAttribute = element.getAttribute("id"); BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder .genericBeanDefinition("org.springframework.batch.core.jsr.job.flow.support.state.JsrSplitState"); List<Element> flowElements = DomUtils.getChildElementsByTagName(element, "flow"); if (flowElements.size() < 2) { parserContext.getReaderContext().error("A <split/> must contain at least two 'flow' elements.", element); } Collection<Object> flows = new ManagedList<>(); int i = 0; for (Element nextElement : flowElements) { FlowParser flowParser = new FlowParser(idAttribute + "." + i, jobFactoryRef); flows.add(flowParser.parse(nextElement, parserContext)); i++; } stateBuilder.addConstructorArgValue(flows); stateBuilder.addConstructorArgValue(idAttribute); PropertyValue propertyValue = getSplitTaskExecutorPropertyValue(parserContext.getRegistry()); stateBuilder.addPropertyValue(propertyValue.getName(), propertyValue.getValue()); return FlowParser.getNextElements(parserContext, null, stateBuilder.getBeanDefinition(), element); }
@Override protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) { BeanDefinition beanDefinition = factory.getBeanDefinition(beanName); if (beanDefinition == null) { _log.warn("could not find bean definition for bean named " + beanName); return; } RuntimeBeanReference ref = new RuntimeBeanReference(value); MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue pv = pvs.getPropertyValue(property); if (pv == null) { pvs.addPropertyValue(property, ref); } else { pv.setConvertedValue(ref); } } }
@Override public BeanDefinition buildFSMHarnessBean( Class<?> statefulClass, String fsmBeanId, String factoryId, String finderId, BeanDefinition repoBeanDefinitionFactory) { String tmId = (String)repoBeanDefinitionFactory.getPropertyValues().getPropertyValue("transactionManager").getValue(); BeanDefinition fsmHarness = BeanDefinitionBuilder .genericBeanDefinition(JPAFSMHarnessImpl.class) .getBeanDefinition(); ConstructorArgumentValues args = fsmHarness.getConstructorArgumentValues(); args.addIndexedArgumentValue(0, new RuntimeBeanReference(fsmBeanId)); args.addIndexedArgumentValue(1, statefulClass); args.addIndexedArgumentValue(2, new RuntimeBeanReference(factoryId)); args.addIndexedArgumentValue(3, new RuntimeBeanReference(finderId)); args.addIndexedArgumentValue(4, new RuntimeBeanReference(tmId)); return fsmHarness; } }
static void setPropertyValue(BeanDefinitionBuilder builder, BeanDefinition source, String propertyName, boolean withDependsOn) { PropertyValue propertyValue = source.getPropertyValues().getPropertyValue(propertyName); if (propertyValue != null) { builder.addPropertyValue(propertyValue.getName(), propertyValue.getValue()); if (withDependsOn && propertyValue.getValue() instanceof RuntimeBeanReference) { builder.addDependsOn(((RuntimeBeanReference) propertyValue.getValue()).getBeanName()); } } }
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext ctx) { if (!ctx.getRegistry().containsBeanDefinition(PluginRegistry.PLUGIN_REGISTRY_BEAN_NAME)) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(PluginRegistryImpl.class); ctx.getRegistry().registerBeanDefinition(PluginRegistry.PLUGIN_REGISTRY_BEAN_NAME, builder.getBeanDefinition()); logger.debug("No BeanDefinition for PluginRegistry found, create and register one"); PluginExtension ext = exts.get(0); BeanDefinition registryBean = ctx.getRegistry().getBeanDefinition(PluginRegistry.PLUGIN_REGISTRY_BEAN_NAME); MutablePropertyValues props = registryBean.getPropertyValues(); PropertyValue prop = props.getPropertyValue(PluginRegistry.PLUGIN_REGISTRYIMPL_PLUGINS_FIELD_NAME); if (prop == null) { Map<String, List<PluginExtension>> extensions = new HashMap<String, List<PluginExtension>>(1); extensions.put(ext.getBeanClassName(), exts); prop = new PropertyValue(PluginRegistry.PLUGIN_REGISTRYIMPL_PLUGINS_FIELD_NAME, extensions); if (logger.isTraceEnabled()) { logger.trace("No 'extensions' property found in PluginRegistry bean definition, create a new one"); props.addPropertyValue(prop); } else { Map<String, List<PluginExtension>> extensions = (Map<String, List<PluginExtension>>) prop.getValue(); List<PluginExtension> oexts = extensions.get(ext.getBeanClassName()); if (oexts == null) {
/** * Copy the properties from the bean we have been building into the target (typically * the parent bean). In other words, the bean is a facade for the target. * * <p>This assumes that the source bean has been constructed correctly (ie the decisions about * what is ignored, a map, a list, etc) have already been made. All it does (apart from a * direct copy) is merge collections with those on the target when necessary. */ public void copyBeanToTarget() { logger.debug("copy " + bean.getBeanDefinition().getBeanClassName() + " -> " + target.getBeanClassName()); assertTargetPresent(); MutablePropertyValues targetProperties = target.getPropertyValues(); MutablePropertyValues beanProperties = bean.getBeanDefinition().getPropertyValues(); for (int i=0;i < beanProperties.size(); i++) { PropertyValue propertyValue = beanProperties.getPropertyValues()[i]; addPropertyWithoutReference(targetProperties, new SinglePropertyLiteral(), propertyValue.getName(), propertyValue.getValue()); } }
parserContext); MutablePropertyValues properties = builder.getRawBeanDefinition() .getPropertyValues(); PropertyValue propertyValue = properties.getPropertyValue("arguments"); ManagedList<Object> args = new ManagedList(); args.addAll(Arrays.asList( (Object[]) propertyValue.getValue())); args.add(new RuntimeBeanReference(optionBeanId)); properties.removePropertyValue("arguments"); properties.addPropertyValue("arguments", args);
beanDefinition.getPropertyValues().addPropertyValue("id", id); PropertyValue property = definition.getPropertyValues().getPropertyValue("protocol"); if (property != null) { Object value = property.getValue(); if (value instanceof ProtocolConfig && id.equals(((ProtocolConfig) value).getName())) { definition.getPropertyValues().addPropertyValue("protocol", new RuntimeBeanReference(id)); String returnRef = value.substring(0, index); String returnMethod = value.substring(index + 1); reference = new RuntimeBeanReference(returnRef); beanDefinition.getPropertyValues().addPropertyValue("onreturnMethod", returnMethod); } else if ("onthrow".equals(property)) { String throwRef = value.substring(0, index); String throwMethod = value.substring(index + 1); reference = new RuntimeBeanReference(throwRef); beanDefinition.getPropertyValues().addPropertyValue("onthrowMethod", throwMethod); } else if ("oninvoke".equals(property)) { if ("ref".equals(property) && parserContext.getRegistry().containsBeanDefinition(value)) { BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value); if (!refBean.isSingleton()) { throw new IllegalStateException("The exported service ref " + value + " must be singleton! Please set the " + value + " bean scope to singleton, eg: <bean id=\"" + value + "\" scope=\"singleton\" ...>");
@Override public void insertBeanInTarget(String oldName) { assertTargetPresent(); PropertyValues sourceProperties = bean.getRawBeanDefinition().getPropertyValues(); String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName()); MutablePropertyValues targetProperties = target.getPropertyValues(); PropertyValue propertyValue = targetProperties.getPropertyValue(newName); @SuppressWarnings("unchecked") ManagedMap<String, Object> propertiesMap = (ManagedMap<String, Object>) (null == propertyValue ? null : propertyValue.getValue()); if (propertiesMap == null) { propertiesMap = new ManagedMap<>(); propertyValue = new PropertyValue(newName, propertiesMap); targetProperties.addPropertyValue(propertyValue); } PropertyValue propertyKey = sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY); AbstractBeanDefinition typedValueBeanDefinition = getTypedValue(sourceProperties); propertiesMap.put((String) propertyKey.getValue(), typedValueBeanDefinition); }
@SuppressWarnings({"unchecked"}) protected static String findDefaultFilterChainBeanId(ParserContext parserContext) { BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS); // Get the list of SecurityFilterChain beans List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue(); return filterChains.get(filterChains.size() - 1).getBeanName(); }
if (mpvs.isConverted()) { mbd.getResourceDescription(), beanName, "Error setting property values", ex); original = mpvs.getPropertyValueList(); boolean resolveNecessary = false; for (PropertyValue pv : original) { if (pv.isConverted()) { deepCopy.add(pv); String propertyName = pv.getName(); Object originalValue = pv.getValue(); Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue); Object convertedValue = resolvedValue; pv.setConvertedValue(convertedValue); !((TypedStringValue) originalValue).isDynamic() && !(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv); deepCopy.add(new PropertyValue(pv, convertedValue)); mpvs.setConverted(); mbd.getResourceDescription(), beanName, "Error setting property values", ex);