Java Code Examples for org.springframework.beans.factory.xml.ParserContext#getRegistry()
The following examples show how to use
org.springframework.beans.factory.xml.ParserContext#getRegistry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolygeneServiceBeanDefinitionParser.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public final BeanDefinition parse( Element anElement, ParserContext aParserContext ) { String serviceId = anElement.getAttribute( SERVICE_ID ); // Service factory bean BeanDefinitionBuilder builder = rootBeanDefinition( ServiceFactoryBean.class ); builder.addConstructorArgReference( BEAN_ID_POLYGENE_APPLICATION ); builder.addConstructorArgValue( serviceId ); AbstractBeanDefinition definition = builder.getBeanDefinition(); // Register service factory bean BeanDefinitionRegistry definitionRegistry = aParserContext.getRegistry(); definitionRegistry.registerBeanDefinition( serviceId, definition ); return definition; }
Example 2
Source File: AbstractCacheProviderFacadeParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Parses the specified XML element which contains the properties of the * <code>{@link org.springmodules.cache.provider.CacheProviderFacade}</code> * to register in the given registry of bean definitions. * * @param element * the XML element to parse * @param parserContext * the parser context * @throws IllegalStateException * if the value of the property <code>serializableFactory</code> * is not equal to "NONE" or "XSTREAM" * * @see BeanDefinitionParser#parse(Element, ParserContext) */ public final BeanDefinition parse(Element element, ParserContext parserContext) throws IllegalStateException { String id = element.getAttribute("id"); // create the cache provider facade Class clazz = getCacheProviderFacadeClass(); MutablePropertyValues propertyValues = new MutablePropertyValues(); RootBeanDefinition cacheProviderFacade = new RootBeanDefinition(clazz, propertyValues); propertyValues.addPropertyValue(parseFailQuietlyEnabledProperty(element)); propertyValues.addPropertyValue(parseSerializableFactoryProperty(element)); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(id, cacheProviderFacade); doParse(id, element, registry); return null; }
Example 3
Source File: DefaultsBeanDefinitionParser.java From jdal with Apache License 2.0 | 5 votes |
/** * Register a BeanComponentDefinition * @param element * @param parserContext * @param BeanComponentDefinition */ private void registerBeanComponentDefinition(Element element, ParserContext parserContext, BeanComponentDefinition bcd) { parserContext.getDelegate().parseBeanDefinitionAttributes(element, bcd.getBeanName(), null, (AbstractBeanDefinition) bcd.getBeanDefinition()); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(bcd.getBeanName(), bcd.getBeanDefinition()); }
Example 4
Source File: SpringNamespaceHandler.java From joyrpc with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { if (ready.compareAndSet(false, true)) { BeanDefinitionRegistry registry = parserContext.getRegistry(); if (!registry.containsBeanDefinition(DependsOnDefinitionPostProcessor.BEAN_NAME)) { registry.registerBeanDefinition(DependsOnDefinitionPostProcessor.BEAN_NAME, new RootBeanDefinition(DependsOnDefinitionPostProcessor.class)); } } return super.parse(element, parserContext); }
Example 5
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { if (StringUtil.isEmpty(element.getAttribute(NAME_ATTRIBUTE))) { parserContext.getReaderContext().error("CommonBaseService must have name attribute", element); } AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); BeanDefinitionRegistry beanDefinitionRegistry = parserContext.getRegistry(); BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); String name = element.getAttribute(NAME_ATTRIBUTE); beanDefinition.setAttribute(ID_ATTRIBUTE, name + COMMON_BASE_SERVICE_SUFFIX); beanDefinition.setBeanClassName(CLASS_NAME); beanDefinitionRegistry.registerBeanDefinition(name + DATA_SOURCE_SUFFIX, buildDataSourceBeanDefinition(element, name)); beanDefinitionRegistry.registerBeanDefinition(name + SQL_SESSION_FACTORY_SUFFIX, buildSqlSessionFactoryBeanDefinition(element, name)); beanDefinitionRegistry.registerBeanDefinition(name + SESSION_FACTORY_SUFFIX, buildSessionFactoryBeanDefinition(element, name, parserContext.getDelegate(), beanDefinitionRegistry)); beanDefinitionRegistry.registerBeanDefinition(name + SQL_SESSION_TEMPLATE_SUFFIX, buildSqlSessionTemplateBeanDefinition(element, name)); beanDefinitionRegistry.registerBeanDefinition(name + COMMON_BASE_DAO_SUFFIX, buildCommonBaseDaoBeanDefinition(element, name)); builder.addPropertyReference(COMMON_BASE_DAO_FIELD_NAME, name + COMMON_BASE_DAO_SUFFIX); element.setAttribute(ID_ATTRIBUTE, name + COMMON_BASE_SERVICE_SUFFIX); List<String> expressionList = buildExpressionList(element, delegate); if (expressionList.size() > 0) { beanDefinitionRegistry.registerBeanDefinition(name + HIBERNATE_TRANSACTION_MANAGER_SUFFIX, buildHibernateTransactionManagerBeanDefinition(element, name)); beanDefinitionRegistry.registerBeanDefinition(name + TRANSACTION_ATTRIBUTE_SOURCE_SUFFIX, buildTransactionAttributeSourceBeanDefinition()); beanDefinitionRegistry.registerBeanDefinition(name + HIBERNATE_ADVICE_SUFFIX, buildHibernateAdviceBeanDefinition(element, name)); buildPointcutAndAdvisorBeanDefinition(name, expressionList, parserContext, beanDefinitionRegistry); } }
Example 6
Source File: NacosPropertySourceBeanDefinitionParser.java From nacos-spring-project with Apache License 2.0 | 5 votes |
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionRegistry registry = parserContext.getRegistry(); // Register Dependent Beans registerNacosPropertySourcePostProcessor(registry); registerXmlNacosPropertySourceBuilder(registry); NacosPropertySourceXmlBeanDefinition beanDefinition = new NacosPropertySourceXmlBeanDefinition(); beanDefinition.setElement(element); beanDefinition.setXmlReaderContext(parserContext.getReaderContext()); return beanDefinition; }
Example 7
Source File: NacosAnnotationDrivenBeanDefinitionParser.java From nacos-spring-project with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { // Get Environment Environment environment = parserContext.getDelegate().getReaderContext() .getReader().getEnvironment(); // Get BeanDefinitionRegistry BeanDefinitionRegistry registry = parserContext.getRegistry(); // Register Nacos Annotation Beans NacosBeanDefinitionRegistrar registrar = new NacosBeanDefinitionRegistrar(); registrar.setEnvironment(environment); registrar.registerNacosAnnotationBeans(registry); return null; }
Example 8
Source File: GlobalNacosPropertiesBeanDefinitionParser.java From nacos-spring-project with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { Properties properties = new Properties(); Environment environment = parserContext.getDelegate().getReaderContext() .getReader().getEnvironment(); properties.setProperty(PropertyKeyConst.ENDPOINT, element.getAttribute(ENDPOINT)); properties.setProperty(PropertyKeyConst.NAMESPACE, element.getAttribute(NAMESPACE)); properties.setProperty(PropertyKeyConst.ACCESS_KEY, element.getAttribute(ACCESS_KEY)); properties.setProperty(PropertyKeyConst.SECRET_KEY, element.getAttribute(SECRET_KEY)); properties.setProperty(PropertyKeyConst.SERVER_ADDR, element.getAttribute(SERVER_ADDR)); properties.setProperty(PropertyKeyConst.CLUSTER_NAME, element.getAttribute(CLUSTER_NAME)); properties.setProperty(PropertyKeyConst.ENCODE, element.getAttribute(ENCODE)); properties.setProperty(PropertyKeyConst.USERNAME, element.getAttribute(USERNAME)); properties.setProperty(PropertyKeyConst.PASSWORD, element.getAttribute(PASSWORD)); BeanDefinitionRegistry registry = parserContext.getRegistry(); // Register Global Nacos Properties as Spring singleton bean registerGlobalNacosProperties(properties, registry, environment, GLOBAL_NACOS_PROPERTIES_BEAN_NAME); return null; }
Example 9
Source File: AbstractClassBeanDefinitionParser.java From conf4j with MIT License | 5 votes |
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionRegistry registry = parserContext.getRegistry(); BeanDefinitionBuilder builder = getBeanDefinitionBuilder(element, parserContext); if (builder == null) { return null; } AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); String beanName = resolveId(element, beanDefinition, parserContext); registry.registerBeanDefinition(beanName, beanDefinition); return beanDefinition; }
Example 10
Source File: DefaultsBeanDefinitionParser.java From jdal with Apache License 2.0 | 5 votes |
/** * @param registry * @param bcd */ private void registerBeanComponentDefinition(Element element, ParserContext parserContext, BeanComponentDefinition bcd) { parserContext.getDelegate().parseBeanDefinitionAttributes(element, bcd.getBeanName(), null, (AbstractBeanDefinition) bcd.getBeanDefinition()); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(bcd.getBeanName(), bcd.getBeanDefinition()); }
Example 11
Source File: CachingListenerValidatorImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * @see CachingListenerValidator#validate(Object, int, ParserContext) */ public void validate(Object cachingListener, int index, ParserContext parserContext) throws IllegalStateException { BeanDefinitionRegistry registry = parserContext.getRegistry(); BeanDefinition beanDefinition = null; if (cachingListener instanceof RuntimeBeanReference) { String beanName = ((RuntimeBeanReference) cachingListener).getBeanName(); beanDefinition = registry.getBeanDefinition(beanName); } else if (cachingListener instanceof BeanDefinitionHolder) { beanDefinition = ((BeanDefinitionHolder) cachingListener) .getBeanDefinition(); } else { throw new IllegalStateException("The caching listener reference/holder [" + index + "] should be an instance of <" + RuntimeBeanReference.class.getName() + "> or <" + BeanDefinitionHolder.class.getName() + ">"); } Class expectedClass = CachingListener.class; Class actualClass = resolveBeanClass(beanDefinition); if (!expectedClass.isAssignableFrom(actualClass)) { throw new IllegalStateException("The caching listener [" + index + "] should be an instance of <" + expectedClass.getName() + ">"); } }
Example 12
Source File: AbstractCacheSetupStrategyParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Parses the given XML element containing the properties and/or sub-elements * necessary to configure a strategy for setting up declarative caching * services. * * @param element * the XML element to parse * @param parserContext * the parser context * @throws IllegalStateException * if the bean definition registry does not have a definition for * the <code>CacheProviderFacade</code> registered under the name * specified in the XML attribute "providerId" * @throws IllegalStateException * if the cache provider facade is in invalid state * @throws IllegalStateException * if any of the caching listeners is not an instance of * <code>CachingListener</code> * * @see BeanDefinitionParser#parse(Element, ParserContext) */ public final BeanDefinition parse(Element element, ParserContext parserContext) throws NoSuchBeanDefinitionException, IllegalStateException { String cacheProviderFacadeId = element.getAttribute("providerId"); BeanDefinitionRegistry registry = parserContext.getRegistry(); if (!registry.containsBeanDefinition(cacheProviderFacadeId)) { throw new IllegalStateException( "An implementation of CacheProviderFacade should be registered under the name " + StringUtils.quote(cacheProviderFacadeId)); } RuntimeBeanReference cacheProviderFacadeReference = new RuntimeBeanReference( cacheProviderFacadeId); Object cacheKeyGenerator = parseCacheKeyGenerator(element, parserContext); List cachingListeners = parseCachingListeners(element, parserContext); Map cachingModels = parseCachingModels(element); Map flushingModels = parseFlushingModels(element); CacheSetupStrategyPropertySource ps = new CacheSetupStrategyPropertySource( cacheKeyGenerator, cacheProviderFacadeReference, cachingListeners, cachingModels, flushingModels); parseCacheSetupStrategy(element, parserContext, ps); return null; }
Example 13
Source File: CacheProxyFactoryBeanParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Creates and registers a <code>{@link CacheProxyFactoryBean}</code> by * parsing the given XML element. * * @param element * the XML element to parse * @param parserContext * the registry of bean definitions * @param propertySource * contains common properties for the different cache setup * strategies * @throws IllegalStateException * if the "proxy" tag does not contain any reference to an existing * bean or if it does not contain a bean definition * * @see AbstractCacheSetupStrategyParser#parseCacheSetupStrategy(Element, * ParserContext, CacheSetupStrategyPropertySource) */ protected void parseCacheSetupStrategy(Element element, ParserContext parserContext, CacheSetupStrategyPropertySource propertySource) { Object target = getBeanReferenceParser().parse(element, parserContext); RootBeanDefinition cacheProxyFactoryBean = new RootBeanDefinition( CacheProxyFactoryBean.class, propertySource.getAllProperties()); cacheProxyFactoryBean.getPropertyValues() .addPropertyValue("target", target); String id = element.getAttribute("id"); BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(id, cacheProxyFactoryBean); }
Example 14
Source File: PolygeneBootstrapBeanDefinitionParser.java From attic-polygene-java with Apache License 2.0 | 4 votes |
private void registerBean( ParserContext aParserContext, BeanDefinition aBeanDefinition ) { BeanDefinitionRegistry registry = aParserContext.getRegistry(); registry.registerBeanDefinition( BEAN_ID_POLYGENE_APPLICATION, aBeanDefinition ); }
Example 15
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding <jms:annotation-driven> element. CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); parserContext.pushContainingComponent(compDefinition); // Nest the concrete post-processor bean in the surrounding component. BeanDefinitionRegistry registry = parserContext.getRegistry(); if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { parserContext.getReaderContext().error( "Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor"); builder.getRawBeanDefinition().setSource(source); String endpointRegistry = element.getAttribute("registry"); if (StringUtils.hasText(endpointRegistry)) { builder.addPropertyReference("endpointRegistry", endpointRegistry); } else { registerDefaultEndpointRegistry(source, parserContext); } String containerFactory = element.getAttribute("container-factory"); if (StringUtils.hasText(containerFactory)) { builder.addPropertyValue("containerFactoryBeanName", containerFactory); } String handlerMethodFactory = element.getAttribute("handler-method-factory"); if (StringUtils.hasText(handlerMethodFactory)) { builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory); } registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME); } // Finally register the composite component. parserContext.popAndRegisterContainingComponent(); return null; }
Example 16
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding <jms:annotation-driven> element. CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); parserContext.pushContainingComponent(compDefinition); // Nest the concrete post-processor bean in the surrounding component. BeanDefinitionRegistry registry = parserContext.getRegistry(); if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { parserContext.getReaderContext().error( "Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor"); builder.getRawBeanDefinition().setSource(source); String endpointRegistry = element.getAttribute("registry"); if (StringUtils.hasText(endpointRegistry)) { builder.addPropertyReference("endpointRegistry", endpointRegistry); } else { registerDefaultEndpointRegistry(source, parserContext); } String containerFactory = element.getAttribute("container-factory"); if (StringUtils.hasText(containerFactory)) { builder.addPropertyValue("containerFactoryBeanName", containerFactory); } String handlerMethodFactory = element.getAttribute("handler-method-factory"); if (StringUtils.hasText(handlerMethodFactory)) { builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory); } registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME); } // Finally register the composite component. parserContext.popAndRegisterContainingComponent(); return null; }
Example 17
Source File: CacheXmlParser.java From jstarcraft-core with Apache License 2.0 | 4 votes |
private void assembleProcessor(ParserContext context) { BeanDefinitionRegistry registry = context.getRegistry(); String name = StringUtility.uncapitalize(CacheAccessorProcessor.class.getSimpleName()); BeanDefinitionBuilder factory = BeanDefinitionBuilder.genericBeanDefinition(CacheAccessorProcessor.class); registry.registerBeanDefinition(name, factory.getBeanDefinition()); }
Example 18
Source File: ResourceXmlParser.java From jstarcraft-core with Apache License 2.0 | 4 votes |
private void assembleProcessor(ParserContext parserContext) { BeanDefinitionRegistry registry = parserContext.getRegistry(); String name = StringUtility.uncapitalize(ResourceAccessorProcessor.class.getSimpleName()); BeanDefinitionBuilder factory = BeanDefinitionBuilder.genericBeanDefinition(ResourceAccessorProcessor.class); registry.registerBeanDefinition(name, factory.getBeanDefinition()); }
Example 19
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From java-technology-stack with MIT License | 4 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding <jms:annotation-driven> element. CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); parserContext.pushContainingComponent(compDefinition); // Nest the concrete post-processor bean in the surrounding component. BeanDefinitionRegistry registry = parserContext.getRegistry(); if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { parserContext.getReaderContext().error( "Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor"); builder.getRawBeanDefinition().setSource(source); String endpointRegistry = element.getAttribute("registry"); if (StringUtils.hasText(endpointRegistry)) { builder.addPropertyReference("endpointRegistry", endpointRegistry); } else { registerDefaultEndpointRegistry(source, parserContext); } String containerFactory = element.getAttribute("container-factory"); if (StringUtils.hasText(containerFactory)) { builder.addPropertyValue("containerFactoryBeanName", containerFactory); } String handlerMethodFactory = element.getAttribute("handler-method-factory"); if (StringUtils.hasText(handlerMethodFactory)) { builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory); } registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME); } // Finally register the composite component. parserContext.popAndRegisterContainingComponent(); return null; }
Example 20
Source File: MethodMapInterceptorsParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 3 votes |
/** * Creates and registers instances * <code>{@link MethodMapCachingInterceptor}</code> and * <code>{@link MethodMapFlushingInterceptor}</code> by parsing the given * XML element. * * @param element * the XML element to parse * @param parserContext * the registry of bean definitions * @param propertySource * contains common properties for the different cache setup * strategies * * @see AbstractCacheSetupStrategyParser#parseCacheSetupStrategy(Element, * ParserContext, CacheSetupStrategyPropertySource) */ protected void parseCacheSetupStrategy(Element element, ParserContext parserContext, CacheSetupStrategyPropertySource propertySource) { BeanDefinitionRegistry registry = parserContext.getRegistry(); String cachingInterceptorId = element.getAttribute("cachingInterceptorId"); registerCachingInterceptor(cachingInterceptorId, registry, propertySource); String flushingInterceptorId = element .getAttribute("flushingInterceptorId"); registerFlushingInterceptor(flushingInterceptorId, registry, propertySource); }