1 | /*
|
---|
2 | * Copyright 2002-2005 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.extension;
|
---|
18 |
|
---|
19 | import org.apache.tools.ant.BuildException;
|
---|
20 | import org.apache.tools.ant.types.DataType;
|
---|
21 | import org.apache.tools.ant.types.Reference;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Simple class that represents an Extension and conforms to Ants
|
---|
25 | * patterns.
|
---|
26 | *
|
---|
27 | * @ant.data-type name="extension"
|
---|
28 | */
|
---|
29 | public class ExtensionAdapter extends DataType {
|
---|
30 | /**
|
---|
31 | * The name of the optional package being made available, or required.
|
---|
32 | */
|
---|
33 | private String extensionName;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The version number (dotted decimal notation) of the specification
|
---|
37 | * to which this optional package conforms.
|
---|
38 | */
|
---|
39 | private DeweyDecimal specificationVersion;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The name of the company or organization that originated the
|
---|
43 | * specification to which this optional package conforms.
|
---|
44 | */
|
---|
45 | private String specificationVendor;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * The unique identifier of the company that produced the optional
|
---|
49 | * package contained in this JAR file.
|
---|
50 | */
|
---|
51 | private String implementationVendorID;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * The name of the company or organization that produced this
|
---|
55 | * implementation of this optional package.
|
---|
56 | */
|
---|
57 | private String implementationVendor;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * The version number (dotted decimal notation) for this implementation
|
---|
61 | * of the optional package.
|
---|
62 | */
|
---|
63 | private DeweyDecimal implementationVersion;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * The URL from which the most recent version of this optional package
|
---|
67 | * can be obtained if it is not already installed.
|
---|
68 | */
|
---|
69 | private String implementationURL;
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Set the name of extension.
|
---|
73 | *
|
---|
74 | * @param extensionName the name of extension
|
---|
75 | */
|
---|
76 | public void setExtensionName(final String extensionName) {
|
---|
77 | verifyNotAReference();
|
---|
78 | this.extensionName = extensionName;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Set the specificationVersion of extension.
|
---|
83 | *
|
---|
84 | * @param specificationVersion the specificationVersion of extension
|
---|
85 | */
|
---|
86 | public void setSpecificationVersion(final String specificationVersion) {
|
---|
87 | verifyNotAReference();
|
---|
88 | this.specificationVersion = new DeweyDecimal(specificationVersion);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Set the specificationVendor of extension.
|
---|
93 | *
|
---|
94 | * @param specificationVendor the specificationVendor of extension
|
---|
95 | */
|
---|
96 | public void setSpecificationVendor(final String specificationVendor) {
|
---|
97 | verifyNotAReference();
|
---|
98 | this.specificationVendor = specificationVendor;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Set the implementationVendorID of extension.
|
---|
103 | *
|
---|
104 | * @param implementationVendorID the implementationVendorID of extension
|
---|
105 | */
|
---|
106 | public void setImplementationVendorId(final String implementationVendorID) {
|
---|
107 | verifyNotAReference();
|
---|
108 | this.implementationVendorID = implementationVendorID;
|
---|
109 | }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Set the implementationVendor of extension.
|
---|
113 | *
|
---|
114 | * @param implementationVendor the implementationVendor of extension
|
---|
115 | */
|
---|
116 | public void setImplementationVendor(final String implementationVendor) {
|
---|
117 | verifyNotAReference();
|
---|
118 | this.implementationVendor = implementationVendor;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Set the implementationVersion of extension.
|
---|
123 | *
|
---|
124 | * @param implementationVersion the implementationVersion of extension
|
---|
125 | */
|
---|
126 | public void setImplementationVersion(final String implementationVersion) {
|
---|
127 | verifyNotAReference();
|
---|
128 | this.implementationVersion = new DeweyDecimal(implementationVersion);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Set the implementationURL of extension.
|
---|
133 | *
|
---|
134 | * @param implementationURL the implementationURL of extension
|
---|
135 | */
|
---|
136 | public void setImplementationUrl(final String implementationURL) {
|
---|
137 | verifyNotAReference();
|
---|
138 | this.implementationURL = implementationURL;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Makes this instance in effect a reference to another ExtensionAdapter
|
---|
143 | * instance.
|
---|
144 | *
|
---|
145 | * <p>You must not set another attribute or nest elements inside
|
---|
146 | * this element if you make it a reference.</p>
|
---|
147 | *
|
---|
148 | * @param reference the reference to which this instance is associated
|
---|
149 | * @exception BuildException if this instance already has been configured.
|
---|
150 | */
|
---|
151 | public void setRefid(final Reference reference)
|
---|
152 | throws BuildException {
|
---|
153 | if (null != extensionName
|
---|
154 | || null != specificationVersion
|
---|
155 | || null != specificationVendor
|
---|
156 | || null != implementationVersion
|
---|
157 | || null != implementationVendorID
|
---|
158 | || null != implementationVendor
|
---|
159 | || null != implementationURL) {
|
---|
160 | throw tooManyAttributes();
|
---|
161 | }
|
---|
162 | // change this to get the objects from the other reference
|
---|
163 | Object o = reference.getReferencedObject(getProject());
|
---|
164 | if (o instanceof ExtensionAdapter) {
|
---|
165 | final ExtensionAdapter other = (ExtensionAdapter) o;
|
---|
166 | extensionName = other.extensionName;
|
---|
167 | specificationVersion = other.specificationVersion;
|
---|
168 | specificationVendor = other.specificationVendor;
|
---|
169 | implementationVersion = other.implementationVersion;
|
---|
170 | implementationVendorID = other.implementationVendorID;
|
---|
171 | implementationVendor = other.implementationVendor;
|
---|
172 | implementationURL = other.implementationURL;
|
---|
173 | } else {
|
---|
174 | final String message =
|
---|
175 | reference.getRefId() + " doesn\'t refer to a Extension";
|
---|
176 | throw new BuildException(message);
|
---|
177 | }
|
---|
178 |
|
---|
179 | super.setRefid(reference);
|
---|
180 | }
|
---|
181 |
|
---|
182 | private void verifyNotAReference()
|
---|
183 | throws BuildException {
|
---|
184 | if (isReference()) {
|
---|
185 | throw tooManyAttributes();
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Convert this adpater object into an extension object.
|
---|
191 | *
|
---|
192 | * @return the extension object
|
---|
193 | */
|
---|
194 | Extension toExtension()
|
---|
195 | throws BuildException {
|
---|
196 | if (null == extensionName) {
|
---|
197 | final String message = "Extension is missing name.";
|
---|
198 | throw new BuildException(message);
|
---|
199 | }
|
---|
200 |
|
---|
201 | String specificationVersionString = null;
|
---|
202 | if (null != specificationVersion) {
|
---|
203 | specificationVersionString = specificationVersion.toString();
|
---|
204 | }
|
---|
205 | String implementationVersionString = null;
|
---|
206 | if (null != implementationVersion) {
|
---|
207 | implementationVersionString = implementationVersion.toString();
|
---|
208 | }
|
---|
209 | return new Extension(extensionName,
|
---|
210 | specificationVersionString,
|
---|
211 | specificationVendor,
|
---|
212 | implementationVersionString,
|
---|
213 | implementationVendor,
|
---|
214 | implementationVendorID,
|
---|
215 | implementationURL);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * @see java.lang.Object#toString()
|
---|
220 | */
|
---|
221 | public String toString() {
|
---|
222 | return "{" + toExtension().toString() + "}";
|
---|
223 | }
|
---|
224 | }
|
---|