KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.types.DataType;
25 import org.apache.tools.ant.types.FileSet;
26 import org.apache.tools.ant.types.Reference;
27
28 /**
29  * The Extension set lists a set of "Optional Packages" /
30  * "Extensions".
31  *
32  * @ant.datatype name="extension-set"
33  */

34 public class ExtensionSet
35     extends DataType {
36     /**
37      * ExtensionAdapter objects representing extensions.
38      */

39     private final ArrayList JavaDoc extensions = new ArrayList JavaDoc();
40
41     /**
42      * Filesets specifying all the extensions wanted.
43      */

44     private final ArrayList JavaDoc extensionsFilesets = new ArrayList JavaDoc();
45
46     /**
47      * Adds an extension that this library requires.
48      *
49      * @param extensionAdapter an extension that this library requires.
50      */

51     public void addExtension(final ExtensionAdapter extensionAdapter) {
52         extensions.add(extensionAdapter);
53     }
54
55     /**
56      * Adds a set of files about which extensions data will be extracted.
57      *
58      * @param fileSet a set of files about which extensions data will be extracted.
59      */

60     public void addLibfileset(final LibFileSet fileSet) {
61         extensionsFilesets.add(fileSet);
62     }
63
64     /**
65      * Adds a set of files about which extensions data will be extracted.
66      *
67      * @param fileSet a set of files about which extensions data will be extracted.
68      */

69     public void addFileset(final FileSet fileSet) {
70         extensionsFilesets.add(fileSet);
71     }
72
73     /**
74      * Extract a set of Extension objects from the ExtensionSet.
75      *
76      * @param proj the project instance.
77      * @return an array containing the Extensions from this set
78      * @throws BuildException if an error occurs
79      */

80     public Extension[] toExtensions(final Project proj)
81         throws BuildException {
82         final ArrayList JavaDoc extensionsList = ExtensionUtil.toExtensions(extensions);
83         ExtensionUtil.extractExtensions(proj, extensionsList, extensionsFilesets);
84         return (Extension[]) extensionsList.toArray(new Extension[extensionsList.size()]);
85     }
86
87     /**
88      * Makes this instance in effect a reference to another ExtensionSet
89      * instance.
90      *
91      * <p>You must not set another attribute or nest elements inside
92      * this element if you make it a reference.</p>
93      *
94      * @param reference the reference to which this instance is associated
95      * @exception BuildException if this instance already has been configured.
96      */

97     public void setRefid(final Reference reference)
98         throws BuildException {
99         if (!extensions.isEmpty() || !extensionsFilesets.isEmpty()) {
100             throw tooManyAttributes();
101         }
102         // change this to get the objects from the other reference
103
final Object JavaDoc object =
104             reference.getReferencedObject(getProject());
105         if (object instanceof ExtensionSet) {
106             final ExtensionSet other = (ExtensionSet) object;
107             extensions.addAll(other.extensions);
108             extensionsFilesets.addAll(other.extensionsFilesets);
109         } else {
110             final String JavaDoc message =
111                 reference.getRefId() + " doesn\'t refer to a ExtensionSet";
112             throw new BuildException(message);
113         }
114
115         super.setRefid(reference);
116     }
117
118     /**
119      * @see java.lang.Object#toString()
120      * @return the extensions in a string.
121      */

122     public String JavaDoc toString() {
123         return "ExtensionSet" + Arrays.asList(toExtensions(getProject()));
124     }
125 }
126
Popular Tags