001    package de.mospace.lang;
002    /* Mp3dings - manage mp3 meta-information
003     * Copyright (C) 2003 Moritz Ringler
004     * $Id: ClassLoaderProvider.java 12 2007-07-27 09:48:53Z ringler $
005     *
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010     *
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019     */
020    import java.io.File;
021    import java.io.Serializable; 
022    
023    /** This interface essentially provides the functionality of a
024    * dynamic class path. Libraries can be registered with a ClassLoaderProvider
025    * and class loaders that look for class files in these libraries
026    * can be obtained with the {@link #getClassLoader} method.
027    **/
028    public interface ClassLoaderProvider extends Serializable{
029        /** serialization version id */
030        public static final long serialVersionUID = 372109672623762879L;
031        
032        /** Returns a class loader that looks for class files in all libraries
033         * that have been successfully registered with this ClassLoaderProvider,
034         * so far.
035         * Subsequent calls to this method must return the same class loader
036         * or class loaders that delegate to all class loaders previously returned.
037         * @return a ClassLoader that looks for class files in all successfully
038         * registered libraries.
039         */
040        public ClassLoader getClassLoader();
041    
042        /** Requests that the specified jar file be registered, so that it is
043         * in the class path of all class loaders returned by future calls to
044         * {@link #getClassLoader}.
045         * @param jarFile a jar archive with Java class files 
046         * @return true if the ClassLoaderProvider honored the request.
047         * @throws IllegalArgumentException if jarFile does not exist
048         *         or is not a jar file
049         **/
050        public boolean registerLibrary(File jarFile);
051    
052        /**  Requests that the specified jar files be registered, so that they are
053         * in the class path of all class loaders returned by future calls to
054         * {@link #getClassLoader}.
055         * @param jarFiles an array of jar archives with Java class files 
056         * @return true if the ClassLoaderProvider honored the request at least for
057         * one jar file.
058         **/
059        public boolean registerLibraries(File[] jarFiles);
060    
061        /**  Requests that the all jar files in the specified directory be
062         * registered, so that they are in the class path of all class loaders
063         * returned by future calls to
064         * {@link #getClassLoader}.
065         * @param dir a directory with jar archives
066         * @return true if there was at least one jar archive in <code>dir</code>,
067         * for wich the request was honored.
068         **/
069        public boolean registerLibraryDirectory(File dir);
070    
071        /**  Requests that the all jar files in the specified directories be
072         * registered, so that they are in the class path of all class loaders
073         * returned by future calls to
074         * {@link #getClassLoader}.
075         * @param dirs an array of directories with jar archives
076         * @return true if there was at least one jar archive in <code>dirs</code>,
077         * for wich the request was honored.
078         **/
079        public boolean registerLibraryDirectories(File[] dirs);
080    }