X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2Fspring%2FAbstractSpringArg.java;h=6c64235986740357cfff57a52f818b13fabe5ea2;hb=875f97b054c6e996fa2d03c299c83cc80d336b54;hp=86757751bd556d1bd03bb936a5bf04f7198bcdb0;hpb=6e6998e19852f8209f955c0d2c773feca161d4d0;p=gpl%2Fargeo-slc.git
diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java
index 86757751b..6c6423598 100644
--- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java
+++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/spring/AbstractSpringArg.java
@@ -7,8 +7,6 @@ import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.context.ApplicationContext;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.DataType;
import org.argeo.slc.ant.SlcProjectHelper;
@@ -19,6 +17,9 @@ public abstract class AbstractSpringArg extends DataType {
private String bean;
+ // cache bean instance to avoid reading it twice if it is a prototype
+ private Object beanInstance = null;
+
/** The name of the underlying bean, as set throught the attribute. */
public String getBean() {
return bean;
@@ -30,28 +31,30 @@ public abstract class AbstractSpringArg extends DataType {
}
/**
- * Retrieve the instance of the bean. If teh underlying Spring bean is a
- * prototype, it will instanciated each time.
+ * Retrieve the instance of the bean, and sets the overriden properties.
+ * The value is cached.
*/
- protected Object getBeanInstance() {
- Object obj = getContext().getBean(bean);
-
- BeanWrapper wrapper = new BeanWrapperImpl(obj);
- for (OverrideArg override : overrides) {
- wrapper.setPropertyValue(override.getName(), override.getObject());
+ public Object getBeanInstance() {
+ if (beanInstance == null) {
+ beanInstance = getContext().getBean(bean);
+
+ BeanWrapper wrapper = new BeanWrapperImpl(beanInstance);
+ for (OverrideArg override : overrides) {
+ wrapper.setPropertyValue(override.getName(), override
+ .getObject());
+ }
}
-
- return obj;
+ return beanInstance;
}
- /** Creates an override subtag.*/
+ /** Creates an override subtag. */
public OverrideArg createOverride() {
OverrideArg propertyArg = new OverrideArg();
overrides.add(propertyArg);
return propertyArg;
}
- /** The related Spring application context.*/
+ /** The related Spring application context. */
protected ApplicationContext getContext() {
return (ApplicationContext) getProject().getReference(
SlcProjectHelper.REF_ROOT_CONTEXT);