KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.extension;
9
10 import java.io.File JavaDoc;
11
12 /**
13  * This contains the required meta-data for an "Optional Package"
14  * (formerly known as "Standard Extension") as described in the manifest
15  * of a JAR file.
16  *
17  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
18  */

19 public final class OptionalPackage
20 {
21     private final File JavaDoc m_file;
22     private final Extension[] m_available;
23     private final Extension[] m_required;
24
25     /**
26      * Convert a list of OptionalPackages into a list of Files.
27      *
28      * @param packages the list of packages
29      * @return the list of files
30      */

31     public static final File JavaDoc[] toFiles( final OptionalPackage[] packages )
32     {
33         final File JavaDoc[] results = new File JavaDoc[ packages.length ];
34
35         for( int i = 0; i < packages.length; i++ )
36         {
37             results[ i ] = packages[ i ].getFile();
38         }
39
40         return results;
41     }
42
43     /**
44      * Constructor for OptionalPackage.
45      * No parameter is allowed to be null.
46      *
47      * @param file absolute location of file
48      * @param available the list of Extensions Optional Package provides
49      * @param required the list of Extensions Optional Package requires
50      */

51     public OptionalPackage( final File JavaDoc file,
52                             final Extension[] available,
53                             final Extension[] required )
54     {
55         if( null == file )
56         {
57             throw new NullPointerException JavaDoc( "file property is null" );
58         }
59
60         if( null == available )
61         {
62             throw new NullPointerException JavaDoc( "available property is null" );
63         }
64
65         if( null == required )
66         {
67             throw new NullPointerException JavaDoc( "required property is null" );
68         }
69
70         m_file = file;
71         m_available = available;
72         m_required = required;
73     }
74
75     /**
76      * Return <code>File</code> object in which OptionalPackage
77      * is contained.
78      *
79      * @return the file object for OptionalPackage
80      */

81     public File JavaDoc getFile()
82     {
83         return m_file;
84     }
85
86     /**
87      * Return <code>Extension</code>s which OptionalPackage
88      * requires to operate.
89      *
90      * @return the extensions required by OptionalPackage
91      */

92     public Extension[] getRequiredExtensions()
93     {
94         return m_required;
95     }
96
97     /**
98      * Return <code>Extension</code>s which OptionalPackage
99      * makes available.
100      *
101      * @return the extensions made available by OptionalPackage
102      */

103     public Extension[] getAvailableExtensions()
104     {
105         return m_available;
106     }
107
108     /**
109      * Return <code>true</code> if any of the available <code>Extension</code>s
110      * are compatible with specified extension. Otherwise return <code>false</code>.
111      *
112      * @param extension the extension
113      * @return true if compatible, false otherwise
114      */

115     public boolean isCompatible( final Extension extension )
116     {
117         for( int i = 0; i < m_available.length; i++ )
118         {
119             if( m_available[ i ].isCompatibleWith( extension ) )
120             {
121                 return true;
122             }
123         }
124
125         return false;
126     }
127
128     /**
129      * Return a String representation of this object.
130      */

131     public String JavaDoc toString()
132     {
133         final StringBuffer JavaDoc sb = new StringBuffer JavaDoc( "OptionalPackage[" );
134         sb.append( m_file );
135
136         sb.append( ", Available[" );
137         for( int i = 0; i < m_available.length; i++ )
138         {
139             sb.append( m_available );
140             sb.append( " " );
141         }
142
143         sb.append( "], Required[" );
144         for( int i = 0; i < m_required.length; i++ )
145         {
146             sb.append( m_required );
147             sb.append( " " );
148         }
149
150         sb.append( "] ]" );
151
152         return sb.toString();
153     }
154 }
155
Popular Tags