1 18 19 package org.apache.tools.ant.types; 20 21 import java.util.Vector ; 22 import org.apache.tools.ant.BuildException; 23 24 28 public class Environment { 29 31 35 protected Vector variables; 36 37 39 42 public static class Variable { 43 44 48 private String key, value; 49 50 54 public Variable() { 55 super(); 56 } 57 58 62 public void setKey(String key) { 63 this.key = key; 64 } 65 66 70 public void setValue(String value) { 71 this.value = value; 72 } 73 74 78 public String getKey() { 79 return this.key; 80 } 81 82 86 public String getValue() { 87 return this.value; 88 } 89 90 96 public void setPath(Path path) { 97 this.value = path.toString(); 98 } 99 100 104 public void setFile(java.io.File file) { 105 this.value = file.getAbsolutePath(); 106 } 107 108 115 public String getContent() throws BuildException { 116 validate(); 117 StringBuffer sb = new StringBuffer (key.trim()); 118 sb.append("=").append(value.trim()); 119 return sb.toString(); 120 } 121 122 126 public void validate() { 127 if (key == null || value == null) { 128 throw new BuildException("key and value must be specified " 129 + "for environment variables."); 130 } 131 } 132 } 133 134 137 public Environment() { 138 variables = new Vector (); 139 } 140 141 147 public void addVariable(Variable var) { 148 variables.addElement(var); 149 } 150 151 156 public String [] getVariables() throws BuildException { 157 if (variables.size() == 0) { 158 return null; 159 } 160 String [] result = new String [variables.size()]; 161 for (int i = 0; i < result.length; i++) { 162 result[i] = ((Variable) variables.elementAt(i)).getContent(); 163 } 164 return result; 165 } 166 167 173 public Vector getVariablesVector() { 174 return variables; 175 } 176 } 177 | Popular Tags |