1 18 package org.apache.tools.ant.taskdefs.optional.extension; 19 20 import org.apache.tools.ant.BuildException; 21 import org.apache.tools.ant.types.DataType; 22 import org.apache.tools.ant.types.Reference; 23 24 30 public class ExtensionAdapter extends DataType { 31 34 private String extensionName; 35 36 40 private DeweyDecimal specificationVersion; 41 42 46 private String specificationVendor; 47 48 52 private String implementationVendorID; 53 54 58 private String implementationVendor; 59 60 64 private DeweyDecimal implementationVersion; 65 66 70 private String implementationURL; 71 72 77 public void setExtensionName(final String extensionName) { 78 verifyNotAReference(); 79 this.extensionName = extensionName; 80 } 81 82 87 public void setSpecificationVersion(final String specificationVersion) { 88 verifyNotAReference(); 89 this.specificationVersion = new DeweyDecimal(specificationVersion); 90 } 91 92 97 public void setSpecificationVendor(final String specificationVendor) { 98 verifyNotAReference(); 99 this.specificationVendor = specificationVendor; 100 } 101 102 107 public void setImplementationVendorId(final String implementationVendorID) { 108 verifyNotAReference(); 109 this.implementationVendorID = implementationVendorID; 110 } 111 112 117 public void setImplementationVendor(final String implementationVendor) { 118 verifyNotAReference(); 119 this.implementationVendor = implementationVendor; 120 } 121 122 127 public void setImplementationVersion(final String implementationVersion) { 128 verifyNotAReference(); 129 this.implementationVersion = new DeweyDecimal(implementationVersion); 130 } 131 132 137 public void setImplementationUrl(final String implementationURL) { 138 verifyNotAReference(); 139 this.implementationURL = implementationURL; 140 } 141 142 152 public void setRefid(final Reference reference) 153 throws BuildException { 154 if (null != extensionName 155 || null != specificationVersion 156 || null != specificationVendor 157 || null != implementationVersion 158 || null != implementationVendorID 159 || null != implementationVendor 160 || null != implementationURL) { 161 throw tooManyAttributes(); 162 } 163 Object o = reference.getReferencedObject(getProject()); 165 if (o instanceof ExtensionAdapter) { 166 final ExtensionAdapter other = (ExtensionAdapter) o; 167 extensionName = other.extensionName; 168 specificationVersion = other.specificationVersion; 169 specificationVendor = other.specificationVendor; 170 implementationVersion = other.implementationVersion; 171 implementationVendorID = other.implementationVendorID; 172 implementationVendor = other.implementationVendor; 173 implementationURL = other.implementationURL; 174 } else { 175 final String message = 176 reference.getRefId() + " doesn\'t refer to a Extension"; 177 throw new BuildException(message); 178 } 179 180 super.setRefid(reference); 181 } 182 183 private void verifyNotAReference() 184 throws BuildException { 185 if (isReference()) { 186 throw tooManyAttributes(); 187 } 188 } 189 190 195 Extension toExtension() 196 throws BuildException { 197 if (null == extensionName) { 198 final String message = "Extension is missing name."; 199 throw new BuildException(message); 200 } 201 202 String specificationVersionString = null; 203 if (null != specificationVersion) { 204 specificationVersionString = specificationVersion.toString(); 205 } 206 String implementationVersionString = null; 207 if (null != implementationVersion) { 208 implementationVersionString = implementationVersion.toString(); 209 } 210 return new Extension(extensionName, 211 specificationVersionString, 212 specificationVendor, 213 implementationVersionString, 214 implementationVendor, 215 implementationVendorID, 216 implementationURL); 217 } 218 219 224 public String toString() { 225 return "{" + toExtension().toString() + "}"; 226 } 227 } 228 | Popular Tags |