List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference getBeanName
@Override
public String getBeanName()
From source file:org.springmodules.cache.config.ConfigAssert.java
/** * Asserts that both <code>{@link RuntimeBeanReference}</code> have the same * target bean name.//ww w . j a v a 2 s. com * * @param message * message to be displayed if this assertion is <code>false</code> * @param expected * the runtime bean reference containing the expected target bean * name * @param actual * the runtime bean reference containing the actual target bean name */ public static void assertEqualBeanNames(String message, RuntimeBeanReference expected, RuntimeBeanReference actual) { Assert.assertEquals(message, expected.getBeanName(), actual.getBeanName()); }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
public static Object propertyValueToBeanName(Object value, BeanDefConverter converter) { Object beanspec = null;// ww w .j a va 2 s. c o m if (value instanceof BeanDefinitionHolder) { // Resolve BeanDefinitionHolder: contains BeanDefinition with name and // aliases. BeanDefinitionHolder bdHolder = (BeanDefinitionHolder) value; String beanname = bdHolder.getBeanName(); converter.convertBeanDef(bdHolder.getBeanDefinition(), beanname, true); beanspec = beanname; } else if (value instanceof BeanDefinition) { throw new IllegalArgumentException("No idea what to do with bean definition!"); } else if (value instanceof RuntimeBeanReference) { RuntimeBeanReference ref = (RuntimeBeanReference) value; beanspec = ref.getBeanName(); } else if (value instanceof ManagedList) { List valuelist = (List) value; StringList togo = new StringList(); for (int i = 0; i < valuelist.size(); ++i) { String thisbeanname = (String) propertyValueToBeanName(valuelist.get(i), converter); togo.add(thisbeanname); } beanspec = togo; } else if (value instanceof String) { beanspec = new ValueHolder((String) value); } else if (value instanceof TypedStringValue) { beanspec = new ValueHolder(((TypedStringValue) value).getValue()); } else { Logger.log.warn( "RSACBeanLocator Got value " + value + " of unknown type " + value.getClass() + ": ignoring"); } return beanspec; }
From source file:me.springframework.di.spring.SpringConfigurationLoader.java
/** * Constructs a {@link MutableSource} from a source based on a reference to * a bean defined somewhere else.//from w ww . j av a 2s . c om * * @param sink * The {@link Sink} configured to receive the value produced by * the source. * @param value * Spring's representation of the object producing the data to be * injected. * @return The {@link Source} representation of the object producing that * value. */ private static MutableSource load(Sink sink, RuntimeBeanReference value, MutableContext context) { String name = value.getBeanName(); return new MutableInstanceReference(sink, name); }
From source file:org.drools.container.spring.namespace.KnowledgeAgentDefinitionParser.java
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(KnowledgeAgentBeanFactory.class); String id = element.getAttribute("id"); emptyAttributeCheck(element.getLocalName(), "id", id); factory.addPropertyValue("id", id); String kbase = element.getAttribute("kbase"); if (StringUtils.hasText(kbase)) { factory.addPropertyReference("kbase", kbase); }/*from w ww .j a v a 2 s . c o m*/ String newInstance = element.getAttribute("new-instance"); if (StringUtils.hasText(newInstance)) { factory.addPropertyValue("newInstance", newInstance); } String useKbaseClassloader = element.getAttribute("use-kbase-classloader"); if (!useKbaseClassloader.trim().equals("")) { factory.addPropertyValue("useKbaseClassloader", useKbaseClassloader); } ManagedList resources = KnowledgeBaseDefinitionParser.getResources(element, parserContext, factory); if (resources != null) { factory.addPropertyValue("resources", resources); } // inject the kagent into any stateless sessions for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) { BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName); if (StatelessKnowledgeSessionBeanFactory.class.getName().equals(def.getBeanClassName())) { PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase"); RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue(); if (kbase.equals(tbf.getBeanName())) { def.getPropertyValues().addPropertyValue("knowledgeAgent", new RuntimeBeanReference(id)); } } } return factory.getBeanDefinition(); }
From source file:com.apporiented.spring.override.MapMergeProcessor.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { BeanDefinition bd = beanFactory.getBeanDefinition(ref); if (property == null) { Assert.state(MapFactoryBean.class.getName().equals(bd.getBeanClassName()), "Bean [" + ref + "] must be a MapFactoryBean"); property = "sourceMap"; }/*from w w w . ja v a2 s. c o m*/ if (log.isInfoEnabled()) { String keys = StringUtils.collectionToCommaDelimitedString(entries.keySet()); log.debug("Adding [" + keys + "] to " + ref + "." + property); } PropertyValue pv = bd.getPropertyValues().getPropertyValue(property); if (pv == null) { // No map set on the target bean, create a new one ... ManagedMap map = new ManagedMap(); map.putAll(entries); bd.getPropertyValues().addPropertyValue(property, map); } else { Object value = pv.getValue(); if (value instanceof RuntimeBeanReference) { RuntimeBeanReference ref = (RuntimeBeanReference) value; value = beanFactory.getBean(ref.getBeanName()); } Assert.isInstanceOf(Map.class, value); Map map = (Map) value; map.putAll(entries); } }
From source file:org.bytesoft.bytetcc.supports.spring.TransactionConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 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(); if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName() .equals(beanClassName)) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName));/*from www . ja v a2s. c om*/ } if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName() .equals(beanClassName)) { boolean errorExists = true; MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource"); Object value = pv == null ? null : pv.getValue(); if (value != null && RuntimeBeanReference.class.isInstance(value)) { RuntimeBeanReference reference = (RuntimeBeanReference) value; BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName()); String refBeanClassName = refBeanDef.getBeanClassName(); errorExists = AnnotationTransactionAttributeSource.class.getName() .equals(refBeanClassName) == false; } if (errorExists) { throw new FatalBeanException(String.format( "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).", beanName)); } } } }
From source file:com.apporiented.spring.override.ListMergeProcessor.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { BeanDefinition bd = beanFactory.getBeanDefinition(ref); if (property == null) { //Assert.state(ListFactoryBean.class.getName().equals(bd.getBeanClassName()), // "Bean [" + ref + "] must be a ListFactoryBean"); property = "sourceList"; }//from w w w .j ava2 s. co m log.debug("Adding " + values.size() + " items to " + ref + "." + property + ": " + values); PropertyValue pv = bd.getPropertyValues().getPropertyValue(property); if (pv == null) { // No list set on the target bean, create a new one ... ManagedList list = new ManagedList(); list.addAll(values); bd.getPropertyValues().addPropertyValue(property, list); } else { Object value = pv.getValue(); if (value instanceof RuntimeBeanReference) { RuntimeBeanReference ref = (RuntimeBeanReference) value; value = beanFactory.getBean(ref.getBeanName()); } else if (value instanceof TypedStringValue) { TypedStringValue tsv = (TypedStringValue) value; ManagedList list = new ManagedList(); list.addAll(values); list.add(tsv.getValue()); bd.getPropertyValues().addPropertyValue(property, list); return; } Assert.isInstanceOf(List.class, value); List list = (List) value; if (append) { list.addAll(values); } else { for (int i = values.size() - 1; i >= 0; i--) { list.add(0, values.get(i)); } } } }
From source file:org.springmodules.cache.config.BeanReferenceParserImplTests.java
private void assertIsRuntimeBeanReference(Object actual, String refId) { AssertExt.assertInstanceOf(RuntimeBeanReference.class, actual); RuntimeBeanReference actualReference = (RuntimeBeanReference) actual; assertEquals("<ref id>", refId, actualReference.getBeanName()); }
From source file:org.bytesoft.bytetcc.supports.dubbo.CompensableDubboConfigValidator.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); final Map<String, Class<?>> beanClassMap = new HashMap<String, Class<?>>(); final Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>(); final Map<String, BeanDefinition> references = new HashMap<String, 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 {/* w w w . j a v a 2 s .co m*/ beanClass = cl.loadClass(beanClassName); beanClassMap.put(beanName, beanClass); } catch (Exception ex) { continue; } if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) { serviceMap.put(beanName, beanDef); } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) { references.put(beanName, beanDef); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue ref = mpv.getPropertyValue("ref"); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (ref == null || ref.getValue() == null || RuntimeBeanReference.class.equals(ref.getValue().getClass()) == false) { continue; } RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue(); Class<?> refClass = beanClassMap.get(beanRef.getBeanName()); if (refClass.getAnnotation(Compensable.class) == null) { continue; } if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException(String.format("Timeout value(beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = references.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException( String.format("The value of attribute 'timeout' (beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } }
From source file:org.springmodules.cache.config.CacheManagerAndProviderFacadeParserTests.java
/** * Asserts that the cache provider facade definition has a reference to the * definition of a cache manager factory. *//* w w w. jav a2s . com*/ private void assertCacheProviderFacadeHasCacheManagerAsProperty() { PropertyValue cacheManagerProperty = cacheProviderFacade.getPropertyValues() .getPropertyValue("cacheManager"); RuntimeBeanReference cacheManager = (RuntimeBeanReference) cacheManagerProperty.getValue(); assertEquals(BeanName.CACHE_MANAGER, cacheManager.getBeanName()); }