KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > extension > manager > OptionalPackage


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

17
18 package org.apache.avalon.extension.manager;
19
20 import java.io.File JavaDoc;
21
22 import org.apache.avalon.extension.Extension;
23
24 /**
25  * This contains the required meta-data for an "Optional Package"
26  * (formerly known as "Standard Extension") as described in the manifest
27  * of a JAR file.
28  *
29  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30  */

31 public final class OptionalPackage
32 {
33     private final File JavaDoc m_file;
34     private final Extension[] m_available;
35     private final Extension[] m_required;
36
37     /**
38      * Convert a list of OptionalPackages into a list of Files.
39      *
40      * @param packages the list of packages
41      * @return the list of files
42      */

43     public static final File JavaDoc[] toFiles( final OptionalPackage[] packages )
44     {
45         final File JavaDoc[] results = new File JavaDoc[ packages.length ];
46
47         for( int i = 0; i < packages.length; i++ )
48         {
49             results[ i ] = packages[ i ].getFile();
50         }
51
52         return results;
53     }
54
55     /**
56      * Constructor for OptionalPackage.
57      * No parameter is allowed to be null.
58      *
59      * @param file absolute location of file
60      * @param available the list of Extensions Optional Package provides
61      * @param required the list of Extensions Optional Package requires
62      */

63     public OptionalPackage( final File JavaDoc file,
64                             final Extension[] available,
65                             final Extension[] required )
66     {
67         if( null == file )
68         {
69             throw new NullPointerException JavaDoc( "file" );
70         }
71
72         if( null == available )
73         {
74             throw new NullPointerException JavaDoc( "available" );
75         }
76
77         if( null == required )
78         {
79             throw new NullPointerException JavaDoc( "required" );
80         }
81
82         m_file = file;
83         m_available = available;
84         m_required = required;
85     }
86
87     /**
88      * Return <code>File</code> object in which OptionalPackage
89      * is contained.
90      *
91      * @return the file object for OptionalPackage
92      */

93     public File JavaDoc getFile()
94     {
95         return m_file;
96     }
97
98     /**
99      * Return <code>Extension</code>s which OptionalPackage
100      * requires to operate.
101      *
102      * @return the extensions required by OptionalPackage
103      */

104     public Extension[] getRequiredExtensions()
105     {
106         return m_required;
107     }
108
109     /**
110      * Return <code>Extension</code>s which OptionalPackage
111      * makes available.
112      *
113      * @return the extensions made available by OptionalPackage
114      */

115     public Extension[] getAvailableExtensions()
116     {
117         return m_available;
118     }
119
120     /**
121      * Return <code>true</code> if any of the available <code>Extension</code>s
122      * are compatible with specified extension. Otherwise return <code>false</code>.
123      *
124      * @param extension the extension
125      * @return true if compatible, false otherwise
126      */

127     public boolean isCompatible( final Extension extension )
128     {
129         for( int i = 0; i < m_available.length; i++ )
130         {
131             if( m_available[ i ].isCompatibleWith( extension ) )
132             {
133                 return true;
134             }
135         }
136
137         return false;
138     }
139
140     /**
141      * Return a String representation of this object.
142      *
143      * @return the string representation of object
144      */

145     public String JavaDoc toString()
146     {
147         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc( "OptionalPackage[" );
148         sb.append( m_file );
149
150         sb.append( ", Available[" );
151         for( int i = 0; i < m_available.length; i++ )
152         {
153             if( 0 != i )
154             {
155                 sb.append( " " );
156             }
157             sb.append( m_available[ i ].getExtensionName() );
158         }
159
160         sb.append( "], Required[" );
161         for( int i = 0; i < m_required.length; i++ )
162         {
163             if( 0 != i )
164             {
165                 sb.append( " " );
166             }
167             sb.append( m_required[ i ].getExtensionName() );
168         }
169
170         sb.append( "] ]" );
171
172         return sb.toString();
173     }
174 }
175
Popular Tags