List of usage examples for org.springframework.beans.factory.config BeanDefinition getAttribute
@Nullable Object getAttribute(String name);
From source file:org.springframework.boot.autoconfigure.ComponentScanDetector.java
private void storeComponentScanBasePackages(ConfigurableListableBeanFactory beanFactory) { List<String> basePackages = new ArrayList<String>(); for (String beanName : beanFactory.getBeanDefinitionNames()) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); String[] basePackagesAttribute = (String[]) beanDefinition.getAttribute("componentScanBasePackages"); if (basePackagesAttribute != null) { basePackages.addAll(Arrays.asList(basePackagesAttribute)); }//from w w w . j a v a2 s. co m AnnotationMetadata metadata = getMetadata(beanDefinition); basePackages.addAll(getBasePackages(metadata)); } AutoConfigurationUtils.storeBasePackages(beanFactory, basePackages); }
From source file:org.springframework.integration.config.xml.ChainParser.java
@Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException { String id = super.resolveId(element, definition, parserContext); BeanDefinition containingBeanDefinition = parserContext.getContainingBeanDefinition(); if (containingBeanDefinition != null) { String nestedChainIdPrefix = (String) containingBeanDefinition .getAttribute(SI_CHAIN_NESTED_ID_ATTRIBUTE); if (StringUtils.hasText(nestedChainIdPrefix)) { id = nestedChainIdPrefix + "$child." + id; }//from ww w.jav a 2 s.c o m } definition.setAttribute(SI_CHAIN_NESTED_ID_ATTRIBUTE, id); return id; }
From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java
@Override public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) { // We only apply special treatment to ScriptFactory implementations here. if (!ScriptFactory.class.isAssignableFrom(beanClass)) { return null; }//from w w w.ja va2 s . co m Assert.state(this.beanFactory != null, "No BeanFactory set"); BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName); String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName; String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName; prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName); ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class); ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator()); boolean isFactoryBean = false; try { Class<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource); // Returned type may be null if the factory is unable to determine the type. if (scriptedObjectType != null) { isFactoryBean = FactoryBean.class.isAssignableFrom(scriptedObjectType); } } catch (Exception ex) { throw new BeanCreationException(beanName, "Could not determine scripted object type for " + scriptFactory, ex); } long refreshCheckDelay = resolveRefreshCheckDelay(bd); if (refreshCheckDelay >= 0) { Class<?>[] interfaces = scriptFactory.getScriptInterfaces(); RefreshableScriptTargetSource ts = new RefreshableScriptTargetSource(this.scriptBeanFactory, scriptedObjectBeanName, scriptFactory, scriptSource, isFactoryBean); boolean proxyTargetClass = resolveProxyTargetClass(bd); String language = (String) bd.getAttribute(LANGUAGE_ATTRIBUTE); if (proxyTargetClass && (language == null || !language.equals("groovy"))) { throw new BeanDefinitionValidationException( "Cannot use proxyTargetClass=true with script beans where language is not 'groovy': '" + language + "'"); } ts.setRefreshCheckDelay(refreshCheckDelay); return createRefreshableProxy(ts, interfaces, proxyTargetClass); } if (isFactoryBean) { scriptedObjectBeanName = BeanFactory.FACTORY_BEAN_PREFIX + scriptedObjectBeanName; } return this.scriptBeanFactory.getBean(scriptedObjectBeanName); }
From source file:org.statefulj.framework.core.StatefulFactory.java
/** * @param entityToRepositoryMapping//from w w w . j av a2s. co m * @param bfName * @param bf * @throws ClassNotFoundException */ private void mapEntityToRepository(Map<Class<?>, String> entityToRepositoryMapping, String bfName, BeanDefinition bf) throws ClassNotFoundException { // Determine the Entity Class associated with the Repo // String value = (String) bf.getAttribute("factoryBeanObjectType"); Class<?> repoInterface = Class.forName(value); Class<?> entityType = null; for (Type type : repoInterface.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parmType = (ParameterizedType) type; if (Repository.class.isAssignableFrom((Class<?>) parmType.getRawType()) && parmType.getActualTypeArguments() != null && parmType.getActualTypeArguments().length > 0) { entityType = (Class<?>) parmType.getActualTypeArguments()[0]; break; } } } if (entityType == null) { throw new RuntimeException("Unable to determine Entity type for class " + repoInterface.getName()); } // Map Entity to the RepositoryFactoryBeanSupport bean // logger.debug("Mapped \"{}\" to repo \"{}\", beanId=\"{}\"", entityType.getName(), value, bfName); entityToRepositoryMapping.put(entityType, bfName); }