List of usage examples for org.springframework.beans.factory.config BeanDefinition isAbstract
boolean isAbstract();
From source file:me.springframework.di.spring.SpringConfigurationLoader.java
/** * Returns a {@link Map} of {@link MutableInstance MutableInstances}, * indexed by name./*from ww w . j a v a 2 s. c om*/ * * @param registry * The {@link BeanDefinitionRegistry} holding the bean * definitions. * @return A {@link Map} of {@link MutableInstance MutableInstances} * representing the root beans defined by the * {@link ListableBeanFactory}. */ protected static MutableContext loadBeans(ConfigurableListableBeanFactory factory) { MutableContext context = new MutableContext(); for (String name : factory.getBeanDefinitionNames()) { for (String alias : factory.getAliases(name)) { context.addAlias(alias, name); } } for (String name : factory.getBeanDefinitionNames()) { BeanDefinition definition = factory.getBeanDefinition(name); if (!definition.isAbstract()) { BeanDefinition merged = factory.getMergedBeanDefinition(name); MutableInstance instance = new MutableInstance(name); load(instance, merged, context); context.addInstance(name, instance); } } return context; }
From source file:de.contentreich.instrumentation.SpringBeansHelper.java
private Class getBeanClass(String beanName, DefaultListableBeanFactory beanFactory) { Class clazz = null;//from w w w .j a v a 2 s .com if (beanFactory != null) { BeanDefinition definition = beanFactory.getBeanDefinition(beanName); if (!definition.isAbstract()) { clazz = beanFactory.getType(beanName); } } return clazz; }
From source file:org.nuunframework.spring.SpringModule.java
@SuppressWarnings("unchecked") private void bindFromApplicationContext() { boolean debugEnabled = logger.isDebugEnabled(); ConfigurableListableBeanFactory currentBeanFactory = this.beanFactory; do {/* w ww . j a v a2 s. c o m*/ for (String beanName : currentBeanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName); if (!beanDefinition.isAbstract()) { Class<?> beanClass = classFromString(beanDefinition.getBeanClassName()); if (beanClass == null) { logger.warn("Cannot bind spring bean " + beanName + " because its class " + beanDefinition.getBeanClassName() + " failed to load"); return; } SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName, currentBeanFactory); // Adding bean with its base type addBeanDefinition(beanClass, springBeanDefinition); // Adding bean with its parent type if enabled Class<?> parentClass = beanClass.getSuperclass(); if (parentClass != null && parentClass != Object.class) addBeanDefinition(parentClass, springBeanDefinition); // Adding bean with its immediate interfaces if enabled for (Class<?> i : beanClass.getInterfaces()) addBeanDefinition(i, springBeanDefinition); } } BeanFactory factory = currentBeanFactory.getParentBeanFactory(); if (factory != null) { if (factory instanceof ConfigurableListableBeanFactory) currentBeanFactory = (ConfigurableListableBeanFactory) factory; else { logger.info( "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory"); currentBeanFactory = null; } } else currentBeanFactory = null; } while (currentBeanFactory != null); for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : this.beanDefinitions.entrySet()) { Class<?> type = entry.getKey(); Map<String, SpringBeanDefinition> definitions = entry.getValue(); // Bind by name for each bean of this type and by type if there is no ambiguity for (SpringBeanDefinition candidate : definitions.values()) { if (debugEnabled) logger.info("Binding spring bean " + candidate.getName() + " by name and type " + type.getCanonicalName()); bind(type).annotatedWith(Names.named(candidate.getName())).toProvider( new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory())); } } }
From source file:io.nuun.plugin.spring.SpringModule.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void bindFromApplicationContext() { boolean debugEnabled = logger.isDebugEnabled(); ConfigurableListableBeanFactory currentBeanFactory = beanFactory; do {/*w ww . jav a 2 s . co m*/ for (String beanName : currentBeanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName); if (!beanDefinition.isAbstract()) { Class<?> beanClass = classFromString(beanDefinition.getBeanClassName()); if (beanClass == null) { logger.warn("Cannot bind spring bean " + beanName + " because its class " + beanDefinition.getBeanClassName() + " failed to load"); return; } SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName, currentBeanFactory); // Adding bean with its base type addBeanDefinition(beanClass, springBeanDefinition); // Adding bean with its parent type if enabled Class<?> parentClass = beanClass.getSuperclass(); if (parentClass != null && parentClass != Object.class) { addBeanDefinition(parentClass, springBeanDefinition); } // Adding bean with its immediate interfaces if enabled for (Class<?> i : beanClass.getInterfaces()) { addBeanDefinition(i, springBeanDefinition); } } } BeanFactory factory = currentBeanFactory.getParentBeanFactory(); if (factory != null) { if (factory instanceof ConfigurableListableBeanFactory) { currentBeanFactory = (ConfigurableListableBeanFactory) factory; } else { logger.info( "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory"); currentBeanFactory = null; } } else { currentBeanFactory = null; } } while (currentBeanFactory != null); for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : beanDefinitions.entrySet()) { Class<?> type = entry.getKey(); Map<String, SpringBeanDefinition> definitions = entry.getValue(); // Bind by name for each bean of this type and by type if there is no ambiguity for (SpringBeanDefinition candidate : definitions.values()) { if (debugEnabled) { logger.info("Binding spring bean " + candidate.getName() + " by name and type " + type.getCanonicalName()); } bind(type).annotatedWith(Names.named(candidate.getName())).toProvider( new ByNameSpringContextProvider(type, candidate.getName(), candidate.getBeanFactory())); } } }
From source file:com.sourceallies.beanoh.BeanohTestCase.java
private void iterateBeanDefinitions(BeanDefinitionAction action) { String[] names = context.getBeanDefinitionNames(); for (String name : names) { BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition(name); if (!beanDefinition.isAbstract()) { action.execute(name, beanDefinition); }/*w w w.ja v a 2 s . c o m*/ } }
From source file:org.seedstack.spring.internal.SpringModule.java
@SuppressWarnings("unchecked") private void bindFromApplicationContext() { boolean debugEnabled = LOGGER.isDebugEnabled(); ConfigurableListableBeanFactory currentBeanFactory = this.beanFactory; do {/*from ww w .j a v a 2 s . c o m*/ for (String beanName : currentBeanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = currentBeanFactory.getMergedBeanDefinition(beanName); if (!beanDefinition.isAbstract()) { Class<?> beanClass; try { beanClass = Class.forName(beanDefinition.getBeanClassName()); } catch (ClassNotFoundException e) { LOGGER.warn("Cannot bind spring bean " + beanName + " because its class " + beanDefinition.getBeanClassName() + " failed to load", e); continue; } // FactoryBean special case: retrieve it and query for the object type it creates if (FactoryBean.class.isAssignableFrom(beanClass)) { beanClass = ((FactoryBean) currentBeanFactory.getBean('&' + beanName)).getObjectType(); if (beanClass == null) { LOGGER.warn("Cannot bind spring bean " + beanName + " because its factory bean cannot determine its class"); continue; } } SpringBeanDefinition springBeanDefinition = new SpringBeanDefinition(beanName, currentBeanFactory); // Adding bean with its base type addBeanDefinition(beanClass, springBeanDefinition); // Adding bean with its parent type if enabled Class<?> parentClass = beanClass.getSuperclass(); if (parentClass != null && parentClass != Object.class) { addBeanDefinition(parentClass, springBeanDefinition); } // Adding bean with its immediate interfaces if enabled for (Class<?> i : beanClass.getInterfaces()) { addBeanDefinition(i, springBeanDefinition); } } } BeanFactory factory = currentBeanFactory.getParentBeanFactory(); if (factory != null) { if (factory instanceof ConfigurableListableBeanFactory) { currentBeanFactory = (ConfigurableListableBeanFactory) factory; } else { LOGGER.info( "Cannot go up further in the bean factory hierarchy, parent bean factory doesn't implement ConfigurableListableBeanFactory"); currentBeanFactory = null; } } else { currentBeanFactory = null; } } while (currentBeanFactory != null); for (Map.Entry<Class<?>, Map<String, SpringBeanDefinition>> entry : this.beanDefinitions.entrySet()) { Class<?> type = entry.getKey(); Map<String, SpringBeanDefinition> definitions = entry.getValue(); // Bind by name for each bean of this type and by type if there is no ambiguity for (SpringBeanDefinition candidate : definitions.values()) { if (debugEnabled) { LOGGER.info("Binding spring bean " + candidate.getName() + " by name and type " + type.getCanonicalName()); } bind(type).annotatedWith(Names.named(candidate.getName())) .toProvider(new SpringBeanProvider(type, candidate.getName(), candidate.getBeanFactory())); } } }
From source file:com.haulmont.cuba.core.app.AbstractBeansMetadata.java
protected List<MethodInfo> getAvailableMethods(String beanName) { List<MethodInfo> methods = new ArrayList<>(); try {//from ww w. j av a2 s . c om AutowireCapableBeanFactory beanFactory = AppContext.getApplicationContext() .getAutowireCapableBeanFactory(); if (beanFactory instanceof CubaDefaultListableBeanFactory) { BeanDefinition beanDefinition = ((CubaDefaultListableBeanFactory) beanFactory) .getBeanDefinition(beanName); if (beanDefinition.isAbstract()) return methods; } Object bean = AppBeans.get(beanName); @SuppressWarnings("unchecked") List<Class> classes = ClassUtils.getAllInterfaces(bean.getClass()); for (Class aClass : classes) { if (aClass.getName().startsWith("org.springframework.")) continue; Class<?> targetClass = bean instanceof TargetClassAware ? ((TargetClassAware) bean).getTargetClass() : bean.getClass(); for (Method method : aClass.getMethods()) { if (isMethodAvailable(method)) { Method targetClassMethod = targetClass.getMethod(method.getName(), method.getParameterTypes()); List<MethodParameterInfo> methodParameters = getMethodParameters(targetClassMethod); MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters); addMethod(methods, methodInfo); } } if (methods.isEmpty()) { for (Method method : bean.getClass().getMethods()) { if (!method.getDeclaringClass().equals(Object.class) && isMethodAvailable(method)) { List<MethodParameterInfo> methodParameters = getMethodParameters(method); MethodInfo methodInfo = new MethodInfo(method.getName(), methodParameters); addMethod(methods, methodInfo); } } } } } catch (Throwable t) { log.debug(t.getMessage()); } return methods; }
From source file:org.solmix.runtime.support.spring.SpringBeanProvider.java
public boolean hasConfiguredPropertyValue(String beanName, String propertyName, String searchValue) { if (context.containsBean(beanName) && !passThroughs.contains(beanName)) { ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext) context; BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanName); if (!ctxt.getBeanFactory().isSingleton(beanName) || def.isAbstract()) { return false; }//from w w w .j a va2 s. c o m Collection<?> ids = null; PropertyValue pv = def.getPropertyValues().getPropertyValue(propertyName); if (pv != null) { Object value = pv.getValue(); if (!(value instanceof Collection)) { throw new RuntimeException("The property " + propertyName + " must be a collection!"); } if (value instanceof Mergeable) { if (!((Mergeable) value).isMergeEnabled()) { ids = (Collection<?>) value; } } else { ids = (Collection<?>) value; } } if (ids != null) { for (Iterator<?> itr = ids.iterator(); itr.hasNext();) { Object o = itr.next(); if (o instanceof TypedStringValue) { if (searchValue.equals(((TypedStringValue) o).getValue())) { return true; } } else { if (searchValue.equals(o)) { return true; } } } } } return false; // return orig.hasConfiguredPropertyValue(beanName, propertyName, searchValue); }
From source file:org.beangle.spring.bind.DefinitionBindRegistry.java
public DefinitionBindRegistry(BeanDefinitionRegistry registry) { for (String name : registry.getBeanDefinitionNames()) { BeanDefinition bd = registry.getBeanDefinition(name); if (bd.isAbstract()) continue; // find classname String className = bd.getBeanClassName(); if (null == className) { String parentName = bd.getParentName(); if (null == parentName) continue; else { BeanDefinition parentDef = registry.getBeanDefinition(parentName); className = parentDef.getBeanClassName(); }//from w w w . j av a 2 s .co m } if (null == className) continue; try { Class<?> beanClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader()); if (FactoryBean.class.isAssignableFrom(beanClass)) { register(beanClass, "&" + name); PropertyValue pv = bd.getPropertyValues().getPropertyValue("target"); if (null == pv) { Class<?> artifactClass = ((FactoryBean<?>) beanClass.newInstance()).getObjectType(); if (null != artifactClass) register(artifactClass, name); } else { if (pv.getValue() instanceof BeanDefinitionHolder) { String nestedClassName = ((BeanDefinitionHolder) pv.getValue()).getBeanDefinition() .getBeanClassName(); if (null != nestedClassName) { register(ClassUtils.forName(nestedClassName, ClassUtils.getDefaultClassLoader()), name); } } } } else { register(beanClass, name); } } catch (Exception e) { logger.error("class not found", e); continue; } } }
From source file:org.impalaframework.spring.ProxyCreatingBeanFactory.java
@Override public void preInstantiateSingletons() throws BeansException { if (logger.isInfoEnabled()) { logger.info("Pre-instantiating singletons in factory [" + this + "]"); }// w ww . j a va 2 s. com String[] beanNames = this.getBeanDefinitionNames(); for (int i = 0; i < beanNames.length; i++) { String beanName = beanNames[i]; if (!containsSingleton(beanName) && containsBeanDefinition(beanName)) { BeanDefinition bd = getMergedBeanDefinition(beanName); if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) { if (bd instanceof RootBeanDefinition) { RootBeanDefinition rootBeanDefinition = (RootBeanDefinition) bd; Class<?> beanClass = resolveBeanClass(rootBeanDefinition, beanName); if (beanClass != null && FactoryBean.class.isAssignableFrom(beanClass)) { getBean(FACTORY_BEAN_PREFIX + beanName); } else { getBean(beanName); } } else { log.warn("Unable to instantiate bean definition " + bd + " as this is not an instance of " + RootBeanDefinition.class.getName()); } } } } }