Code example for AbstractBeanDefinition

Methods: setBeanClassvalidate

0
class CacheParser extends AbstractSimpleBeanDefinitionParser {
 
	@Override 
	protected Class<?> getBeanClass(Element element) {
		return CacheFactoryBean.class; 
	} 
 
	@Override 
	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
		super.doParse(element, builder);
 
		ParsingUtils.setPropertyValue(element, builder, "cache-xml-location", "cacheXml");
		ParsingUtils.setPropertyReference(element, builder, "properties-ref", "properties");
		ParsingUtils.setPropertyValue(element, builder, "lazy-init","lazyInitialize");
		ParsingUtils.setPropertyValue(element, builder, "use-bean-factory-locator");
		ParsingUtils.setPropertyValue(element, builder, "close");
		ParsingUtils.setPropertyValue(element, builder, "copy-on-read");
		ParsingUtils.setPropertyValue(element, builder, "critical-heap-percentage");
		ParsingUtils.setPropertyValue(element, builder, "eviction-heap-percentage");
		ParsingUtils.setPropertyValue(element, builder, "enable-auto-reconnect");
		ParsingUtils.setPropertyValue(element, builder, "lock-lease");
		ParsingUtils.setPropertyValue(element, builder, "lock-timeout");
		ParsingUtils.setPropertyValue(element, builder, "message-sync-interval");
		ParsingUtils.setPropertyReference(element, builder, "pdx-serializer-ref", "pdxSerializer");
		ParsingUtils.setPropertyValue(element, builder, "pdx-read-serialized");
		ParsingUtils.setPropertyValue(element, builder, "pdx-ignore-unread-fields");
		ParsingUtils.setPropertyValue(element, builder, "pdx-persistent");
		parsePdxDiskStore(element, parserContext, builder);
		ParsingUtils.setPropertyValue(element, builder, "search-timeout");
		ParsingUtils.setPropertyValue(element, builder, "use-cluster-configuration");
 
		List<Element> txListeners = DomUtils.getChildElementsByTagName(element, "transaction-listener");
 
		if (!CollectionUtils.isEmpty(txListeners)) {
			ManagedList<Object> transactionListeners = new ManagedList<Object>();
			for (Element txListener : txListeners) {
				transactionListeners.add(ParsingUtils.parseRefOrNestedBeanDeclaration(
					parserContext, txListener, builder));
			} 
			builder.addPropertyValue("transactionListeners", transactionListeners);
		} 
 
		Element txWriter = DomUtils.getChildElementByTagName(element, "transaction-writer");
 
		if (txWriter != null) {
			builder.addPropertyValue("transactionWriter", ParsingUtils.parseRefOrNestedBeanDeclaration(
				parserContext, txWriter, builder));
		} 
 
		Element gatewayConflictResolver = DomUtils.getChildElementByTagName(element, "gateway-conflict-resolver");
 
		if (gatewayConflictResolver != null) {
			ParsingUtils.throwExceptionIfNotGemfireV7(element.getLocalName(), "gateway-conflict-resolver", parserContext);
			builder.addPropertyValue("gatewayConflictResolver", ParsingUtils.parseRefOrSingleNestedBeanDeclaration(
				parserContext, gatewayConflictResolver, builder));
		} 
 
		Element function = DomUtils.getChildElementByTagName(element, "function");
 
		if (function != null) {
			builder.addPropertyValue("functions", ParsingUtils.parseRefOrNestedBeanDeclaration(
				parserContext, function, builder));
		} 
 
		parseDynamicRegionFactory(element, builder);
		parseJndiBindings(element, builder);
	} 
 
	private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
		ParsingUtils.setPropertyValue(element, builder, "pdx-disk-store", "pdxDiskStoreName");
 
		final String pdxDiskStoreName = element.getAttribute("pdx-disk-store");
 
		if (!StringUtils.isEmpty(pdxDiskStoreName)) {
			registerPdxDiskStoreAwareBeanFactoryPostProcessor(parserContext, pdxDiskStoreName);
		} 
	} 
 
	private void registerPdxDiskStoreAwareBeanFactoryPostProcessor(ParserContext parserContext, String pdxDiskStoreName) {
		BeanDefinitionReaderUtils.registerWithGeneratedName(
			createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(pdxDiskStoreName),
				parserContext.getRegistry());
	} 
 
	private AbstractBeanDefinition createPdxDiskStoreAwareBeanFactoryPostProcessorBeanDefinition(String pdxDiskStoreName) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
			PdxDiskStoreAwareBeanFactoryPostProcessor.class); 
		builder.addConstructorArgValue(pdxDiskStoreName);
		return builder.getBeanDefinition();
	} 
 
	private void parseDynamicRegionFactory(Element element, BeanDefinitionBuilder builder) {
		Element dynamicRegionFactory = DomUtils.getChildElementByTagName(element, "dynamic-region-factory");
 
		if (dynamicRegionFactory != null) {
			BeanDefinitionBuilder dynamicRegionSupport = buildDynamicRegionSupport(dynamicRegionFactory);
			postProcessDynamicRegionSupport(element, dynamicRegionSupport);
			builder.addPropertyValue("dynamicRegionSupport", dynamicRegionSupport.getBeanDefinition());
		} 
	} 
 
	private BeanDefinitionBuilder buildDynamicRegionSupport(Element dynamicRegionFactory) {
		if (dynamicRegionFactory != null) {
			BeanDefinitionBuilder dynamicRegionSupport = BeanDefinitionBuilder.genericBeanDefinition(
				CacheFactoryBean.DynamicRegionSupport.class); 
 
			String diskDirectory = dynamicRegionFactory.getAttribute("disk-dir");