]>
git.argeo.org Git - gpl/argeo-slc.git/blob - spring/AbstractSpringArg.java
1 package org
.argeo
.slc
.ant
.spring
;
4 import java
.util
.Vector
;
6 import org
.springframework
.beans
.BeanWrapper
;
7 import org
.springframework
.beans
.BeanWrapperImpl
;
8 import org
.springframework
.context
.ApplicationContext
;
10 import org
.apache
.tools
.ant
.types
.DataType
;
12 import org
.argeo
.slc
.ant
.SlcProjectHelper
;
14 /** Abstract Ant type wrapping a Spring bean. */
15 public abstract class AbstractSpringArg
extends DataType
{
16 private List
<OverrideArg
> overrides
= new Vector
<OverrideArg
>();
20 // cache bean instance to avoid reading it twice if it is a prototype
21 private Object beanInstance
= null;
23 /** The <u>name</u> of the underlying bean, as set throught the attribute. */
24 public String
getBean() {
28 /** Setter for the bean name. */
29 public void setBean(String bean
) {
34 * Retrieve the instance of the bean. <b>The value is cached.</b>
36 public Object
getBeanInstance() {
37 if (beanInstance
== null) {
38 beanInstance
= getContext().getBean(bean
);
40 BeanWrapper wrapper
= new BeanWrapperImpl(beanInstance
);
41 for (OverrideArg override
: overrides
) {
42 wrapper
.setPropertyValue(override
.getName(), override
49 /** Creates an override subtag. */
50 public OverrideArg
createOverride() {
51 OverrideArg propertyArg
= new OverrideArg();
52 overrides
.add(propertyArg
);
56 /** The related Spring application context. */
57 protected ApplicationContext
getContext() {
58 return (ApplicationContext
) getProject().getReference(
59 SlcProjectHelper
.REF_ROOT_CONTEXT
);