List of usage examples for org.springframework.beans.factory.config BeanDefinition getPropertyValues
MutablePropertyValues getPropertyValues();
From source file:com.brienwheeler.apps.schematool.SchemaToolBean.java
@SuppressWarnings("unchecked") private PersistenceUnitManager simulateDefaultPum(NonInitializingClassPathXmlApplicationContext context, BeanDefinition emfBeanDef) { // Simulate Spring's use of DefaultPersistenceUnitManager DefaultPersistenceUnitManager defpum = new DefaultPersistenceUnitManager(); // Set the location of the persistence XML -- when using the DPUM, // you can only set one persistence XML location on the EntityManagerFactory PropertyValue locationProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceXmlLocation"); if (locationProperty == null || !(locationProperty.getValue() instanceof TypedStringValue)) { throw new RuntimeException( "no property 'persistenceXmlLocation' defined on bean: " + emfContextBeanName); }/*from w ww . j a v a2s . c o m*/ // Since PersistenceUnitPostProcessors may do things like set properties // onto the persistence unit, we need to instantiate them here so that // they get called when preparePersistenceUnitInfos() executes PropertyValue puiPostProcProperty = emfBeanDef.getPropertyValues() .getPropertyValue("persistenceUnitPostProcessors"); if (puiPostProcProperty != null && puiPostProcProperty.getValue() instanceof ManagedList) { List<PersistenceUnitPostProcessor> postProcessors = new ArrayList<PersistenceUnitPostProcessor>(); for (BeanDefinitionHolder postProcBeanDef : (ManagedList<BeanDefinitionHolder>) puiPostProcProperty .getValue()) { String beanName = postProcBeanDef.getBeanName(); BeanDefinition beanDefinition = postProcBeanDef.getBeanDefinition(); PersistenceUnitPostProcessor postProcessor = (PersistenceUnitPostProcessor) context .createBean(beanName, beanDefinition); postProcessors.add(postProcessor); } defpum.setPersistenceUnitPostProcessors( postProcessors.toArray(new PersistenceUnitPostProcessor[postProcessors.size()])); } defpum.setPersistenceXmlLocation(((TypedStringValue) locationProperty.getValue()).getValue()); defpum.preparePersistenceUnitInfos(); return defpum; }
From source file:com.laxser.blitz.lama.core.LamaDaoProcessor.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (logger.isInfoEnabled()) { logger.info("[jade] starting ..."); }/*from w w w .j a v a 2 s . c o m*/ final List<ResourceRef> resources; try { resources = BlitzScanner.getInstance().getJarOrClassesFolderResources(); } catch (IOException e) { throw new ApplicationContextException("error on getJarResources/getClassesFolderResources", e); } List<String> urls = new LinkedList<String>(); for (ResourceRef resourceInfo : resources) { if (resourceInfo.hasModifier("dao") || resourceInfo.hasModifier("DAO")) { try { Resource resource = resourceInfo.getResource(); File resourceFile = resource.getFile(); if (resourceFile.isFile()) { urls.add("jar:file:" + resourceFile.toURI().getPath() + ResourceUtils.JAR_URL_SEPARATOR); } else if (resourceFile.isDirectory()) { urls.add(resourceFile.toURI().toString()); } } catch (IOException e) { throw new ApplicationContextException("error on resource.getFile", e); } } } if (logger.isInfoEnabled()) { logger.info("[jade] found " + urls.size() + " jade urls: " + urls); } if (urls.size() > 0) { LamaDaoComponentProvider provider = new LamaDaoComponentProvider(true); if (filters != null) { for (TypeFilter excludeFilter : filters) { provider.addExcludeFilter(excludeFilter); } } final DataAccessProvider dataAccessProvider = createJdbcTemplateDataAccessProvider(); Set<String> daoClassNames = new HashSet<String>(); for (String url : urls) { if (logger.isInfoEnabled()) { logger.info("[jade] call 'jade/find'"); } Set<BeanDefinition> dfs = provider.findCandidateComponents(url); if (logger.isInfoEnabled()) { logger.info("[jade] found " + dfs.size()// + " beanDefinition from '" + url + "'"); } for (BeanDefinition beanDefinition : dfs) { String daoClassName = beanDefinition.getBeanClassName(); if (daoClassNames.contains(daoClassName)) { if (logger.isDebugEnabled()) { logger.debug("[jade] ignored replicated jade dao class: " + daoClassName + " [" + url + "]"); } continue; } daoClassNames.add(daoClassName); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); propertyValues.addPropertyValue("dataAccessProvider", dataAccessProvider); propertyValues.addPropertyValue("daoClass", daoClassName); ScannedGenericBeanDefinition scannedBeanDefinition = (ScannedGenericBeanDefinition) beanDefinition; scannedBeanDefinition.setPropertyValues(propertyValues); scannedBeanDefinition.setBeanClass(LamaDaoFactoryBean.class); DefaultListableBeanFactory defaultBeanFactory = (DefaultListableBeanFactory) beanFactory; defaultBeanFactory.registerBeanDefinition(daoClassName, beanDefinition); if (logger.isDebugEnabled()) { logger.debug("[jade] register jade dao bean: " + daoClassName); } } } } if (logger.isInfoEnabled()) { logger.info("[jade] exits"); } }
From source file:de.acosix.alfresco.utility.common.spring.PropertyAlteringBeanFactoryPostProcessor.java
protected void applyChange(final Function<String, BeanDefinition> getBeanDefinition) { final BeanDefinition beanDefinition = getBeanDefinition.apply(this.targetBeanName); if (beanDefinition != null) { LOGGER.debug("[{}] Patching property {} of Spring bean {}", this.beanName, this.propertyName, this.targetBeanName); final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); final PropertyValue configuredValue = propertyValues.getPropertyValue(this.propertyName); final Object value; if (this.valueList != null || this.beanReferenceNameList != null) { value = this.handleListValues(configuredValue); } else if (this.valueSet != null || this.beanReferenceNameSet != null) { value = this.handleSetValues(configuredValue); } else if (this.valueMap != null || this.beanReferenceNameMap != null) { value = this.handleMapValues(configuredValue); } else if (this.value != null) { LOGGER.debug("[{}] Setting new value {} for {} of {}", this.beanName, this.value, this.propertyName, this.targetBeanName); value = this.value; } else if (this.beanReferenceName != null) { LOGGER.debug("[{}] Setting new bean reference to {} for {} of {}", this.beanName, this.beanReferenceName, this.propertyName, this.targetBeanName); value = new RuntimeBeanReference(this.beanReferenceName); } else {//from ww w .j av a2s .com value = null; } if (value != null) { final PropertyValue newValue = new PropertyValue(this.propertyName, value); propertyValues.addPropertyValue(newValue); } else if (configuredValue != null) { LOGGER.debug("[{}] Removing {} property definition from Spring bean {}", this.propertyName, this.targetBeanName); propertyValues.removePropertyValue(configuredValue); } } else { LOGGER.info("[{}] patch cannot be applied - no bean with name {} has been defined", this.beanName, this.targetBeanName); } }
From source file:eap.config.AspectJAutoProxyBeanDefinitionParser.java
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); }/*from www . j av a 2 s. c om*/ } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
From source file:org.bytesoft.bytetcc.supports.spring.TransactionConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName() .equals(beanClassName)) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName));/* w w w .j a v a2s.c o m*/ } if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName() .equals(beanClassName)) { boolean errorExists = true; MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource"); Object value = pv == null ? null : pv.getValue(); if (value != null && RuntimeBeanReference.class.isInstance(value)) { RuntimeBeanReference reference = (RuntimeBeanReference) value; BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName()); String refBeanClassName = refBeanDef.getBeanClassName(); errorExists = AnnotationTransactionAttributeSource.class.getName() .equals(refBeanClassName) == false; } if (errorExists) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName)); } } } }
From source file:org.bigtester.ate.xmlschema.RepeatStepBeanDefinitionParser.java
/** * {@inheritDoc}/* w w w. ja va 2 s . com*/ */ @Override protected AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext) { // Here we parse the Spring elements such as < property> if (parserContext == null || element == null) throw GlobalUtils.createNotInitializedException("element and parserContext"); BeanDefinition bDef = super.parseInternal(element, parserContext); bDef.setBeanClassName(RepeatStep.class.getName()); String startStepname = element.getAttribute(XsdElementConstants.ATTR_REPEATSTEP_STARTSTEPNAME); if (StringUtils.hasText(startStepname)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(startStepname); } String endStepname = element.getAttribute(XsdElementConstants.ATTR_REPEATSTEP_ENDSTEPNAME); if (StringUtils.hasText(endStepname)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(endStepname); } boolean continuef = Boolean .parseBoolean(element.getAttribute(XsdElementConstants.ATTR_REPEATSTEP_CONTINUEONFAILURE)); bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_REPEATSTEP_CONTINUEONFAILURE, continuef); int iter = Integer.parseInt(element.getAttribute(XsdElementConstants.ATTR_REPEATSTEP_NUMBEROFITERATIONS)); bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_REPEATSTEP_NUMBEROFITERATIONS, iter); boolean asserterSame = Boolean .parseBoolean(element.getAttribute(XsdElementConstants.ATTR_REPEATSTEP_ASSERTERVALUESREMAINSAME)); bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_REPEATSTEP_ASSERTERVALUESREMAINSAME, asserterSame); parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef); return (AbstractBeanDefinition) bDef; }
From source file:org.devefx.httpmapper.spring.mapper.MapperScannerConfigurer.java
/** * BeanDefinitionRegistries are called early in application startup, before * BeanFactoryPostProcessors. This means that PropertyResourceConfigurers will not have been * loaded and any property substitution of this class' properties will fail. To avoid this, find * any PropertyResourceConfigurers defined in the context and run them on this class' bean * definition. Then update the values./*from w w w. ja va2s . c om*/ */ private void processPropertyPlaceHolders() { Map<String, PropertyResourceConfigurer> prcs = applicationContext .getBeansOfType(PropertyResourceConfigurer.class); if (!prcs.isEmpty() && applicationContext instanceof GenericApplicationContext) { BeanDefinition mapperScannerBean = ((GenericApplicationContext) applicationContext).getBeanFactory() .getBeanDefinition(beanName); // PropertyResourceConfigurer does not expose any methods to explicitly perform // property placeholder substitution. Instead, create a BeanFactory that just // contains this mapper scanner and post process the factory. DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition(beanName, mapperScannerBean); for (PropertyResourceConfigurer prc : prcs.values()) { prc.postProcessBeanFactory(factory); } PropertyValues values = mapperScannerBean.getPropertyValues(); this.basePackage = updatePropertyValue("basePackage", values); this.configBeanName = updatePropertyValue("configBeanName", values); } }
From source file:cn.guoyukun.spring.SpeedUpSpringProcessor.java
private boolean needRemove(String beanName, BeanDefinition beanDefinition) { if (ArrayUtils.isNotEmpty(removedBeanNames)) { for (String removedBeanName : removedBeanNames) { if (beanName.equals(removedBeanName)) { return true; }//from ww w.ja va2 s . c o m if (beanDefinition.getBeanClassName().equals(removedBeanName)) { return true; } } } if (this.removedBeanProperties != null) { Set<String[]> propertiesSet = removedBeanProperties.get(beanName); if (propertiesSet != null) { Iterator<String[]> iter = propertiesSet.iterator(); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); while (iter.hasNext()) { String[] properties = iter.next(); if (properties.length == 1) { // propertyValues.removePropertyValue(properties[0]); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0]; if (this.replaceBeanProperties.containsKey(key)) { propertyValues.add(properties[0], this.replaceBeanProperties.get(key)); } } } else { PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]); if (propertyValue != null) { Object nextValue = propertyValue.getValue(); //??? + Map if (nextValue instanceof ManagedMap) { TypedStringValue typedStringValue = new TypedStringValue(properties[1]); ((ManagedMap) nextValue).remove(typedStringValue); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0] + "@" + properties[1]; if (this.replaceBeanProperties.containsKey(key)) { ((ManagedMap) nextValue).put(properties[1], this.replaceBeanProperties.get(key)); } } } } } } } } String className = beanDefinition.getBeanClassName(); //spring data jpa if (className.equals("cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean") || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) { PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues() .getPropertyValue("repositoryInterface"); if (repositoryInterfaceValue != null) { className = repositoryInterfaceValue.getValue().toString(); } } if (ArrayUtils.isEmpty(this.removedClassPatterns)) { return false; } if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) { for (String includeClassPattern : includeClassPatterns) { if (className.matches(includeClassPattern)) { return false; } } } for (String removedClassPattern : removedClassPatterns) { if (className.matches(removedClassPattern)) { return true; } } return false; }
From source file:com.luna.common.spring.SpeedUpSpringProcessor.java
private boolean needRemove(String beanName, BeanDefinition beanDefinition) { if (ArrayUtils.isNotEmpty(removedBeanNames)) { for (String removedBeanName : removedBeanNames) { if (beanName.equals(removedBeanName)) { return true; }/*from ww w .j a v a 2 s .c o m*/ if (beanDefinition.getBeanClassName().equals(removedBeanName)) { return true; } } } if (this.removedBeanProperties != null) { Set<String[]> propertiesSet = removedBeanProperties.get(beanName); if (propertiesSet != null) { Iterator<String[]> iter = propertiesSet.iterator(); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); while (iter.hasNext()) { String[] properties = iter.next(); if (properties.length == 1) { // propertyValues.removePropertyValue(properties[0]); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0]; if (this.replaceBeanProperties.containsKey(key)) { propertyValues.add(properties[0], this.replaceBeanProperties.get(key)); } } } else { PropertyValue propertyValue = propertyValues.getPropertyValue(properties[0]); if (propertyValue != null) { Object nextValue = propertyValue.getValue(); //??? + Map if (nextValue instanceof ManagedMap) { TypedStringValue typedStringValue = new TypedStringValue(properties[1]); ((ManagedMap) nextValue).remove(typedStringValue); //????? if (this.replaceBeanProperties != null) { String key = beanName + "@" + properties[0] + "@" + properties[1]; if (this.replaceBeanProperties.containsKey(key)) { ((ManagedMap) nextValue).put(properties[1], this.replaceBeanProperties.get(key)); } } } } } } } } String className = beanDefinition.getBeanClassName(); //spring data jpa if (className.equals("com.luna.common.repository.support.SimpleBaseRepositoryFactoryBean") || className.equals("org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean")) { PropertyValue repositoryInterfaceValue = beanDefinition.getPropertyValues() .getPropertyValue("repositoryInterface"); if (repositoryInterfaceValue != null) { className = repositoryInterfaceValue.getValue().toString(); } } if (ArrayUtils.isEmpty(this.removedClassPatterns)) { return false; } if (ArrayUtils.isNotEmpty(this.includeClassPatterns)) { for (String includeClassPattern : includeClassPatterns) { if (className.matches(includeClassPattern)) { return false; } } } for (String removedClassPattern : removedClassPatterns) { if (className.matches(removedClassPattern)) { return true; } } return false; }