List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference
public RuntimeBeanReference(Class<?> beanType)
From source file:com.github.spring.mvc.util.handler.config.UriMatchingAnnotationDrivenBeanDefinitionParser.java
/** * Create {@link PointcutAdvisor} that puts the {@link Pointcut} and {@link MethodInterceptor} together. * @return Reference to the {@link PointcutAdvisor}. Should never be null. *//*from w ww . j a v a2s .c o m*/ protected RuntimeBeanReference setupPointcutAdvisor(Element element, ParserContext parserContext, Object elementSource, RuntimeBeanReference pointcutReference, RuntimeBeanReference interceptorReference) { final RootBeanDefinition pointcutAdvisor = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); pointcutAdvisor.setSource(elementSource); pointcutAdvisor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final MutablePropertyValues propertyValues = pointcutAdvisor.getPropertyValues(); propertyValues.addPropertyValue("adviceBeanName", interceptorReference.getBeanName()); propertyValues.addPropertyValue("pointcut", pointcutReference); if (element.hasAttribute("order")) { propertyValues.addPropertyValue("order", element.getAttribute("order")); } final BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(CACHING_ADVISOR_BEAN_NAME, pointcutAdvisor); return new RuntimeBeanReference(CACHING_ADVISOR_BEAN_NAME); }
From source file:org.devefx.httpmapper.spring.mapper.ClassPathMapperScanner.java
private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) { ScannedGenericBeanDefinition definition; for (BeanDefinitionHolder holder : beanDefinitions) { definition = (ScannedGenericBeanDefinition) holder.getBeanDefinition(); if (logger.isDebugEnabled()) { logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName() + "' mapperInterface"); }//from w w w.ja v a 2s . c om // the mapper interface is the original class of the bean // but, the actual class of the bean is MapperFactoryBean definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); definition.setBeanClass(this.factoryBeanClass); boolean explicitFactoryUsed = false; if (StringUtils.hasText(this.configBeanName)) { definition.getPropertyValues().add("config", new RuntimeBeanReference(this.configBeanName)); explicitFactoryUsed = true; } if (!explicitFactoryUsed) { if (logger.isDebugEnabled()) { logger.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'."); } definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } } }
From source file:net.scriptability.core.integration.spring.ScriptAbilityBeanDefinitionParser.java
private Map<String, RuntimeBeanReference> createBeanBindings(final Element bindingsElement) { Map<String, RuntimeBeanReference> beanBindings = new ManagedMap<>(); NodeList bindingNodeList = bindingsElement.getElementsByTagNameNS(XML_NAMESPACE__SCRIPTABILITY, XML_ELEMENT__BINDING);/*from www . j av a 2s .co m*/ for (int i = 0; i < bindingNodeList.getLength(); i++) { Element binding = (Element) bindingNodeList.item(i); beanBindings.put(binding.getAttribute(XML_ATTRIBUTE__NAME), new RuntimeBeanReference(binding.getAttribute(XML_ATTRIBUTE__BEAN_REF))); } return beanBindings; }
From source file:org.bigtester.ate.xmlschema.RunTimeDataHolderBeanDefinitionParser.java
/** * {@inheritDoc}/*www . j a v a 2 s . co m*/ */ @Override protected @Nullable AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext) { // Here we parse the Spring elements such as < property> if (parserContext == null || element == null) throw GlobalUtils.createNotInitializedException("element and parserContext"); // Here we parse the Spring elements such as < property> String dataHolderType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAHOLDERTYPE) .toUpperCase(); if (null == dataHolderType || !StringUtils.hasText(dataHolderType)) { throw GlobalUtils.createNotInitializedException("dataHolderType attribute in xml test case"); } RumtimeDataHolderType enumDataHolderType = RumtimeDataHolderType.valueOf(dataHolderType); BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element); BeanDefinition bDef = holder.getBeanDefinition(); switch (enumDataHolderType) { case PAGESOURCEPARSED: bDef.setBeanClassName(PageParsedDataHolder.class.getName()); break; case MANUALASSIGNED: bDef.setBeanClassName(ManualAssignedValueDataHolder.class.getName()); break; case CASESERVICEPARSED: bDef.setBeanClassName(CaseServiceParsedDataHolder.class.getName()); break; case STEPSERVICEPARSED: bDef.setBeanClassName(StepServiceParsedDataHolder.class.getName()); break; case RANDOMALPHATEXT: bDef.setBeanClassName(RandomAlphaTextValueDataHolder.class.getName()); break; case RANDOMNUMBERS: bDef.setBeanClassName(RandomNumericValueDataHolder.class.getName()); break; case RANDOMTEXTNUMBERS: bDef.setBeanClassName(RandomAlphaNumericValueDataHolder.class.getName()); break; case RANDOMEMAIL: bDef.setBeanClassName(RandomEmailDataHolder.class.getName()); break; default: break; } String dataType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATATYPE).toUpperCase(); if (null != dataType && StringUtils.hasText(dataType)) { EnumRunTimeDataType enumDataType = EnumRunTimeDataType.valueOf(dataType); bDef.getConstructorArgumentValues().addGenericArgumentValue(enumDataType); } String dataValue = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAVALUE); if (StringUtils.hasText(dataValue)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(dataValue); } String leftBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_LEFTBOUNDRY); if (StringUtils.hasText(leftBoundry)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(leftBoundry); } String rightBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RIGHTBOUNDRY); if (StringUtils.hasText(rightBoundry)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(rightBoundry); } String page = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_PAGE); if (StringUtils.hasText(page)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(page)); } String beanID = element.getAttribute("id"); bDef.getConstructorArgumentValues().addGenericArgumentValue(beanID); String mappedBeanID = element .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_SUBCASEMAPPEDDATAHOLDERID); if (StringUtils.hasText(mappedBeanID)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(mappedBeanID); } String indexOfSameTypeDataOnPage = element .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_INDEXOFSAMETYPEDATAONPAGE); if (StringUtils.hasText(indexOfSameTypeDataOnPage)) { int index = Integer.parseInt(indexOfSameTypeDataOnPage); bDef.getConstructorArgumentValues().addGenericArgumentValue(index); } String randomTextLength = element .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RANDOMINPUTLENGTH); if (StringUtils.hasText(randomTextLength)) { int length = Integer.parseInt(randomTextLength); bDef.getConstructorArgumentValues().addGenericArgumentValue(length); } parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef); return (AbstractBeanDefinition) bDef; }
From source file:org.mybatis.spring.annotation.EnableMapperScanningTest.java
@Test public void testScanWithExplicitSqlSessionTemplate() throws Exception { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory")); definition.setConstructorArgumentValues(constructorArgs); applicationContext.registerBeanDefinition("sqlSessionTemplate", definition); applicationContext.register(AppConfigWithSqlSessionTemplate.class); startContext();//from w w w. j a v a 2 s.c o m // all interfaces with methods should be loaded applicationContext.getBean("mapperInterface"); applicationContext.getBean("mapperSubinterface"); applicationContext.getBean("mapperChildInterface"); applicationContext.getBean("annotatedMapper"); }
From source file:org.springmodules.cache.config.AbstractMetadataAttributesParser.java
private void registerFlushingAdvisor(BeanDefinitionRegistry registry) { Class flushingAdvisorClass = FlushingAttributeSourceAdvisor.class; RootBeanDefinition flushingAdvisor = new RootBeanDefinition(flushingAdvisorClass); flushingAdvisor.getConstructorArgumentValues() .addGenericArgumentValue(new RuntimeBeanReference(BeanName.FLUSHING_INTERCEPTOR)); registry.registerBeanDefinition(flushingAdvisorClass.getName(), flushingAdvisor); }
From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static BeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass, boolean required) throws ClassNotFoundException { RootBeanDefinition bd = new RootBeanDefinition(); bd.setBeanClass(beanClass);/*from www . ja v a 2 s.com*/ // ??lazy init bd.setLazyInit(false); // id?id,idcontext String id = element.getAttribute("id"); if ((id == null || id.length() == 0) && required) { String generatedBeanName = element.getAttribute("name"); if (generatedBeanName == null || generatedBeanName.length() == 0) { generatedBeanName = element.getAttribute("class"); } if (generatedBeanName == null || generatedBeanName.length() == 0) { generatedBeanName = beanClass.getName(); } id = generatedBeanName; int counter = 2; while (parserContext.getRegistry().containsBeanDefinition(id)) { id = generatedBeanName + (counter++); } } if (id != null && id.length() > 0) { if (parserContext.getRegistry().containsBeanDefinition(id)) { throw new IllegalStateException("Duplicate spring bean id " + id); } parserContext.getRegistry().registerBeanDefinition(id, bd); } bd.getPropertyValues().addPropertyValue("id", id); if (ProtocolConfig.class.equals(beanClass)) { MotanNamespaceHandler.protocolDefineNames.add(id); } else if (RegistryConfig.class.equals(beanClass)) { MotanNamespaceHandler.registryDefineNames.add(id); } else if (BasicServiceInterfaceConfig.class.equals(beanClass)) { MotanNamespaceHandler.basicServiceConfigDefineNames.add(id); } else if (BasicRefererInterfaceConfig.class.equals(beanClass)) { MotanNamespaceHandler.basicRefererConfigDefineNames.add(id); } else if (ServiceConfigBean.class.equals(beanClass)) { String className = element.getAttribute("class"); if (className != null && className.length() > 0) { RootBeanDefinition classDefinition = new RootBeanDefinition(); classDefinition.setBeanClass( Class.forName(className, true, Thread.currentThread().getContextClassLoader())); classDefinition.setLazyInit(false); parseProperties(element.getChildNodes(), classDefinition); bd.getPropertyValues().addPropertyValue("ref", new BeanDefinitionHolder(classDefinition, id + "Impl")); } } Set<String> props = new HashSet<String>(); ManagedMap parameters = null; // ??setbd for (Method setter : beanClass.getMethods()) { String name = setter.getName(); // setXXX if (name.length() <= 3 || !name.startsWith("set") || !Modifier.isPublic(setter.getModifiers()) || setter.getParameterTypes().length != 1) { continue; } String property = (name.substring(3, 4).toLowerCase() + name.substring(4)).replaceAll("_", "-"); props.add(property); if ("id".equals(property)) { bd.getPropertyValues().addPropertyValue("id", id); continue; } String value = element.getAttribute(property); if ("methods".equals(property)) { parseMethods(id, element.getChildNodes(), bd, parserContext); } if (StringUtils.isBlank(value)) { continue; } value = value.trim(); if (value.length() == 0) { continue; } Object reference; if ("ref".equals(property)) { if (parserContext.getRegistry().containsBeanDefinition(value)) { BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value); if (!refBean.isSingleton()) { throw new IllegalStateException( "The exported service ref " + value + " must be singleton! Please set the " + value + " bean scope to singleton, eg: <bean id=\"" + value + "\" scope=\"singleton\" ...>"); } } reference = new RuntimeBeanReference(value); } else if ("protocol".equals(property) && !StringUtils.isBlank(value)) { if (!value.contains(",")) { reference = new RuntimeBeanReference(value); } else { parseMultiRef("protocols", value, bd, parserContext); reference = null; } } else if ("registry".equals(property)) { parseMultiRef("registries", value, bd, parserContext); reference = null; } else if ("basicService".equals(property)) { reference = new RuntimeBeanReference(value); } else if ("basicReferer".equals(property)) { reference = new RuntimeBeanReference(value); } else if ("extConfig".equals(property)) { reference = new RuntimeBeanReference(value); } else { reference = new TypedStringValue(value); } if (reference != null) { bd.getPropertyValues().addPropertyValue(property, reference); } } if (ProtocolConfig.class.equals(beanClass)) { // protocolparameters? NamedNodeMap attributes = element.getAttributes(); int len = attributes.getLength(); for (int i = 0; i < len; i++) { Node node = attributes.item(i); String name = node.getLocalName(); if (!props.contains(name)) { if (parameters == null) { parameters = new ManagedMap(); } String value = node.getNodeValue(); parameters.put(name, new TypedStringValue(value, String.class)); } } bd.getPropertyValues().addPropertyValue("parameters", parameters); } return bd; }
From source file:org.atomserver.utils.test.TestingAtomServer.java
/** * add a new workspace to the testing server with the given name and localization flag. * * @param name the name of the workspace * @param localized true iff the workspace is localized * @return a TestWorkspaceConfigurer to further configure the workspace *///from w ww . j a va 2 s . co m public TestWorkspaceConfigurer addWorkspace(String name, boolean localized) { // create a bean definition for the workspace and add it to the managed set. final RootBeanDefinition workspace = new RootBeanDefinition(WorkspaceOptions.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("name", name); propertyValues.addPropertyValue("defaultLocalized", localized); propertyValues.addPropertyValue("defaultProducingEntryCategoriesFeedElement", true); propertyValues.addPropertyValue("defaultContentStorage", new RuntimeBeanReference("org.atomserver-contentStorage")); propertyValues.addPropertyValue("defaultContentValidator", new RuntimeBeanReference("org.atomserver-simpleXMLContentValidator")); propertyValues.addPropertyValue("defaultCategoriesHandler", new RuntimeBeanReference("org.atomserver-entryCategoriesHandler")); propertyValues.addPropertyValue("defaultEntryIdGenerator", new RuntimeBeanReference("org.atomserver-entryIdGenerator")); workspace.setPropertyValues(propertyValues); workspaceSet.add(workspace); return new TestWorkspaceConfigurer() { // if given a RNC location, we spin up a RelaxNGValidator to validate with it public TestWorkspaceConfigurer setRncLocation(String rncLocation) { RootBeanDefinition autotagger = new RootBeanDefinition(RelaxNGValidator.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("schemaLocation", rncLocation); autotagger.setPropertyValues(propertyValues); workspace.getPropertyValues().addPropertyValue("defaultContentValidator", autotagger); return this; } // if given an XPathAutoTagger script, set up a tagger to use it public TestWorkspaceConfigurer setXPathAutotaggerRules(String rules) { RootBeanDefinition autotagger = new RootBeanDefinition(XPathAutoTagger.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("categoriesHandler", new RuntimeBeanReference("org.atomserver-entryCategoriesHandler")); propertyValues.addPropertyValue("script", rules); autotagger.setPropertyValues(propertyValues); workspace.getPropertyValues().addPropertyValue("defaultAutoTagger", autotagger); return this; } // allow for arbitrary property setting on the workspace bean -- requires knowledge // of the Spring bean factory APIs public TestWorkspaceConfigurer addPropertyValue(String name, Object value) { workspace.getPropertyValues().addPropertyValue(name, value); return this; } }; }
From source file:org.springmodules.cache.config.CacheSetupStrategyParserTests.java
public void testParse() { int listenerCount = 5; int modelCount = 2; elementBuilder.setDefaultCachingListenerElementBuilders(listenerCount); // expectations for cache key generator. RuntimeBeanReference cacheKeyGenerator = expectCacheKeyGeneratorParsing(); // expectations for parsing caching listeners. List cachingListeners = new ArrayList(); for (int i = 0; i < listenerCount; i++) { String refId = elementBuilder.cachingListenerElementBuilders[i].refId; registry.registerBeanDefinition(refId, new RootBeanDefinition(CachingListener.class)); Element cachingListenerElement = elementBuilder.cachingListenerElementBuilders[i].toXml(); // parse caching listener element beanReferenceParser.parse(cachingListenerElement, parserContext, true); RuntimeBeanReference cachingListenerReference = new RuntimeBeanReference(refId); beanReferenceParserControl.setReturnValue(cachingListenerReference); // validate the caching listener validator.validate(cachingListenerReference, i, parserContext); cachingListeners.add(cachingListenerReference); }// w w w . j a v a2 s.c o m registerCacheProviderFacadeDefinition(); // expectations for parsing cache models. elementBuilder.setDefaultCachingModelElementBuilders(modelCount); elementBuilder.setDefaultFlushingModelElementBuilders(modelCount); Map cachingModelMap = expectCachingModelParsing(); Map flushingModelMap = expectFlushingModelParsing(); Element element = elementBuilder.toXml(); CacheSetupStrategyPropertySource propertySource = new CacheSetupStrategyPropertySource(cacheKeyGenerator, new RuntimeBeanReference(elementBuilder.cacheProviderId), cachingListeners, cachingModelMap, flushingModelMap); strategyParser.parseCacheSetupStrategy(element, parserContext, propertySource); strategyParserControl.setMatcher(new CacheSetupStrategyPropertySourceMatcher()); replay(); // method to test strategyParser.parse(element, parserContext); verify(); }