List of usage examples for org.springframework.beans.factory.config BeanDefinitionHolder BeanDefinitionHolder
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName)
From source file:org.apache.ftpserver.config.spring.CommandFactoryBeanDefinitionParser.java
/** * {@inheritDoc}//w w w. jav a2s . c om */ @Override protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) { BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder .genericBeanDefinition(CommandFactoryFactory.class); ManagedMap commands = new ManagedMap(); List<Element> childs = SpringUtil.getChildElements(element); for (Element commandElm : childs) { String name = commandElm.getAttribute("name"); Object bean = SpringUtil.parseSpringChildElement(commandElm, parserContext, builder); commands.put(name, bean); } factoryBuilder.addPropertyValue("commandMap", commands); if (StringUtils.hasText(element.getAttribute("use-default"))) { factoryBuilder.addPropertyValue("useDefaultCommands", Boolean.valueOf(element.getAttribute("use-default"))); } BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition(); String factoryId = parserContext.getReaderContext().generateBeanName(factoryDefinition); BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryId); registerBeanDefinition(factoryHolder, parserContext.getRegistry()); // set the factory on the listener bean builder.getRawBeanDefinition().setFactoryBeanName(factoryId); builder.getRawBeanDefinition().setFactoryMethodName("createCommandFactory"); }
From source file:org.activiti.spring.components.config.xml.ActivitiAnnotationDrivenBeanDefinitionParser.java
@Deprecated private void registerStateHandlerAnnotationBeanFactoryPostProcessor(Element element, ParserContext context) { Class clz = StateHandlerAnnotationBeanFactoryPostProcessor.class; BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(clz.getName()); BeanDefinitionHolder postProcessorHolder = new BeanDefinitionHolder( postProcessorBuilder.getBeanDefinition(), ActivitiContextUtils.ANNOTATION_STATE_HANDLER_BEAN_FACTORY_POST_PROCESSOR_BEAN_NAME); configureProcessEngine(postProcessorBuilder.getBeanDefinition(), element); BeanDefinitionReaderUtils.registerBeanDefinition(postProcessorHolder, context.getRegistry()); }
From source file:com.mtgi.analytics.aop.config.v11.BtJdbcPersisterBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //configure ID generator settings NodeList children = element.getElementsByTagNameNS("*", ELT_ID_SQL); if (children.getLength() == 1) { BeanDefinition def = builder.getRawBeanDefinition(); MutablePropertyValues props = def.getPropertyValues(); Element child = (Element) children.item(0); String sql = child.getTextContent(); if (StringUtils.hasText(sql)) props.addPropertyValue("idSql", sql); if (child.hasAttribute(ATT_INCREMENT)) props.addPropertyValue("idIncrement", child.getAttribute(ATT_INCREMENT)); }/* w w w . j a v a 2 s.c o m*/ //configure nested dataSource NodeList nodes = element.getElementsByTagNameNS("*", "data-source"); if (nodes.getLength() == 1) { Element ds = (Element) nodes.item(0); ds.setAttribute("name", "dataSource"); parserContext.getDelegate().parsePropertyElement(ds, builder.getRawBeanDefinition()); } //push persister into parent manager bean, if applicable if (parserContext.isNested()) { AbstractBeanDefinition def = builder.getBeanDefinition(); String id = element.hasAttribute("id") ? element.getAttribute("id") : BeanDefinitionReaderUtils.generateBeanName(def, parserContext.getReaderContext().getRegistry(), true); BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id); BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext); } }
From source file:net.hasor.rsf.spring.parser.RsfDefinitionParser.java
/** ?Xml */ @Override/*from www. ja v a 2 s . com*/ public BeanDefinition parse(Element element, ParserContext parserContext) { // Spring String version = SpringVersion.getVersion(); version = StringUtils.isBlank(version) ? "?" : version; Map customEditors = null; if (version.charAt(0) == '4' || version.charAt(0) == '5') { customEditors = new HashMap<Class<?>, Class<? extends java.beans.PropertyEditor>>(); customEditors.put(InterAddress.class, RsfAddressPropertyEditor.class); } else { customEditors = new HashMap(); customEditors.put("net.hasor.rsf.InterAddress", new RsfAddressPropertyEditor()); } // // . Bean BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setBeanClass(CustomEditorConfigurer.class); builder.setScope(BeanDefinition.SCOPE_SINGLETON);//? builder.addPropertyValue("customEditors", customEditors); // // .,BeanID net.hasor.rsf.spring.RsfAddressPropertyEditor AbstractBeanDefinition propEditors = builder.getBeanDefinition(); String beanID = RsfAddressPropertyEditor.class.getName(); BeanDefinitionHolder holder = new BeanDefinitionHolder(propEditors, beanID); BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); parserContext.registerComponent(new BeanComponentDefinition(holder)); // // NamedNodeMap attributes = element.getAttributes(); // return null; }
From source file:org.springmodules.cache.config.BeanReferenceParserImplTests.java
public void testParseWithAnonymousBean() { String beanName = ""; Element beanElement = createBeanElementBuilder(beanName).toXml(); Element referenceElement = elementBuilder.toXml(); referenceElement.appendChild(beanElement); RootBeanDefinition beanDefinition = new RootBeanDefinition(String.class); BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, beanName); delegate.parseBeanDefinitionElement(beanElement, null); helperControl.setReturnValue(holder); helperControl.replay();/*w w w .j a v a2s .c o m*/ // method to test Object actual = parser.parse(referenceElement, parserContext, true); assertSame(holder, actual); // assert the bean definition was not registered. assertEquals(0, registry.getBeanDefinitionCount()); }
From source file:br.com.caelum.vraptor.ioc.spring.SpringRegistry.java
private void registerOn(Class<?> type, boolean customComponent) { AnnotatedGenericBeanDefinition definition = new AnnotatedGenericBeanDefinition(type); if (!customComponent) { definition.setLazyInit(true);/* w w w.j a va 2 s . c o m*/ } definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_NO); definition.setPrimary(customComponent); definition.setRole(customComponent ? BeanDefinition.ROLE_APPLICATION : BeanDefinition.ROLE_INFRASTRUCTURE); String name = beanNameGenerator.generateBeanName(definition, (BeanDefinitionRegistry) beanFactory); BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(definition, name); ScopeMetadata scopeMetadata = scopeResolver.resolveScopeMetadata(definition); definitionHolder = applyScopeOn(definitionHolder, scopeMetadata); BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, (BeanDefinitionRegistry) beanFactory); }
From source file:org.springmodules.cache.config.CachingListenerValidatorImplTests.java
private BeanDefinitionHolder createBeanDefinitionHolder(BeanDefinition beanDefinition) { String beanName = CACHING_LISTENER_BEAN_NAME; BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, beanName); return holder; }
From source file:org.apache.smscserver.config.spring.MessageManagerBeanDefinitionParser.java
@Override protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) { Class<?> factoryClass = DBMessageManagerFactory.class; BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(factoryClass); Element dsElm = SpringUtil.getChildElement(element, SmscServerNamespaceHandler.SMSCSERVER_NS, "data-source"); if (dsElm != null) { // schema ensure we get the right type of element Element springElm = SpringUtil.getChildElement(dsElm, null, null); Object o;// w ww .j av a 2 s.co m if ("bean".equals(springElm.getLocalName())) { o = parserContext.getDelegate().parseBeanDefinitionElement(springElm, builder.getBeanDefinition()); } else { // ref o = parserContext.getDelegate().parsePropertySubElement(springElm, builder.getBeanDefinition()); } factoryBuilder.addPropertyValue("dataSource", o); } factoryBuilder.addPropertyValue("embeddedProfile", this.getChildElement(element, "embedded-profile")); factoryBuilder.addPropertyValue("URL", this.getChildElement(element, "url")); factoryBuilder.addPropertyValue("sqlCreateTable", this.getChildElement(element, "crate-table")); factoryBuilder.addPropertyValue("sqlInsertMessage", this.getChildElement(element, "insert-message")); factoryBuilder.addPropertyValue("sqlSelectMessage", this.getChildElement(element, "select-message")); factoryBuilder.addPropertyValue("sqlSelectUserMessage", this.getChildElement(element, "select-user-message")); factoryBuilder.addPropertyValue("sqlSelectLatestReplacableMessage", this.getChildElement(element, "select-replace")); factoryBuilder.addPropertyValue("sqlUpdateMessage", this.getChildElement(element, "update-message")); BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition(); String factoryId = parserContext.getReaderContext().generateBeanName(factoryDefinition); BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryId); this.registerBeanDefinition(factoryHolder, parserContext.getRegistry()); // set the factory on the listener bean builder.getRawBeanDefinition().setFactoryBeanName(factoryId); builder.getRawBeanDefinition().setFactoryMethodName("createMessageManager"); }
From source file:com.mtgi.analytics.aop.config.v11.BtPersisterChainBeanDefinitionParser.java
@Override @SuppressWarnings("unchecked") protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //propagate shared template factory into sub-components if necessary. this would not be //necessary if parserContext gave us access to the entire component stack instead of just the //top. In that case, deeply nested children could search up the stack until they found //the template. perhaps a future version of the Spring API will support this. DefaultListableBeanFactory template = findEnclosingTemplateFactory(parserContext); if (template != null) parserContext.pushContainingComponent(new TemplateComponentDefinition(element.getNodeName(), parserContext.extractSource(element), template)); try {/* w w w.j av a2 s. co m*/ //parse delegate persister definitions ManagedList persisters = new ManagedList(); persisters.setSource(element); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); Object def = handler == null ? parserContext.getDelegate().parsePropertySubElement((Element) node, builder.getRawBeanDefinition()) : handler.parse((Element) node, parserContext); persisters.add(def); } } builder.addPropertyValue("delegates", persisters); } finally { if (template != null) parserContext.popContainingComponent(); } //register persister implementation with parent. if (parserContext.isNested()) { AbstractBeanDefinition def = builder.getBeanDefinition(); String id = element.hasAttribute("id") ? element.getAttribute("id") : parserContext.getReaderContext().generateBeanName(def); BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id); BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext); } }
From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenterTest.java
@Test public void existingBeanDefinitionHolder() { BeanDefinitionHolder bdh = new BeanDefinitionHolder(this.beanDefinition, ""); this.propertyValues.addPropertyValue(this.key, bdh); Map<String, String> m = new HashMap<String, String>(); m.put("additional-key", "additional-value"); this.propertyValues.addPropertyValue("sourceMap", m); this.propertyAugmenter.augment(this.beanFactory, this.beanClass, this.key, this.additionalProperties); assertTrue(this.propertyValues.contains(this.key)); assertContainsKey("additional-key"); }