001 /* 002 * Param.java 003 * 004 * Created on October 1, 2002, 11:01 AM 005 */ 006 007 package biz.hammurapi.ant; 008 009 import org.apache.tools.ant.BuildException; 010 011 /** 012 * Parameter 013 * @ant.element name="parameter" 014 * @author Pavel Vlasov 015 * @version $Revision: 1.2 $ 016 */ 017 public class Param extends ObjectEntry { 018 019 private String name=null; 020 021 /** 022 * @ant.ignore 023 * @return 024 */ 025 public String getName() { 026 return name; 027 } 028 029 /** 030 * Parameter name. 031 * @ant.required 032 * @param name 033 */ 034 public void setName(String name) { 035 this.name = name; 036 } 037 038 /** 039 * Reads value from the property. 040 */ 041 private String property=null; 042 043 /** 044 * Property to get value from. Value will not be set if property is not set. 045 * Mutually exclusive with value and className 046 * @ant.non-required 047 * @param name 048 */ 049 public void setProperty(String property) { 050 this.property=property; 051 } 052 053 public Object getObject(ClassLoader masterClassLoader) throws BuildException { 054 if (property!=null) { 055 if (getValue()!=null) { 056 throw new BuildException("property and value attributes are mutually exclusive"); 057 } 058 059 if (getClassName()!=null) { 060 throw new BuildException("property and className attributes are mutually exclusive"); 061 } 062 063 return getProject()==null ? null : getProject().getProperty(property); 064 } 065 return super.getObject(masterClassLoader); 066 } 067 068 public String getProperty() { 069 return property; 070 } 071 072 public void execute() throws BuildException { 073 if (name==null){ 074 throw new BuildException("Name attribute is mandatory"); 075 } 076 077 if (getValue()==null && property==null && getClassName()==null) { 078 throw new BuildException("Either value, property or className must be set"); 079 } 080 } 081 }