001    package de.mospace.lang;
002    /* Mp3dings - manage mp3 meta-information
003     * Copyright (C) 2003 Moritz Ringler
004     * $Id: MinimalClassLoaderProvider.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    /** A minimal implementation of the ClassLoaderProvider interface whose
024    * {@link #getClassLoader getClassLoader} method always returns the same classloader. **/
025    public class MinimalClassLoaderProvider implements ClassLoaderProvider, Serializable {
026        private final ClassLoader classloader;
027    
028        /** Contructs a new MinimalClassLoaderProvider whose {@link #getClassLoader}
029        * method will always return the specified class loader.
030        * @param classLoader the class loader that will be returned by this object's
031        * {@link #getClassLoader} method
032        */
033        public MinimalClassLoaderProvider(ClassLoader classLoader){
034            classloader = classLoader;
035        }
036    
037        /** Contructs a new MinimalClassLoaderProvider whose {@link #getClassLoader}
038        * method will always return the system class loader.
039        * @see java.lang.ClassLoader#getSystemClassLoader()
040        */
041        public MinimalClassLoaderProvider(){
042            classloader = ClassLoader.getSystemClassLoader();
043        }
044    
045        /** Returns the class loader specified when this MinimalClassLoader
046        * is instantiated. */
047        public ClassLoader getClassLoader(){
048            return classloader;
049        }
050    
051         /** Apart from possibly throwing an IllegalArgumentException a call
052         * to this method has no effect.
053         * @param jarFile a jar archive with Java class files 
054         * @return <code>false</code>
055         * @throws IllegalArgumentException if jarFile does not exist
056         *         or is not a jar file
057         **/
058        public boolean registerLibrary(File jarFile){
059            if (! (jarFile.isFile() && jarFile.getName().endsWith(".jar"))){
060                throw new IllegalArgumentException("Argument must be a jar file.");
061            }
062            return false;
063        }
064    
065        /** Does nothing.
066         * @param jarFiles an array of jar archives with Java class files 
067         * @return <code>false</code> */
068        public boolean registerLibraries(File[] jarFiles){
069            return false;
070        }
071    
072         /** Apart from possibly throwing an IllegalArgumentException a call
073         * to this method has no effect.
074         * @param dir a directory with jar archives
075         * @return <code>false</code>
076         * @throws IllegalArgumentException if <code>dir</code> is not a directory
077         **/
078        public boolean registerLibraryDirectory(File dir){
079            if (! dir.isDirectory()){
080                throw new IllegalArgumentException("Argument must be a directory.");
081            }
082            return false;
083        }
084    
085        /** Does nothing.
086         * @param dirs an array o directories with jar archives
087         * @return <code>false</code> */
088        public boolean registerLibraryDirectories(File[] dirs){
089            return false;
090        }
091    }