DATACMNS-461 - Refactorings in auditing configuration support.
Cleaned up configuration setup. AuditingBeanDefinitionRegistrarSupport now exposes a getAuditingHandlerBeanName() method to determine the bean name to be used for the AuditingHandler.
This commit is contained in:
@@ -63,6 +63,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
String auditorAwareRef = element.getAttribute(AUDITOR_AWARE_REF);
|
||||
|
||||
if (StringUtils.hasText(auditorAwareRef)) {
|
||||
builder.addPropertyValue("auditorAware", createLazyInitTargetSourceBeanDefinition(auditorAwareRef));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.config;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.auditing.IsNewAwareAuditingHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.w3c.dom.Element;
|
||||
@@ -29,6 +32,7 @@ import org.w3c.dom.Element;
|
||||
public class IsNewAwareAuditingHandlerBeanDefinitionParser extends AuditingHandlerBeanDefinitionParser {
|
||||
|
||||
private final String isNewStrategyFactoryBeanId;
|
||||
private String resolvedBeanName;
|
||||
|
||||
/**
|
||||
* Creates a new {@link IsNewAwareAuditingHandlerBeanDefinitionParser}.
|
||||
@@ -41,6 +45,15 @@ public class IsNewAwareAuditingHandlerBeanDefinitionParser extends AuditingHandl
|
||||
this.isNewStrategyFactoryBeanId = isNewStrategyFactoryBeanId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bean name that was used to register the {@link IsNewAwareAuditingHandler}.
|
||||
*
|
||||
* @return the resolvedBeanName
|
||||
*/
|
||||
public String getResolvedBeanName() {
|
||||
return resolvedBeanName;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.config.AuditingHandlerBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
@@ -58,7 +71,18 @@ public class IsNewAwareAuditingHandlerBeanDefinitionParser extends AuditingHandl
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
builder.addConstructorArgReference(isNewStrategyFactoryBeanId);
|
||||
|
||||
super.doParse(element, builder);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#resolveId(org.w3c.dom.Element, org.springframework.beans.factory.support.AbstractBeanDefinition, org.springframework.beans.factory.xml.ParserContext)
|
||||
*/
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
|
||||
this.resolvedBeanName = super.resolveId(element, definition, parserContext);
|
||||
return resolvedBeanName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.config;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
@@ -127,4 +128,23 @@ public abstract class ParsingUtils {
|
||||
definition.setSource(source);
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link BeanDefinition} for an {@link ObjectFactoryCreatingFactoryBean} pointing to the bean with the
|
||||
* given name.
|
||||
*
|
||||
* @param targetBeanName must not be {@literal null} or empty.
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static AbstractBeanDefinition getObjectFactoryBeanDefinition(String targetBeanName, Object source) {
|
||||
|
||||
Assert.hasText(targetBeanName, "Target bean name must not be null or empty!");
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ObjectFactoryCreatingFactoryBean.class);
|
||||
builder.addPropertyValue("targetBeanName", targetBeanName);
|
||||
builder.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
|
||||
return getSourceBeanDefinition(builder, source);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user