List of usage examples for org.springframework.beans.factory.config BeanDefinition getFactoryMethodName
@Nullable String getFactoryMethodName();
From source file:org.echocat.jomon.spring.BeanFactoryUtils.java
@Nullable public static Class<?> findTypeOfBeanDefinition(@Nonnull ConfigurableListableBeanFactory beanFactory, @Nonnull String beanName) { Class<?> type;//from w w w . j av a 2 s . co m final BeanDefinition definition = beanFactory.getBeanDefinition(beanName); if (definition != null && definition.getFactoryMethodName() == null) { final String beanClassName = definition.getBeanClassName(); if (beanClassName != null) { try { type = AutomaticServicesDiscovery.class.getClassLoader().loadClass(beanClassName); } catch (final ClassNotFoundException ignored) { type = null; } } else { type = null; } } else { type = null; } return type == null || FactoryBean.class.isAssignableFrom(type) ? null : type; }
From source file:me.springframework.di.spring.SpringConfigurationLoader.java
/** * Loads a {@link MutableInstance} from one of the {@link BeanDefinition}s * provided by the {@link BeanDefinitionRegistry} passed in. * /*from ww w . j a v a 2s .c o m*/ * @param instance * A {@link MutableInstance} to be populated. * @param definition * A {@link BeanDefinition}, providing the meta data. */ private static void load(MutableInstance instance, BeanDefinition definition, MutableContext context) { instance.setReferencedType(definition.getBeanClassName()); instance.setPrimitive(false); instance.setLazyInit(definition.isLazyInit()); instance.setId("source" + counter++); instance.setFactoryMethod(definition.getFactoryMethodName()); instance.setFactoryInstance(definition.getFactoryBeanName()); if (ConfigurableBeanFactory.SCOPE_SINGLETON.equals(definition.getScope())) { instance.setScope(Scope.SINGLETON); } if (ConfigurableBeanFactory.SCOPE_PROTOTYPE.equals(definition.getScope())) { instance.setScope(Scope.PROTOTYPE); } if (definition instanceof AbstractBeanDefinition) { instance.setInitMethod(((AbstractBeanDefinition) definition).getInitMethodName()); instance.setDestroyMethod(((AbstractBeanDefinition) definition).getDestroyMethodName()); } if (!definition.getConstructorArgumentValues().isEmpty()) { List<MutableConstructorArgument> arguments = new ArrayList<MutableConstructorArgument>(); for (Object object : definition.getConstructorArgumentValues().getGenericArgumentValues()) { MutableConstructorArgument argument = new MutableConstructorArgument(instance); argument.setInstance(instance); ValueHolder holder = (ValueHolder) object; argument.setSource(loadSource(context, argument, holder.getValue())); argument.setType(holder.getType()); arguments.add(argument); } instance.setConstructorArguments(arguments); } Set<MutablePropertySetter> setters = new HashSet<MutablePropertySetter>(); for (Object object : definition.getPropertyValues().getPropertyValueList()) { MutablePropertySetter setter = new MutablePropertySetter(instance); setter.setInstance(instance); PropertyValue value = (PropertyValue) object; setter.setName(value.getName()); setter.setSource(loadSource(context, setter, value.getValue())); setters.add(setter); } instance.setSetters(setters); // added by woj instance.setAutowireCandidate(definition.isAutowireCandidate()); if (definition instanceof AbstractBeanDefinition) { instance.setAutowireMode(((AbstractBeanDefinition) definition).getResolvedAutowireMode()); } else { instance.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_NO); } }
From source file:com.tacitknowledge.flip.spring.config.FeatureServiceHandlerParserTest.java
@Test public void testCreateFeatureServiceBean() { assertNotNull(context.containsBeanDefinition("featureService")); BeanDefinition beanDefinition = context.getBeanDefinition("featureService"); assertEquals("featureServiceFactory", beanDefinition.getFactoryBeanName()); assertEquals("createFeatureService", beanDefinition.getFactoryMethodName()); FeatureService featureService = context.getBean("featureService", FeatureService.class); assertNotNull(featureService);/* w ww . jav a 2 s . c om*/ }
From source file:lodsve.core.condition.BeanTypeRegistry.java
private Class<?> doGetFactoryBeanGeneric(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition, String name) throws Exception, ClassNotFoundException, LinkageError { if (StringUtils.hasLength(definition.getFactoryBeanName()) && StringUtils.hasLength(definition.getFactoryMethodName())) { return getConfigurationClassFactoryBeanGeneric(beanFactory, definition, name); }/*from w w w . j a v a 2 s .c o m*/ if (StringUtils.hasLength(definition.getBeanClassName())) { return getDirectFactoryBeanGeneric(beanFactory, definition, name); } return null; }
From source file:lodsve.core.condition.BeanTypeRegistry.java
private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition) throws Exception { if (definition instanceof AnnotatedBeanDefinition) { MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition) .getFactoryMethodMetadata(); if (factoryMethodMetadata instanceof StandardMethodMetadata) { return ((StandardMethodMetadata) factoryMethodMetadata).getIntrospectedMethod(); }/*w ww. j a v a 2s . c o m*/ } BeanDefinition factoryDefinition = beanFactory.getBeanDefinition(definition.getFactoryBeanName()); Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(), beanFactory.getBeanClassLoader()); return ReflectionUtils.findMethod(factoryClass, definition.getFactoryMethodName()); }
From source file:org.springframework.context.annotation.ConfigurationClassUtils.java
/** * Check whether the given bean definition is a candidate for a configuration class * (or a nested component class declared within a configuration/component class, * to be auto-registered as well), and mark it accordingly. * @param beanDef the bean definition to check * @param metadataReaderFactory the current factory in use by the caller * @return whether the candidate qualifies as (any kind of) configuration class *///from w ww . j a v a 2 s . c o m public static boolean checkConfigurationClassCandidate(BeanDefinition beanDef, MetadataReaderFactory metadataReaderFactory) { String className = beanDef.getBeanClassName(); if (className == null || beanDef.getFactoryMethodName() != null) { return false; } AnnotationMetadata metadata; if (beanDef instanceof AnnotatedBeanDefinition && className.equals(((AnnotatedBeanDefinition) beanDef).getMetadata().getClassName())) { // Can reuse the pre-parsed metadata from the given BeanDefinition... metadata = ((AnnotatedBeanDefinition) beanDef).getMetadata(); } else if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) { // Check already loaded Class if present... // since we possibly can't even load the class file for this Class. Class<?> beanClass = ((AbstractBeanDefinition) beanDef).getBeanClass(); metadata = new StandardAnnotationMetadata(beanClass, true); } else { try { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(className); metadata = metadataReader.getAnnotationMetadata(); } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug( "Could not find class file for introspecting configuration annotations: " + className, ex); } return false; } } if (isFullConfigurationCandidate(metadata)) { beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL); } else if (isLiteConfigurationCandidate(metadata)) { beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE); } else { return false; } // It's a full or lite configuration candidate... Let's determine the order value, if any. Integer order = getOrder(metadata); if (order != null) { beanDef.setAttribute(ORDER_ATTRIBUTE, order); } return true; }
From source file:org.statefulj.framework.core.StatefulFactory.java
/** * @param bf// w w w .j a v a 2s . c om * @param reg * @param clazz * @return * @throws ClassNotFoundException */ private Class<?> getClassFromFactoryMethod(BeanDefinition bf, BeanDefinitionRegistry reg) throws ClassNotFoundException { Class<?> clazz = null; String factoryBeanName = bf.getFactoryBeanName(); if (factoryBeanName != null) { BeanDefinition factory = reg.getBeanDefinition(factoryBeanName); if (factory != null) { String factoryClassName = factory.getBeanClassName(); Class<?> factoryClass = Class.forName(factoryClassName); List<Method> methods = new LinkedList<Method>(); methods.addAll(Arrays.asList(factoryClass.getMethods())); methods.addAll(Arrays.asList(factoryClass.getDeclaredMethods())); for (Method method : methods) { method.setAccessible(true); if (method.getName().equals(bf.getFactoryMethodName())) { clazz = method.getReturnType(); break; } } } } return clazz; }