List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getBeanDefinitionNames
String[] getBeanDefinitionNames();
From source file:org.bytesoft.bytetcc.supports.dubbo.CompensableConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); String applicationBeanId = null; String registryBeanId = null; String transactionBeanId = null; String compensableBeanId = 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 is more than one application name was found!"); }//from w ww. ja va 2 s. co m } else if (org.bytesoft.bytetcc.TransactionCoordinator.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(transactionBeanId)) { transactionBeanId = beanName; } else { throw new FatalBeanException( "There is more than one org.bytesoft.bytetcc.TransactionCoordinator was found!"); } } else if (org.bytesoft.bytetcc.supports.dubbo.CompensableBeanRegistry.class.getName() .equals(beanClassName)) { if (StringUtils.isBlank(registryBeanId)) { registryBeanId = beanName; } else { throw new FatalBeanException( "There is more than one org.bytesoft.bytetcc.supports.dubbo.CompensableBeanRegistry was found!"); } } else if (org.bytesoft.bytetcc.CompensableCoordinator.class.getName().equals(beanClassName)) { if (StringUtils.isBlank(compensableBeanId)) { compensableBeanId = beanName; } else { throw new FatalBeanException( "There is more than one org.bytesoft.bytetcc.CompensableCoordinator 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(compensableBeanId)) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytetcc.CompensableCoordinator was found."); } else if (StringUtils.isBlank(transactionBeanId)) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytetcc.TransactionCoordinator was found."); } else if (registryBeanId == null) { throw new FatalBeanException( "No configuration of class org.bytesoft.bytetcc.supports.dubbo.CompensableBeanRegistry 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.CompensableAnnotationValidator.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Map<String, Class<?>> otherServiceMap = new HashMap<String, Class<?>>(); Map<String, Compensable> compensables = new HashMap<String, Compensable>(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; beanNameArray != null && i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String className = beanDef.getBeanClassName(); Class<?> clazz = null; try {// w w w . j av a 2 s .c om clazz = cl.loadClass(className); } catch (ClassNotFoundException ex) { continue; } try { Compensable compensable = clazz.getAnnotation(Compensable.class); if (compensable == null) { otherServiceMap.put(beanName, clazz); continue; } else { compensables.put(beanName, compensable); } Class<?> interfaceClass = compensable.interfaceClass(); if (interfaceClass.isInterface() == false) { throw new IllegalStateException("Compensable's interfaceClass must be a interface."); } Method[] methodArray = interfaceClass.getDeclaredMethods(); for (int j = 0; j < methodArray.length; j++) { Method interfaceMethod = methodArray[j]; Method method = clazz.getMethod(interfaceMethod.getName(), interfaceMethod.getParameterTypes()); this.validateDeclaredRemotingException(method, clazz); this.validateTransactionalPropagation(method, clazz); } } catch (IllegalStateException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (NoSuchMethodException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (SecurityException ex) { throw new FatalBeanException(ex.getMessage(), ex); } } Iterator<Map.Entry<String, Compensable>> itr = compensables.entrySet().iterator(); while (itr.hasNext()) { Map.Entry<String, Compensable> entry = itr.next(); Compensable compensable = entry.getValue(); Class<?> interfaceClass = compensable.interfaceClass(); String confirmableKey = compensable.confirmableKey(); String cancellableKey = compensable.cancellableKey(); if (StringUtils.isNotBlank(confirmableKey)) { if (compensables.containsKey(confirmableKey)) { throw new FatalBeanException(String .format("The confirm bean(id= %s) cannot be a compensable service!", confirmableKey)); } Class<?> clazz = otherServiceMap.get(confirmableKey); if (clazz == null) { throw new IllegalStateException( String.format("The confirm bean(id= %s) is not exists!", confirmableKey)); } try { Method[] methodArray = interfaceClass.getDeclaredMethods(); for (int j = 0; j < methodArray.length; j++) { Method interfaceMethod = methodArray[j]; Method method = clazz.getMethod(interfaceMethod.getName(), interfaceMethod.getParameterTypes()); this.validateDeclaredRemotingException(method, clazz); this.validateTransactionalPropagation(method, clazz); this.validateTransactionalRollbackFor(method, clazz, confirmableKey); } } catch (IllegalStateException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (NoSuchMethodException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (SecurityException ex) { throw new FatalBeanException(ex.getMessage(), ex); } } if (StringUtils.isNotBlank(cancellableKey)) { if (compensables.containsKey(cancellableKey)) { throw new FatalBeanException(String .format("The cancel bean(id= %s) cannot be a compensable service!", confirmableKey)); } Class<?> clazz = otherServiceMap.get(cancellableKey); if (clazz == null) { throw new IllegalStateException( String.format("The cancel bean(id= %s) is not exists!", cancellableKey)); } try { Method[] methodArray = interfaceClass.getDeclaredMethods(); for (int j = 0; j < methodArray.length; j++) { Method interfaceMethod = methodArray[j]; Method method = clazz.getMethod(interfaceMethod.getName(), interfaceMethod.getParameterTypes()); this.validateDeclaredRemotingException(method, clazz); this.validateTransactionalPropagation(method, clazz); this.validateTransactionalRollbackFor(method, clazz, cancellableKey); } } catch (IllegalStateException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (NoSuchMethodException ex) { throw new FatalBeanException(ex.getMessage(), ex); } catch (SecurityException ex) { throw new FatalBeanException(ex.getMessage(), ex); } } } }
From source file:org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { boolean trace = log.isTraceEnabled(); String[] names = beanFactory.getBeanDefinitionNames(); for (String name : names) { BeanDefinition definition = beanFactory.getBeanDefinition(name); if (definition.hasAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME)) { ConstructorArgumentValues cArgs = definition.getConstructorArgumentValues(); if (trace) log.trace("Inspecting cycles for (blueprint) bean " + name); tag(cArgs.getGenericArgumentValues(), name, definition); tag(cArgs.getIndexedArgumentValues().values(), name, definition); }//from w w w . ja v a2 s . c o m } }
From source file:org.gridgain.grid.kernal.processors.spring.GridSpringProcessorImpl.java
/** * Creates Spring application context. Optionally excluded properties can be specified, * it means that if such a property is found in {@link GridConfiguration} * then it is removed before the bean is instantiated. * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses. * * @param cfgUrl Resource where config file is located. * @param excludedProps Properties to be excluded. * @return Spring application context./*from www .j ava 2s . co m*/ */ public static ApplicationContext applicationContext(URL cfgUrl, final String... excludedProps) { GenericApplicationContext springCtx = new GenericApplicationContext(); BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition def = beanFactory.getBeanDefinition(beanName); if (def.getBeanClassName() != null) { try { Class.forName(def.getBeanClassName()); } catch (ClassNotFoundException ignored) { ((BeanDefinitionRegistry) beanFactory).removeBeanDefinition(beanName); continue; } } MutablePropertyValues vals = def.getPropertyValues(); for (PropertyValue val : new ArrayList<>(vals.getPropertyValueList())) { for (String excludedProp : excludedProps) { if (val.getName().equals(excludedProp)) vals.removePropertyValue(val); } } } } }; springCtx.addBeanFactoryPostProcessor(postProc); new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(cfgUrl)); springCtx.refresh(); return springCtx; }
From source file:org.impalaframework.spring.dynamic.DynamicBeansProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames().clone(); for (String beanName : beanDefinitionNames) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (logger.isInfoEnabled()) logger.info(beanName + ": " + beanDefinition.getScope()); if (beanDefinition.getScope().equals("dynamic") && beanFactory instanceof BeanDefinitionRegistry) { final BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) beanFactory; final String implBeanName = beanName + "Impl"; final String targetSourceBeanName = beanName + "TargetSource"; bdr.registerBeanDefinition(implBeanName, beanDefinition); /*/* www .j a v a2 s . c om*/ * <bean id="testInterface" * class="org.springframework.aop.framework.ProxyFactoryBean"> * <property name="targetSource"> <bean * class="org.impalaframework.spring.externalconfig.RefreshableTargetSourceFactoryBean"> * <property name="beanName" methodName = "testInterfaceImpl"/> * </bean> </property> </bean> */ RootBeanDefinition targetSource = new RootBeanDefinition(PrototypeTargetSource.class); targetSource.getPropertyValues().addPropertyValue("targetBeanName", implBeanName); bdr.registerBeanDefinition(targetSourceBeanName, targetSource); RootBeanDefinition proxy = new RootBeanDefinition(ProxyFactoryBean.class); proxy.getPropertyValues().addPropertyValue("targetSource", new RuntimeBeanReference(targetSourceBeanName)); bdr.registerBeanDefinition(beanName, proxy); } } }
From source file:org.impalaframework.spring.service.exporter.NamedServiceAutoExportPostProcessor.java
void processBeanFactory(final BeanFactoryCallback callback) { ConfigurableListableBeanFactory listableBeanFactory = ObjectUtils.cast(beanFactory, ConfigurableListableBeanFactory.class); // gets list of all bean definitions in this context final String[] beanNames = listableBeanFactory.getBeanDefinitionNames(); for (String beanName : beanNames) { final BeanDefinition beanDefinition = listableBeanFactory.getBeanDefinition(beanName); if (!beanDefinition.isAbstract()) { final Object bean = beanFactory.getBean(beanName); callback.doWithBean(beanName, bean); }// w w w .ja va 2 s . c o m } }
From source file:org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor.java
/** * Iterates through all beans in the factory and invokes processing * * @param beanFactory bean factory instance to process * @throws org.springframework.beans.BeansException *//*from www.j a v a 2 s .co m*/ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Set<String> processedBeanNames = new HashSet<String>(); LOG.info("Beginning post processing of bean factory for UIF expressions"); String[] beanNames = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNames.length; i++) { String beanName = beanNames[i]; BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); processBeanDefinition(beanName, beanDefinition, beanFactory, processedBeanNames); } LOG.info("Finished post processing of bean factory for UIF expressions"); }
From source file:org.openspaces.core.context.GigaSpaceLateContextBeanFactoryPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNames = beanFactory.getBeanDefinitionNames(); for (String beanName : beanNames) { if (!beanFactory.isSingleton(beanName)) { continue; }/*from w w w . j av a2 s . c o m*/ List<AnnotatedMember> metadata = findClassMetadata(beanFactory.getType(beanName)); if (metadata.isEmpty()) { continue; } Object bean = beanFactory.getBean(beanName); for (AnnotatedMember member : metadata) { member.inject(bean); } } }
From source file:org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (beanFactory != null && beanFactory.getBeanDefinitionCount() > 0) { for (String beanName : beanFactory.getBeanDefinitionNames()) { validateBeanScope(beanName, beanFactory.getBeanDefinition(beanName)); }// w w w. j av a 2s . co m } }
From source file:org.springframework.amqp.rabbit.stocks.context.RefreshScope.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { beanFactory.registerScope(name, this); setSerializationId(beanFactory);/* w ww .java 2s. c o m*/ this.beanFactory = beanFactory; evaluationContext = new StandardEvaluationContext(); evaluationContext.addPropertyAccessor(new BeanFactoryAccessor()); Assert.state(beanFactory instanceof BeanDefinitionRegistry, "BeanFactory was not a BeanDefinitionRegistry, so RefreshScope cannot be used."); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition definition = beanFactory.getBeanDefinition(beanName); // Replace this or any of its inner beans with scoped proxy if it // has this scope boolean scoped = name.equals(definition.getScope()); Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped); scopifier.visitBeanDefinition(definition); if (scoped) { createScopedProxy(beanName, definition, registry, proxyTargetClass); } } }