]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc/src/main/java/org/argeo/slc/ant/spring/OverrideArg.java
Introduce directory based structure
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / spring / OverrideArg.java
1 package org.argeo.slc.ant.spring;
2
3 import org.apache.tools.ant.BuildException;
4
5 /** Ant type allowing to override bean properties. */
6 public class OverrideArg extends AbstractSpringArg {
7 private String name;
8 private Object value;
9
10 /** The nbame of the property to override. */
11 public String getName() {
12 return name;
13 }
14
15 public void setName(String name) {
16 this.name = name;
17 }
18
19 /** Both value and bean cannot be set. */
20 public void setValue(String value) {
21 if (getBean() != null) {
22 throw new BuildException(
23 "Cannot set both 'bean' and 'value' attributes.");
24 }
25 this.value = value;
26 }
27
28 @Override
29 public void setBean(String bean) {
30 if (value != null) {
31 throw new BuildException(
32 "Cannot set both 'bean' and 'value' attributes.");
33 }
34 super.setBean(bean);
35 }
36
37 /**
38 * The related object: the value if a value had been set or an instance of
39 * the bean if not.
40 */
41 public Object getObject() {
42 if (value != null) {
43 return value;
44 } else if (getBean() != null) {
45 return getBeanInstance();
46 } else {
47 throw new BuildException("Value or bean not set.");
48 }
49 }
50
51 }