List of usage examples for org.springframework.beans.factory.support RootBeanDefinition RootBeanDefinition
RootBeanDefinition(BeanDefinition original)
From source file:org.springmodules.cache.config.AbstractCacheManagerAndProviderFacadeParser.java
/** * Parses the given XML element containing the properties of the cache manager * to register in the given registry of bean definitions. * /*from ww w . ja v a2 s . c o m*/ * @param element * the XML element to parse * @param registry * the registry of bean definitions * * @see AbstractCacheProviderFacadeParser#doParse(String, Element, * BeanDefinitionRegistry) */ protected final void doParse(String cacheProviderFacadeId, Element element, BeanDefinitionRegistry registry) { String id = "cacheManager"; Class clazz = getCacheManagerClass(); RootBeanDefinition cacheManager = new RootBeanDefinition(clazz); MutablePropertyValues cacheManagerProperties = new MutablePropertyValues(); cacheManager.setPropertyValues(cacheManagerProperties); PropertyValue configLocation = parseConfigLocationProperty(element); cacheManagerProperties.addPropertyValue(configLocation); registry.registerBeanDefinition(id, cacheManager); BeanDefinition cacheProviderFacade = registry.getBeanDefinition(cacheProviderFacadeId); cacheProviderFacade.getPropertyValues().addPropertyValue("cacheManager", new RuntimeBeanReference(id)); }
From source file:org.zalando.spring.data.businesskey.config.BusinessKeyBeanDefinitionParser.java
public BeanDefinition parse(final Element element, final ParserContext parser) { new SpringConfiguredBeanDefinitionParser().parse(element, parser); BeanDefinition keyHandlerDefinition = keyHandlerParser.parse(element, parser); BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(KEY_ENTITY_LISTENER_CLASS_NAME); // Achtung member-access, member muss genauso heissen builder.addPropertyValue("keyHandler", keyHandlerDefinition); builder.setScope("prototype"); registerInfrastructureBeanWithId(builder.getRawBeanDefinition(), KEY_ENTITY_LISTENER_CLASS_NAME, parser, element);//w w w. ja v a 2 s .c o m RootBeanDefinition def = new RootBeanDefinition(KEY_BFPP_CLASS_NAME); registerInfrastructureBeanWithId(def, KEY_BFPP_CLASS_NAME, parser, element); return null; }
From source file:fr.xebia.management.config.ServletContextAwareMBeanServerDefinitionParser.java
/** * Logic taken from/*from w ww .j a v a 2 s .co m*/ * <code>org.springframework.context.config.MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment()</code> */ static AbstractBeanDefinition findServerForSpecialEnvironment() { boolean weblogicPresent = ClassUtils.isPresent("weblogic.management.Helper", ServletContextAwareMBeanServerDefinitionParser.class.getClassLoader()); boolean webspherePresent = ClassUtils.isPresent("com.ibm.websphere.management.AdminServiceFactory", ServletContextAwareMBeanServerDefinitionParser.class.getClassLoader()); if (weblogicPresent) { RootBeanDefinition bd = new RootBeanDefinition(JndiObjectFactoryBean.class); bd.getPropertyValues().add("jndiName", "java:comp/env/jmx/runtime"); return bd; } else if (webspherePresent) { return new RootBeanDefinition(WebSphereMBeanServerFactoryBean.class); } else { return null; } }
From source file:org.springjutsu.validation.namespace.ValidationEntityDefinitionParser.java
/** * Do actual parsing./* w w w .j a va 2s.com*/ * Since rules may be nested, delegate to {@link #parseNestedRules(Element, Class)} * where necessary. */ public BeanDefinition parse(Element entityNode, ParserContext parserContext) { RootBeanDefinition entityDefinition = new RootBeanDefinition(ValidationEntity.class); String className = entityNode.getAttribute("class"); Class<?> modelClass; try { modelClass = Class.forName(className); } catch (ClassNotFoundException cnfe) { throw new ValidationParseException("Class " + className + " does not exist as a model class."); } List<String> excludePaths = new ArrayList<String>(); NodeList excludes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-exclude"); for (int excludeNbr = 0; excludeNbr < excludes.getLength(); excludeNbr++) { Element excludeNode = (Element) excludes.item(excludeNbr); String path = excludeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-exclude property name \"" + path + "\" Exclude paths should not be nested fields."); } else { excludePaths.add(path); } } List<String> includePaths = new ArrayList<String>(); NodeList includes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "recursion-include"); for (int includeNbr = 0; includeNbr < includes.getLength(); includeNbr++) { Element includeNode = (Element) includes.item(includeNbr); String path = includeNode.getAttribute("propertyName"); if (path.contains(".")) { throw new ValidationParseException("Invalid recursion-include property name \"" + path + "\" Include paths should not be nested fields."); } else { includePaths.add(path); } } ValidationStructure validationStructure = parseNestedValidation(entityNode, modelClass); List<ValidationTemplate> templates = new ArrayList<ValidationTemplate>(); NodeList templateNodes = entityNode.getElementsByTagNameNS(entityNode.getNamespaceURI(), "template"); for (int templateNbr = 0; templateNbr < templateNodes.getLength(); templateNbr++) { Element templateNode = (Element) templateNodes.item(templateNbr); String templateName = templateNode.getAttribute("name"); ValidationStructure templateValidation = parseNestedValidation(templateNode, modelClass); ValidationTemplate template = new ValidationTemplate(templateName, modelClass); template.setRules(templateValidation.rules); template.setTemplateReferences(templateValidation.refs); template.setValidationContexts(templateValidation.contexts); templates.add(template); } entityDefinition.getPropertyValues().add("rules", validationStructure.rules); entityDefinition.getPropertyValues().add("templateReferences", validationStructure.refs); entityDefinition.getPropertyValues().add("validationContexts", validationStructure.contexts); entityDefinition.getPropertyValues().add("validationTemplates", templates); entityDefinition.getPropertyValues().add("validationClass", modelClass); entityDefinition.getPropertyValues().add("includedPaths", includePaths); entityDefinition.getPropertyValues().add("excludedPaths", excludePaths); String entityName = parserContext.getReaderContext().registerWithGeneratedName(entityDefinition); parserContext.registerComponent(new BeanComponentDefinition(entityDefinition, entityName)); return null; }
From source file:com.google.inject.spring.SpringIntegrationTest.java
public void testBindAll() throws CreationException { final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); RootBeanDefinition singleton = new RootBeanDefinition(Singleton.class); beanFactory.registerBeanDefinition("singleton", singleton); RootBeanDefinition prototype = new RootBeanDefinition(Prototype.class, false); beanFactory.registerBeanDefinition("prototype", prototype); Injector injector = Guice.createInjector(new AbstractModule() { protected void configure() { SpringIntegration.bindAll(binder(), beanFactory); }/*from w w w. j av a2 s .com*/ }); Key<Singleton> singletonKey = Key.get(Singleton.class, Names.named("singleton")); Key<Prototype> prototypeKey = Key.get(Prototype.class, Names.named("prototype")); assertNotNull(injector.getInstance(singletonKey)); assertSame(injector.getInstance(singletonKey), injector.getInstance(singletonKey)); assertNotNull(injector.getInstance(prototypeKey)); assertNotSame(injector.getInstance(prototypeKey), injector.getInstance(prototypeKey)); }
From source file:gr.abiss.calipso.fs.FilePersistenceConfigPostProcessor.java
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { if (this.repositoryClass == null) { LOGGER.debug("Adding FilePersistenceService bean using: " + this.repositoryClassName); if (StringUtils.isBlank(this.repositoryClassName)) { this.repositoryClassName = ConfigurationFactory.getConfiguration() .getString(ConfigurationFactory.FS_IMPL_CLASS); }/*from w ww . j a v a 2s .c o m*/ try { this.repositoryClass = FilePersistenceConfigPostProcessor.class.forName(this.repositoryClassName); } catch (ClassNotFoundException e) { LOGGER.error("Failed to obtain repository class: " + this.repositoryClassName + ", will fallback to default"); } } if (this.repositoryClass == null) { this.repositoryClass = DummyFilePersistenceServiceImpl.class; } RootBeanDefinition beanDefinition = new RootBeanDefinition(this.repositoryClass); //The service implementation beanDefinition.setTargetType(FilePersistenceService.class); //The service interface //beanDefinition.setRole(BeanDefinition.ROLE_APPLICATION); registry.registerBeanDefinition(FilePersistenceService.BEAN_ID, beanDefinition); LOGGER.debug("Added FilePersistenceService bean using: " + this.repositoryClass.getName()); }
From source file:org.snaker.engine.spring.SpringContext.java
/** * ?springbean/*from w w w. j a va 2 s. c o m*/ */ public void put(String name, Class<?> clazz) { BeanDefinition definition = new RootBeanDefinition(clazz); beanFactory.registerBeanDefinition(name, definition); }
From source file:fr.xebia.management.config.ProfileAspectDefinitionParser.java
/** * Logic taken from//from w ww .jav a 2 s . c o m * <code>org.springframework.context.config.MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment()</code> */ static AbstractBeanDefinition findServerForSpecialEnvironment() { boolean weblogicPresent = ClassUtils.isPresent("weblogic.management.Helper", ProfileAspectDefinitionParser.class.getClassLoader()); boolean webspherePresent = ClassUtils.isPresent("com.ibm.websphere.management.AdminServiceFactory", ProfileAspectDefinitionParser.class.getClassLoader()); if (weblogicPresent) { RootBeanDefinition bd = new RootBeanDefinition(JndiObjectFactoryBean.class); bd.getPropertyValues().add("jndiName", "java:comp/env/jmx/runtime"); return bd; } else if (webspherePresent) { return new RootBeanDefinition(WebSphereMBeanServerFactoryBean.class); } else { return null; } }
From source file:ro.fortsoft.pf4j.spring.ExtensionsInjector.java
private void injectExtensions(BeanDefinitionRegistry registry) { PluginManager pluginManager = applicationContext.getBean(PluginManager.class); List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins(); for (PluginWrapper plugin : startedPlugins) { log.debug("Registering extensions of the plugin '{}' as beans", plugin.getPluginId()); Set<String> extensionClassNames = pluginManager.getExtensionClassNames(plugin.getPluginId()); for (String extensionClassName : extensionClassNames) { Class<?> extensionClass = null; try { log.debug("Register extension '{}' as bean", extensionClassName); extensionClass = plugin.getPluginClassLoader().loadClass(extensionClassName); BeanDefinition definition = new RootBeanDefinition(extensionClass); // optionally configure all bean properties, like scope, prototype/singleton, etc registry.registerBeanDefinition(extensionClassName, definition); } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); }/*from w ww . j a v a 2s .c om*/ } } }
From source file:com.developmentsprint.spring.breaker.config.BreakerAdviceParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addPropertyReference(CB_MANAGER_NAME, BreakerNamespaceHandler.extractCircuitManager(element)); List<Element> cbAttributes = DomUtils.getChildElementsByTagName(element, CB_ELEMENT_NAME); if (cbAttributes.size() > 0) { // Using attributes source. RootBeanDefinition attributeSourceDefinition = parseAttributeSource(cbAttributes, parserContext); builder.addPropertyValue("circuitBreakerAttributeSource", attributeSourceDefinition); } else {/*from w w w.j ava2 s .c o m*/ // Assume annotations source. builder.addPropertyValue("circuitBreakerAttributeSource", new RootBeanDefinition( "com.developmentsprint.spring.breaker.annotations.AnnotationCircuitBreakerAttributeSource")); } }