All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.boot.comp.CCLoader Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * Created on : 04.2003
 * Created by : s3595
 */

package at.spardat.xma.boot.comp;

import java.io.File;
import java.io.FilenameFilter;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import at.spardat.xma.boot.cache.VersionNumber;


/**
 * custom classloader, created for each xma-application
 *
 * ! lazy loading is not supported until now !
 *
 * @author s3595 Chris Sch?fer (CGS)
 * @version $Id: CCLoader.java 2115 2007-11-29 16:54:19Z s3460 $
 */
public class CCLoader extends URLClassLoader {
    ArrayList libs;
    ArrayList libPaths;

    /**
     * Contructs a CCLoader
     * @param classpath containing one URL for each directory or jar-file to search for classes
     */
    public CCLoader(URL[] classpath ) {
        super(classpath);
    }

    /**
     * Contructs a CCLoader
     * @param classpath containing one URL for each directory or jar-file to search for classes
     * @param parent the parent class loader to use
     */
    public CCLoader(URL[] classpath, ClassLoader parent ) {
        super(classpath, parent );
    }

    /**
     * Appends the specified URL to the list of URLs to search for
     * classes and resources.
     *
     * @param url the URL to be added to the class path of URLs
     */
    public void addURL(URL url) {
        super.addURL(url);
    }

    /**
     * Appends the specified URL representing a native library to the list of URLs to search for
     * native libraries.
     *
     * @param url the URL to be added to the library path of URLs
     */
    public void addNativeLib(URL url) {
        if(libs==null) libs = new ArrayList();
        libs.add(url);
    }

    /**
     * Appends the specified URL to the list of URLs representing paths to search for
     * native libraries.
     * @param url
     * @since version_number
     * @author s3460
     */
    public void addNativeLibPath(URL url) {
        if(libPaths==null) libPaths = new ArrayList();
        libPaths.add(url);
    }

    /**
     * Appends the URLs in the specified Collection to the list of URLs to search for
     * native libraries. The collection must contain only valid URLs.
     *
     * @param list of URLs to be added to the library path of URLs
     */
    public void addNativeLibs(Collection list) {
        if(libs==null) libs = new ArrayList();
        libs.addAll(list);
    }

    /**
     * Appends the URLs in the specified Collection to the list of URLs reprsenting paths to search for
     * native libraries. The collection must contain only valid URLs.
     *
     * @param list of URLs to be added to the library path of URLs
     */
    public void addNativeLibPaths(Collection list) {
        if(libPaths==null) libPaths = new ArrayList();
        libPaths.addAll(list);
    }

    /**
     * Returns the absolute path name of a native library.
     * The library is searched for in the urls given with
     * {@link #addNativeLib(URL)} and {@link #addNativeLibs(Collection)}.
     * The VM invokes this method to locate the native libraries
     * that belong to classes loaded with this class loader.
     *
     * @param  libname The library name
     * @return  The absolute path of the native library
     */
    public String findLibrary(String libname) {
        String found = super.findLibrary(libname);
        if(found!=null) return found;

        final String libnameFull = System.mapLibraryName(libname);

        //look in full file paths for matching file - return absolute path
        if(libs!=null) {
            for(Iterator it=libs.iterator();it.hasNext();) {
                URL url = (URL)it.next();
                String path = url.getPath();
                String filename;
                int last = path.lastIndexOf("/");
                if(last>=0) {
                    if(last0){
                    return files[0].getAbsolutePath();
                }
            }
        }

        return null;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy