List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanDefinition
BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class); if (beanNameArray.length != 1) { throw new FatalBeanException("Multiple TransactionCuratorClient instance exists!"); }/*from w w w. j ava2 s. c o m*/ BeanDefinition beanDef = beanFactory.getBeanDefinition(beanNameArray[0]); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue(KEY_FIELD_ZOOKEEPER_ADDRESS); if (pv == null || pv.getValue() == null || StringUtils.isBlank(String.valueOf(pv.getValue()))) { this.initZookeeperAddressIfNecessary(beanFactory); } }
From source file:lodsve.core.condition.OnBeanCondition.java
private List<String> getPrimaryBeans(ConfigurableListableBeanFactory beanFactory, List<String> beanNames) { List<String> primaryBeans = new ArrayList<String>(); for (String beanName : beanNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (beanDefinition != null && beanDefinition.isPrimary()) { primaryBeans.add(beanName);/* w w w . ja v a 2s . co m*/ } } return primaryBeans; }
From source file:org.bytesoft.bytejta.supports.spring.TransactionBeanFactoryPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); String beanFactoryBeanId = null; List<BeanDefinition> beanFactoryAwareBeanIdList = new ArrayList<BeanDefinition>(); 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(); Class<?> beanClass = null; try {//from www . j a v a2 s .com beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { continue; } if (TransactionBeanFactoryAware.class.isAssignableFrom(beanClass)) { beanFactoryAwareBeanIdList.add(beanDef); } if (TransactionBeanFactory.class.isAssignableFrom(beanClass)) { if (beanFactoryBeanId == null) { beanFactoryBeanId = beanName; } else { throw new FatalBeanException("Duplicated transaction-bean-factory defined."); } } } for (int i = 0; beanFactoryBeanId != null && i < beanFactoryAwareBeanIdList.size(); i++) { BeanDefinition beanDef = beanFactoryAwareBeanIdList.get(i); MutablePropertyValues mpv = beanDef.getPropertyValues(); RuntimeBeanReference beanRef = new RuntimeBeanReference(beanFactoryBeanId); mpv.addPropertyValue(TransactionBeanFactoryAware.BEAN_FACTORY_FIELD_NAME, beanRef); } }
From source file:de.extra.client.core.annotation.PropertyPlaceholderPluginConfigurer.java
private void setPluginProperties(final ConfigurableListableBeanFactory beanFactory, final Properties properties, final String beanName, final Class<?> clazz) { final PluginConfiguration annotationConfigutation = clazz.getAnnotation(PluginConfiguration.class); final MutablePropertyValues mutablePropertyValues = beanFactory.getBeanDefinition(beanName) .getPropertyValues();/*from w ww .jav a 2 s . c o m*/ for (final PropertyDescriptor property : BeanUtils.getPropertyDescriptors(clazz)) { final Method setter = property.getWriteMethod(); PluginValue valueAnnotation = null; if (setter != null && setter.isAnnotationPresent(PluginValue.class)) { valueAnnotation = setter.getAnnotation(PluginValue.class); } if (valueAnnotation != null) { final String key = extractKey(annotationConfigutation, valueAnnotation, clazz); final String value = resolvePlaceholder(key, properties, SYSTEM_PROPERTIES_MODE_FALLBACK); if (StringUtils.isEmpty(value)) { throw new BeanCreationException(beanName, "No such property=[" + key + "] found in properties."); } if (LOG.isDebugEnabled()) { LOG.debug("setting property=[" + clazz.getName() + "." + property.getName() + "] value=[" + key + "=" + value + "]"); } mutablePropertyValues.addPropertyValue(property.getName(), value); } } for (final Field field : clazz.getDeclaredFields()) { if (LOG.isDebugEnabled()) { LOG.debug("examining field=[" + clazz.getName() + "." + field.getName() + "]"); } if (field.isAnnotationPresent(PluginValue.class)) { final PluginValue valueAnnotation = field.getAnnotation(PluginValue.class); final PropertyDescriptor property = BeanUtils.getPropertyDescriptor(clazz, field.getName()); if (property == null || property.getWriteMethod() == null) { throw new BeanCreationException(beanName, "setter for property=[" + clazz.getName() + "." + field.getName() + "] not available."); } final String key = extractKey(annotationConfigutation, valueAnnotation, clazz); String value = resolvePlaceholder(key, properties, SYSTEM_PROPERTIES_MODE_FALLBACK); if (value == null) { // DEFAULT Value suchen final int separatorIndex = key.indexOf(VALUE_SEPARATOR); if (separatorIndex != -1) { final String actualPlaceholder = key.substring(0, separatorIndex); final String defaultValue = key.substring(separatorIndex + VALUE_SEPARATOR.length()); value = resolvePlaceholder(actualPlaceholder, properties, SYSTEM_PROPERTIES_MODE_FALLBACK); if (value == null) { value = defaultValue; } } } if (value != null) { if (LOG.isDebugEnabled()) { LOG.debug("setting property=[" + clazz.getName() + "." + field.getName() + "] value=[" + key + "=" + value + "]"); } mutablePropertyValues.addPropertyValue(field.getName(), value); } else if (!ignoreNullValues) { throw new BeanCreationException(beanName, "No such property=[" + key + "] found in properties."); } } } }
From source file:org.bytesoft.bytejta.supports.dubbo.TransactionConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); String applicationBeanId = null; String registryBeanId = null; String transactionBeanId = null; for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); if (com.alibaba.dubbo.config.ApplicationConfig.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(applicationBeanId)) { applicationBeanId = beanName; } else { throw new FatalBeanException("There are more than one application name was found!"); }/*from ww w . ja va 2s.c o m*/ } else if (org.bytesoft.bytejta.TransactionCoordinator.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(transactionBeanId)) { transactionBeanId = beanName; } else { throw new FatalBeanException( "There are more than one org.bytesoft.bytejta.TransactionCoordinator was found!"); } } else if (org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry.class.getName() .equals(beanClassName)) { if (StringUtils.isBlank(registryBeanId)) { registryBeanId = beanName; } else { throw new FatalBeanException( "There are more than one org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found!"); } } } if (StringUtils.isBlank(applicationBeanId)) { throw new FatalBeanException("No application name was found!"); } BeanDefinition beanDef = beanFactory.getBeanDefinition(applicationBeanId); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("name"); if (pv == null || pv.getValue() == null || StringUtils.isBlank(String.valueOf(pv.getValue()))) { throw new FatalBeanException("No application name was found!"); } if (StringUtils.isBlank(transactionBeanId)) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytejta.TransactionCoordinator was found."); } else if (registryBeanId == null) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytejta.supports.dubbo.TransactionBeanRegistry was found."); } String application = String.valueOf(pv.getValue()); this.initializeForProvider(beanFactory, application, transactionBeanId); this.initializeForConsumer(beanFactory, application, registryBeanId); }
From source file:org.bytesoft.bytetcc.supports.spring.CompensableContextPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); String targetBeanId = null;// w w w.j a v a 2 s .com List<BeanDefinition> beanDefList = new ArrayList<BeanDefinition>(); 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(); Class<?> beanClass = null; try { beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { logger.debug("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex); continue; } if (CompensableContextAware.class.isAssignableFrom(beanClass)) { beanDefList.add(beanDef); } if (CompensableContext.class.isAssignableFrom(beanClass)) { if (targetBeanId == null) { targetBeanId = beanName; } else { throw new FatalBeanException("Duplicated compensable-context defined."); } } } for (int i = 0; targetBeanId != null && i < beanDefList.size(); i++) { BeanDefinition beanDef = beanDefList.get(i); MutablePropertyValues mpv = beanDef.getPropertyValues(); RuntimeBeanReference beanRef = new RuntimeBeanReference(targetBeanId); mpv.addPropertyValue(CompensableContextAware.COMPENSABLE_CONTEXT_FIELD_NAME, beanRef); } }
From source file:org.bytesoft.bytejta.supports.spring.TransactionEndpointPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); BeanDefinition protocolDef = null;//from w w w.j a v a 2 s . com List<BeanDefinition> beanDefList = new ArrayList<BeanDefinition>(); 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(); Class<?> beanClass = null; try { beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { continue; } if (TransactionEndpointAware.class.isAssignableFrom(beanClass)) { beanDefList.add(beanDef); } else if (ProtocolConfig.class.isAssignableFrom(beanClass)) { if (protocolDef == null) { protocolDef = beanDef; } else { throw new FatalBeanException( "There are more than one com.alibaba.dubbo.config.ProtocolConfig was found!"); } } } if (protocolDef == null) { throw new FatalBeanException( "No configuration of class com.alibaba.dubbo.config.ProtocolConfig was found."); } MutablePropertyValues protocolValues = protocolDef.getPropertyValues(); PropertyValue protocolValue = protocolValues.getPropertyValue("port"); if (protocolValue == null || protocolValue.getValue() == null) { throw new FatalBeanException("Attribute 'port' of <dubbo:protocol ... /> is null."); } String host = CommonUtils.getInetAddress(); String port = String.valueOf(protocolValue.getValue()); String identifier = String.format("%s:%s", host, port); for (int i = 0; i < beanDefList.size(); i++) { BeanDefinition beanDef = beanDefList.get(i); MutablePropertyValues mpv = beanDef.getPropertyValues(); mpv.addPropertyValue(TransactionEndpointAware.ENDPOINT_FIELD_NAME, identifier); } }
From source file:org.bytesoft.bytetcc.supports.spring.CompensableEndpointPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); BeanDefinition protocolDef = null;//w w w . j av a2s. c om List<BeanDefinition> beanDefList = new ArrayList<BeanDefinition>(); 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(); Class<?> beanClass = null; try { beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { logger.debug("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex); continue; } if (CompensableEndpointAware.class.isAssignableFrom(beanClass)) { beanDefList.add(beanDef); } else if (ProtocolConfig.class.isAssignableFrom(beanClass)) { if (protocolDef == null) { protocolDef = beanDef; } else { throw new FatalBeanException( "There are more than one com.alibaba.dubbo.config.ProtocolConfig was found!"); } } } if (protocolDef == null) { throw new FatalBeanException( "No configuration of class com.alibaba.dubbo.config.ProtocolConfig was found."); } MutablePropertyValues protocolValues = protocolDef.getPropertyValues(); PropertyValue protocolValue = protocolValues.getPropertyValue("port"); if (protocolValue == null || protocolValue.getValue() == null) { throw new FatalBeanException("Attribute 'port' of <dubbo:protocol ... /> is null."); } String host = CommonUtils.getInetAddress(); String port = String.valueOf(protocolValue.getValue()); String identifier = String.format("%s:%s", host, port); for (int i = 0; i < beanDefList.size(); i++) { BeanDefinition beanDef = beanDefList.get(i); MutablePropertyValues mpv = beanDef.getPropertyValues(); mpv.addPropertyValue(CompensableEndpointAware.ENDPOINT_FIELD_NAME, identifier); } }
From source file:org.echocat.jomon.spring.BeanPostConfigurer.java
@Nonnull protected List<AbstractBeanDefinition> getAllBeanDefinitionsBy(@Nonnull String targetBeanDefinitionName, @Nonnull ConfigurableListableBeanFactory beanFactory) { final List<AbstractBeanDefinition> result = new ArrayList<>(); for (final String beanDefinitionName : beanFactory.getBeanDefinitionNames()) { if (targetBeanDefinitionName.equals(beanDefinitionName) || beanDefinitionName.startsWith(targetBeanDefinitionName + "#")) { result.add((AbstractBeanDefinition) beanFactory.getBeanDefinition(beanDefinitionName)); } else {/*from w w w . j a v a 2 s.c om*/ for (final String alias : beanFactory.getAliases(beanDefinitionName)) { if (targetBeanDefinitionName.equals(alias)) { result.add((AbstractBeanDefinition) beanFactory.getBeanDefinition(beanDefinitionName)); } } } } return result; }