List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference
public RuntimeBeanReference(Class<?> beanType)
From source file:org.opencredo.couchdb.config.CouchDbInboundChannelAdapterParser.java
@Override protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = null; String databaseUrl = element.getAttribute(COUCHDB_DATABASE_URL_ATTRIBUTE); String changesOperations = element.getAttribute(COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE); String allDocuments = element.getAttribute(COUCHDB_ALL_DOCUMENTS_ATTRIBUTE); String allDocumentsLimit = element.getAttribute(COUCHDB_ALL_DOCUMENTS_LIMIT_ATTRIBUTE); if (StringUtils.hasText(databaseUrl)) { if (StringUtils.hasText(changesOperations)) { parserContext.getReaderContext().error("At most one of '" + COUCHDB_DATABASE_URL_ATTRIBUTE + "' and '" + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' may be provided.", element); } else {/*from ww w.j a v a2 s .com*/ if ("true".equals(allDocuments)) { builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbAllDocumentsMessageSource.class); } else { builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbChangesPollingMessageSource.class); } builder.addConstructorArgValue(databaseUrl); } } else if (StringUtils.hasText(changesOperations)) { // changesOperations and allDocuments are XOR if ("true".equals(allDocuments)) { parserContext.getReaderContext().error("At most one of '" + COUCHDB_ALL_DOCUMENTS_ATTRIBUTE + "' and '" + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' may be provided.", element); } else { builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbChangesPollingMessageSource.class); builder.addConstructorArgReference(changesOperations); } } else { parserContext.getReaderContext().error("Either '" + COUCHDB_DATABASE_URL_ATTRIBUTE + "' or '" + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' must be provided.", element); } if ("true".equals(allDocuments)) { builder.addConstructorArgValue(Integer.valueOf(allDocumentsLimit)); } String beanName = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry()); return new RuntimeBeanReference(beanName); }
From source file:org.jdal.beans.ServiceBeanDefinitionParser.java
/** * {@inheritDoc}//from ww w .ja va 2 s .com */ public AbstractBeanDefinition parse(Element element, ParserContext parserContext) { // default dao and service classes String daoClassName = JPA_DAO_CLASS_NAME; String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME; String name = null; boolean declareService = false; if (element.hasAttribute(DAO_CLASS)) daoClassName = element.getAttribute(DAO_CLASS); if (element.hasAttribute(SERVICE_CLASS)) { serviceClassName = element.getAttribute(SERVICE_CLASS); declareService = true; } if (element.hasAttribute(NAME)) name = element.getAttribute(NAME); if (element.hasAttribute(ENTITY)) { String className = element.getAttribute(ENTITY); if (name == null) { name = StringUtils .uncapitalize(StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR)); } parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Dao BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA); if (nl.getLength() > 0) { ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER))); } daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders); } daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null)); daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String daoBeanName; if (declareService) { // use dao suffix daoBeanName = name + DAO_SUFFIX; registerBeanDefinition(parserContext, daoBuilder, daoBeanName); // register service wrapper String serviceBeanName = name + SERVICE_SUFFIX; BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder .genericBeanDefinition(serviceClassName); serviceBuilder.addPropertyReference("dao", daoBeanName); registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); } else { // use service suffix for dao and declare an alias with dao suffix for compatibility with older api. daoBeanName = name + SERVICE_SUFFIX; String[] aliases = new String[] { name + DAO_SUFFIX }; BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), daoBeanName, aliases); parserContext.registerBeanComponent(bcd); } parserContext.popAndRegisterContainingComponent(); } return null; }
From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java
/** * Parse the supplied {@link org.w3c.dom.Element} and populate the supplied * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and/*from w w w. j a v a 2 s . c o m*/ * {@link org.springframework.beans.factory.support.BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param parserContext the object encapsulating the current state of the parsing process * @param builder used to define the <code>BeanDefinition</code> * @see #extractPropertyName(String) */ protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); String name = attribute.getLocalName(); if (isEligibleAttribute(name, parserContext)) { String propertyName = extractPropertyName(name); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); Object value; if (references.contains(propertyName)) { value = new RuntimeBeanReference(attribute.getValue()); } else { value = attribute.getValue(); } builder.addPropertyValue(propertyName, value); } } postProcess(builder, parserContext, element); }
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Test public void testNameGenerator() { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(BeanNameGenerator.class); applicationContext.registerBeanDefinition("beanNameGenerator", definition); applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add("nameGenerator", new RuntimeBeanReference("beanNameGenerator")); startContext();/*from w w w.j a va 2 s.c om*/ // only child inferfaces should be loaded and named with its class name applicationContext.getBean(MapperInterface.class.getName()); applicationContext.getBean(MapperSubinterface.class.getName()); applicationContext.getBean(MapperChildInterface.class.getName()); applicationContext.getBean(AnnotatedMapper.class.getName()); }
From source file:com.inspiresoftware.lib.dto.geda.config.XmlDrivenGeDABeanDefinitionParser.java
public BeanDefinitionHolder decorate(final Node node, final BeanDefinitionHolder definition, final ParserContext parserContext) { final BeanDefinition beanDefinition = definition.getBeanDefinition(); final String dtoSupportProperty = node.getAttributes().getNamedItem(XSD_ATTR__PROPERTY).getNodeValue(); final MutablePropertyValues properties = beanDefinition.getPropertyValues(); properties.add(dtoSupportProperty, new RuntimeBeanReference(dtoSupportBeanName)); return definition; }
From source file:com.github.spring.mvc.util.handler.config.UriMatchingAnnotationDrivenBeanDefinitionParser.java
/** * Create {@link MethodInterceptor} that is applies the caching logic to advised methods. * @return Reference to the {@link MethodInterceptor}. Should never be null. *//*w ww.j a v a 2 s. c o m*/ protected RuntimeBeanReference setupInterceptor(Element element, ParserContext parserContext, Object elementSource) { final RootBeanDefinition interceptor = new RootBeanDefinition( UriMatchingHandlerInterceptorInterceptor.class); interceptor.setSource(elementSource); interceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final XmlReaderContext readerContext = parserContext.getReaderContext(); final String interceptorBeanName = readerContext.registerWithGeneratedName(interceptor); return new RuntimeBeanReference(interceptorBeanName); }
From source file:org.opencredo.esper.config.xml.EsperStatementParser.java
/** * Parses out the individual statement elements for further processing. * //from ww w . j a va2 s . c o m * @param element * the esper-template context * @param parserContext * the parser's context * @return a set of initialized esper statements */ @SuppressWarnings("unchecked") public ManagedSet parseStatements(Element element, ParserContext parserContext) { ManagedSet statements = new ManagedSet(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; String localName = child.getLocalName(); if ("statement".equals(localName)) { BeanDefinition definition = parserContext.getDelegate().parseCustomElement(childElement); statements.add(definition); } else if ("ref".equals(localName)) { String ref = childElement.getAttribute("bean"); statements.add(new RuntimeBeanReference(ref)); } } } return statements; }
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.filtering.AttributeFilterPolicyBeanDefinitionParser.java
/** {@inheritDoc} */ protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(config, parserContext, builder); String policyId = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "id")); log.info("Parsing configuration for attribute filter policy {}", policyId); builder.addPropertyValue("policyId", policyId); List<Element> children; Map<QName, List<Element>> childrenMap = XMLHelper.getChildElements(config); children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PolicyRequirementRule")); if (children != null && children.size() > 0) { builder.addPropertyValue("policyRequirement", SpringConfigurationUtils.parseInnerCustomElement(children.get(0), parserContext)); } else {/*w w w . j a v a 2s . com*/ children = childrenMap .get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PolicyRequirementRuleReference")); String reference = getAbsoluteReference(config, "PolicyRequirementRule", children.get(0).getTextContent()); builder.addPropertyReference("policyRequirement", reference); } ManagedList attributeRules = new ManagedList(); children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRule")); if (children != null && children.size() > 0) { attributeRules.addAll(SpringConfigurationUtils.parseInnerCustomElements(children, parserContext)); } children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRuleReference")); if (children != null && children.size() > 0) { String reference; for (Element child : children) { reference = getAbsoluteReference(config, "AttributeRule", child.getTextContent()); attributeRules.add(new RuntimeBeanReference(reference)); } } builder.addPropertyValue("attributeRules", attributeRules); }
From source file:org.springmodules.cache.config.AbstractMetadataAttributesParser.java
private void registerCachingAdvisor(BeanDefinitionRegistry registry) { Class cachingAdvisorClass = CachingAttributeSourceAdvisor.class; RootBeanDefinition cachingAdvisor = new RootBeanDefinition(cachingAdvisorClass); cachingAdvisor.getConstructorArgumentValues() .addGenericArgumentValue(new RuntimeBeanReference(BeanName.CACHING_INTERCEPTOR)); registry.registerBeanDefinition(cachingAdvisorClass.getName(), cachingAdvisor); }
From source file:org.jsr107.ri.annotations.spring.config.AnnotationDrivenJCacheBeanDefinitionParser.java
/** * Create a {@link CacheContextSourceImpl} bean that will be used by the advisor and interceptor * * @return Reference to the {@link CacheContextSourceImpl}. Should never be null. *///from w ww . j a v a 2s. co m protected RuntimeBeanReference setupCacheOperationSource(Element element, ParserContext parserContext, Object elementSource) { final RootBeanDefinition cacheAttributeSource = new RootBeanDefinition(CacheContextSourceImpl.class); cacheAttributeSource.setSource(elementSource); cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final RootBeanDefinition defaultCacheResolverFactory = new RootBeanDefinition( DefaultCacheResolverFactory.class); cacheAttributeSource.setSource(elementSource); cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final String cacheManagerName = element.getAttribute(XSD_ATTR_CACHE_MANAGER); if (StringUtils.hasText(cacheManagerName)) { final RuntimeBeanReference cacheManagerReference = new RuntimeBeanReference(cacheManagerName); final ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addIndexedArgumentValue(0, cacheManagerReference); cacheAttributeSource.setConstructorArgumentValues(constructorArgumentValues); } final RootBeanDefinition defaultCacheKeyGenerator = new RootBeanDefinition(DefaultCacheKeyGenerator.class); cacheAttributeSource.setSource(elementSource); cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final MutablePropertyValues propertyValues = cacheAttributeSource.getPropertyValues(); propertyValues.addPropertyValue("defaultCacheKeyGenerator", defaultCacheKeyGenerator); propertyValues.addPropertyValue("defaultCacheResolverFactory", defaultCacheResolverFactory); final BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(JCACHE_CACHE_OPERATION_SOURCE_BEAN_NAME, cacheAttributeSource); return new RuntimeBeanReference(JCACHE_CACHE_OPERATION_SOURCE_BEAN_NAME); }