001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.taskdefs.optional.extension;
019:
020: import org.apache.tools.ant.BuildException;
021: import org.apache.tools.ant.types.DataType;
022: import org.apache.tools.ant.types.Reference;
023:
024: /**
025: * Simple class that represents an Extension and conforms to Ants
026: * patterns.
027: *
028: * @ant.datatype name="extension"
029: */
030: public class ExtensionAdapter extends DataType {
031: /**
032: * The name of the optional package being made available, or required.
033: */
034: private String extensionName;
035:
036: /**
037: * The version number (dotted decimal notation) of the specification
038: * to which this optional package conforms.
039: */
040: private DeweyDecimal specificationVersion;
041:
042: /**
043: * The name of the company or organization that originated the
044: * specification to which this optional package conforms.
045: */
046: private String specificationVendor;
047:
048: /**
049: * The unique identifier of the company that produced the optional
050: * package contained in this JAR file.
051: */
052: private String implementationVendorID;
053:
054: /**
055: * The name of the company or organization that produced this
056: * implementation of this optional package.
057: */
058: private String implementationVendor;
059:
060: /**
061: * The version number (dotted decimal notation) for this implementation
062: * of the optional package.
063: */
064: private DeweyDecimal implementationVersion;
065:
066: /**
067: * The URL from which the most recent version of this optional package
068: * can be obtained if it is not already installed.
069: */
070: private String implementationURL;
071:
072: /**
073: * Set the name of extension.
074: *
075: * @param extensionName the name of extension
076: */
077: public void setExtensionName(final String extensionName) {
078: verifyNotAReference();
079: this .extensionName = extensionName;
080: }
081:
082: /**
083: * Set the specificationVersion of extension.
084: *
085: * @param specificationVersion the specificationVersion of extension
086: */
087: public void setSpecificationVersion(
088: final String specificationVersion) {
089: verifyNotAReference();
090: this .specificationVersion = new DeweyDecimal(
091: specificationVersion);
092: }
093:
094: /**
095: * Set the specificationVendor of extension.
096: *
097: * @param specificationVendor the specificationVendor of extension
098: */
099: public void setSpecificationVendor(final String specificationVendor) {
100: verifyNotAReference();
101: this .specificationVendor = specificationVendor;
102: }
103:
104: /**
105: * Set the implementationVendorID of extension.
106: *
107: * @param implementationVendorID the implementationVendorID of extension
108: */
109: public void setImplementationVendorId(
110: final String implementationVendorID) {
111: verifyNotAReference();
112: this .implementationVendorID = implementationVendorID;
113: }
114:
115: /**
116: * Set the implementationVendor of extension.
117: *
118: * @param implementationVendor the implementationVendor of extension
119: */
120: public void setImplementationVendor(
121: final String implementationVendor) {
122: verifyNotAReference();
123: this .implementationVendor = implementationVendor;
124: }
125:
126: /**
127: * Set the implementationVersion of extension.
128: *
129: * @param implementationVersion the implementationVersion of extension
130: */
131: public void setImplementationVersion(
132: final String implementationVersion) {
133: verifyNotAReference();
134: this .implementationVersion = new DeweyDecimal(
135: implementationVersion);
136: }
137:
138: /**
139: * Set the implementationURL of extension.
140: *
141: * @param implementationURL the implementationURL of extension
142: */
143: public void setImplementationUrl(final String implementationURL) {
144: verifyNotAReference();
145: this .implementationURL = implementationURL;
146: }
147:
148: /**
149: * Makes this instance in effect a reference to another ExtensionAdapter
150: * instance.
151: *
152: * <p>You must not set another attribute or nest elements inside
153: * this element if you make it a reference.</p>
154: *
155: * @param reference the reference to which this instance is associated
156: * @exception BuildException if this instance already has been configured.
157: */
158: public void setRefid(final Reference reference)
159: throws BuildException {
160: if (null != extensionName || null != specificationVersion
161: || null != specificationVendor
162: || null != implementationVersion
163: || null != implementationVendorID
164: || null != implementationVendor
165: || null != implementationURL) {
166: throw tooManyAttributes();
167: }
168: // change this to get the objects from the other reference
169: Object o = reference.getReferencedObject(getProject());
170: if (o instanceof ExtensionAdapter) {
171: final ExtensionAdapter other = (ExtensionAdapter) o;
172: extensionName = other.extensionName;
173: specificationVersion = other.specificationVersion;
174: specificationVendor = other.specificationVendor;
175: implementationVersion = other.implementationVersion;
176: implementationVendorID = other.implementationVendorID;
177: implementationVendor = other.implementationVendor;
178: implementationURL = other.implementationURL;
179: } else {
180: final String message = reference.getRefId()
181: + " doesn\'t refer to a Extension";
182: throw new BuildException(message);
183: }
184:
185: super .setRefid(reference);
186: }
187:
188: private void verifyNotAReference() throws BuildException {
189: if (isReference()) {
190: throw tooManyAttributes();
191: }
192: }
193:
194: /**
195: * Convert this adpater object into an extension object.
196: *
197: * @return the extension object
198: */
199: Extension toExtension() throws BuildException {
200: if (null == extensionName) {
201: final String message = "Extension is missing name.";
202: throw new BuildException(message);
203: }
204:
205: String specificationVersionString = null;
206: if (null != specificationVersion) {
207: specificationVersionString = specificationVersion
208: .toString();
209: }
210: String implementationVersionString = null;
211: if (null != implementationVersion) {
212: implementationVersionString = implementationVersion
213: .toString();
214: }
215: return new Extension(extensionName, specificationVersionString,
216: specificationVendor, implementationVersionString,
217: implementationVendor, implementationVendorID,
218: implementationURL);
219: }
220:
221: /**
222: * a debug toString method.
223: * @return the extension in a string.
224: * @see java.lang.Object#toString()
225: */
226: public String toString() {
227: return "{" + toExtension().toString() + "}";
228: }
229: }
|