KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > extensions > pkgmgr > OptionalPackage


1 /* ====================================================================
2  * Loom Software License, version 1.1
3  *
4  * Copyright (c) 2003, Loom Group. All rights reserved.
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. Neither the name of the Loom Group nor the name "Loom" nor
18  * the names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior
20  * written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * ====================================================================
36  *
37  * Loom includes code from the Apache Software Foundation
38  *
39  * ====================================================================
40  * The Apache Software License, Version 1.1
41  *
42  * Copyright (c) 1997-2003 The Apache Software Foundation. All rights
43  * reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  *
49  * 1. Redistributions of source code must retain the above copyright
50  * notice, this list of conditions and the following disclaimer.
51  *
52  * 2. Redistributions in binary form must reproduce the above copyright
53  * notice, this list of conditions and the following disclaimer in
54  * the documentation and/or other materials provided with the
55  * distribution.
56  *
57  * 3. The end-user documentation included with the redistribution,
58  * if any, must include the following acknowledgment:
59  * "This product includes software developed by the
60  * Apache Software Foundation (http://www.apache.org/)."
61  * Alternately, this acknowledgment may appear in the software
62  * itself, if and wherever such third-party acknowledgments
63  * normally appear.
64  *
65  * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
66  * must not be used to endorse or promote products derived from this
67  * software without prior written permission. For written
68  * permission, please contact apache@apache.org.
69  *
70  * 5. Products derived from this software may not be called "Apache",
71  * nor may "Apache" appear in their name, without prior written
72  * permission of the Apache Software Foundation.
73  *
74  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
75  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
77  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
79  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
80  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
82  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
83  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
84  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85  * SUCH DAMAGE.
86  */

87 package org.codehaus.loom.components.extensions.pkgmgr;
88
89 import java.io.File JavaDoc;
90
91 import org.codehaus.loom.extension.Extension;
92
93 /**
94  * This contains the required meta-data for an "Optional Package" (formerly
95  * known as "Standard Extension") as described in the manifest of a JAR file.
96  *
97  * @author Peter Donald
98  */

99 public final class OptionalPackage
100 {
101     private final File JavaDoc m_file;
102     private final Extension[] m_available;
103     private final Extension[] m_required;
104
105     /**
106      * Convert a list of OptionalPackages into a list of Files.
107      *
108      * @param packages the list of packages
109      * @return the list of files
110      */

111     public static final File JavaDoc[] toFiles( final OptionalPackage[] packages )
112     {
113         final File JavaDoc[] results = new File JavaDoc[ packages.length ];
114
115         for( int i = 0; i < packages.length; i++ )
116         {
117             results[ i ] = packages[ i ].getFile();
118         }
119
120         return results;
121     }
122
123     /**
124      * Constructor for OptionalPackage. No parameter is allowed to be null.
125      *
126      * @param file absolute location of file
127      * @param available the list of Extensions Optional Package provides
128      * @param required the list of Extensions Optional Package requires
129      */

130     public OptionalPackage( final File JavaDoc file,
131                             final Extension[] available,
132                             final Extension[] required )
133     {
134         if( null == file )
135         {
136             throw new NullPointerException JavaDoc( "file" );
137         }
138
139         if( null == available )
140         {
141             throw new NullPointerException JavaDoc( "available" );
142         }
143
144         if( null == required )
145         {
146             throw new NullPointerException JavaDoc( "required" );
147         }
148
149         m_file = file;
150         m_available = available;
151         m_required = required;
152     }
153
154     /**
155      * Return <code>File</code> object in which OptionalPackage is contained.
156      *
157      * @return the file object for OptionalPackage
158      */

159     public File JavaDoc getFile()
160     {
161         return m_file;
162     }
163
164     /**
165      * Return <code>Extension</code>s which OptionalPackage requires to
166      * operate.
167      *
168      * @return the extensions required by OptionalPackage
169      */

170     public Extension[] getRequiredExtensions()
171     {
172         return m_required;
173     }
174
175     /**
176      * Return <code>Extension</code>s which OptionalPackage makes available.
177      *
178      * @return the extensions made available by OptionalPackage
179      */

180     public Extension[] getAvailableExtensions()
181     {
182         return m_available;
183     }
184
185     /**
186      * Return <code>true</code> if any of the available <code>Extension</code>s
187      * are compatible with specified extension. Otherwise return
188      * <code>false</code>.
189      *
190      * @param extension the extension
191      * @return true if compatible, false otherwise
192      */

193     public boolean isCompatible( final Extension extension )
194     {
195         for( int i = 0; i < m_available.length; i++ )
196         {
197             if( m_available[ i ].isCompatibleWith( extension ) )
198             {
199                 return true;
200             }
201         }
202
203         return false;
204     }
205
206     /**
207      * Return a String representation of this object.
208      *
209      * @return the string representation of object
210      */

211     public String JavaDoc toString()
212     {
213         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc( "OptionalPackage[" );
214         sb.append( m_file );
215
216         sb.append( ", Available[" );
217         for( int i = 0; i < m_available.length; i++ )
218         {
219             if( 0 != i )
220             {
221                 sb.append( " " );
222             }
223             sb.append( m_available[ i ].getExtensionName() );
224         }
225
226         sb.append( "], Required[" );
227         for( int i = 0; i < m_required.length; i++ )
228         {
229             if( 0 != i )
230             {
231                 sb.append( " " );
232             }
233             sb.append( m_required[ i ].getExtensionName() );
234         }
235
236         sb.append( "] ]" );
237
238         return sb.toString();
239     }
240 }
241
Popular Tags