KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > extension > ExtensionAdapter


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

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 /**
25  * Simple class that represents an Extension and conforms to Ants
26  * patterns.
27  *
28  * @ant.datatype name="extension"
29  */

30 public class ExtensionAdapter extends DataType {
31     /**
32      * The name of the optional package being made available, or required.
33      */

34     private String JavaDoc extensionName;
35
36     /**
37      * The version number (dotted decimal notation) of the specification
38      * to which this optional package conforms.
39      */

40     private DeweyDecimal specificationVersion;
41
42     /**
43      * The name of the company or organization that originated the
44      * specification to which this optional package conforms.
45      */

46     private String JavaDoc specificationVendor;
47
48     /**
49      * The unique identifier of the company that produced the optional
50      * package contained in this JAR file.
51      */

52     private String JavaDoc implementationVendorID;
53
54     /**
55      * The name of the company or organization that produced this
56      * implementation of this optional package.
57      */

58     private String JavaDoc implementationVendor;
59
60     /**
61      * The version number (dotted decimal notation) for this implementation
62      * of the optional package.
63      */

64     private DeweyDecimal implementationVersion;
65
66     /**
67      * The URL from which the most recent version of this optional package
68      * can be obtained if it is not already installed.
69      */

70     private String JavaDoc implementationURL;
71
72     /**
73      * Set the name of extension.
74      *
75      * @param extensionName the name of extension
76      */

77     public void setExtensionName(final String JavaDoc extensionName) {
78         verifyNotAReference();
79         this.extensionName = extensionName;
80     }
81
82     /**
83      * Set the specificationVersion of extension.
84      *
85      * @param specificationVersion the specificationVersion of extension
86      */

87     public void setSpecificationVersion(final String JavaDoc specificationVersion) {
88         verifyNotAReference();
89         this.specificationVersion = new DeweyDecimal(specificationVersion);
90     }
91
92     /**
93      * Set the specificationVendor of extension.
94      *
95      * @param specificationVendor the specificationVendor of extension
96      */

97     public void setSpecificationVendor(final String JavaDoc specificationVendor) {
98         verifyNotAReference();
99         this.specificationVendor = specificationVendor;
100     }
101
102     /**
103      * Set the implementationVendorID of extension.
104      *
105      * @param implementationVendorID the implementationVendorID of extension
106      */

107     public void setImplementationVendorId(final String JavaDoc implementationVendorID) {
108         verifyNotAReference();
109         this.implementationVendorID = implementationVendorID;
110     }
111
112     /**
113      * Set the implementationVendor of extension.
114      *
115      * @param implementationVendor the implementationVendor of extension
116      */

117     public void setImplementationVendor(final String JavaDoc implementationVendor) {
118         verifyNotAReference();
119         this.implementationVendor = implementationVendor;
120     }
121
122     /**
123      * Set the implementationVersion of extension.
124      *
125      * @param implementationVersion the implementationVersion of extension
126      */

127     public void setImplementationVersion(final String JavaDoc implementationVersion) {
128         verifyNotAReference();
129         this.implementationVersion = new DeweyDecimal(implementationVersion);
130     }
131
132     /**
133      * Set the implementationURL of extension.
134      *
135      * @param implementationURL the implementationURL of extension
136      */

137     public void setImplementationUrl(final String JavaDoc implementationURL) {
138         verifyNotAReference();
139         this.implementationURL = implementationURL;
140     }
141
142     /**
143      * Makes this instance in effect a reference to another ExtensionAdapter
144      * instance.
145      *
146      * <p>You must not set another attribute or nest elements inside
147      * this element if you make it a reference.</p>
148      *
149      * @param reference the reference to which this instance is associated
150      * @exception BuildException if this instance already has been configured.
151      */

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         // change this to get the objects from the other reference
164
Object JavaDoc 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 JavaDoc 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     /**
191      * Convert this adpater object into an extension object.
192      *
193      * @return the extension object
194      */

195     Extension toExtension()
196         throws BuildException {
197         if (null == extensionName) {
198             final String JavaDoc message = "Extension is missing name.";
199             throw new BuildException(message);
200         }
201
202         String JavaDoc specificationVersionString = null;
203         if (null != specificationVersion) {
204             specificationVersionString = specificationVersion.toString();
205         }
206         String JavaDoc 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     /**
220      * a debug toString method.
221      * @return the extension in a string.
222      * @see java.lang.Object#toString()
223      */

224     public String JavaDoc toString() {
225         return "{" + toExtension().toString() + "}";
226     }
227 }
228
Popular Tags