01: /*
02: * Param.java
03: *
04: * Created on October 1, 2002, 11:01 AM
05: */
06:
07: package biz.hammurapi.ant;
08:
09: import org.apache.tools.ant.BuildException;
10:
11: /**
12: * Parameter
13: * @ant.element name="parameter"
14: * @author Pavel Vlasov
15: * @version $Revision: 1.2 $
16: */
17: public class Param extends ObjectEntry {
18:
19: private String name = null;
20:
21: /**
22: * @ant.ignore
23: * @return
24: */
25: public String getName() {
26: return name;
27: }
28:
29: /**
30: * Parameter name.
31: * @ant.required
32: * @param name
33: */
34: public void setName(String name) {
35: this .name = name;
36: }
37:
38: /**
39: * Reads value from the property.
40: */
41: private String property = null;
42:
43: /**
44: * Property to get value from. Value will not be set if property is not set.
45: * Mutually exclusive with value and className
46: * @ant.non-required
47: * @param name
48: */
49: public void setProperty(String property) {
50: this .property = property;
51: }
52:
53: public Object getObject(ClassLoader masterClassLoader)
54: throws BuildException {
55: if (property != null) {
56: if (getValue() != null) {
57: throw new BuildException(
58: "property and value attributes are mutually exclusive");
59: }
60:
61: if (getClassName() != null) {
62: throw new BuildException(
63: "property and className attributes are mutually exclusive");
64: }
65:
66: return getProject() == null ? null : getProject()
67: .getProperty(property);
68: }
69: return super .getObject(masterClassLoader);
70: }
71:
72: public String getProperty() {
73: return property;
74: }
75:
76: public void execute() throws BuildException {
77: if (name == null) {
78: throw new BuildException("Name attribute is mandatory");
79: }
80:
81: if (getValue() == null && property == null
82: && getClassName() == null) {
83: throw new BuildException(
84: "Either value, property or className must be set");
85: }
86: }
87: }
|