FileDocCategorySizeDatePackage
FilterFactory.javaAPI DocAndroid 5.1 API5191Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

FilterFactory

public class FilterFactory extends Object
hide

Fields Summary
private static FilterFactory
mSharedFactory
private HashSet
mPackages
private static ClassLoader
mCurrentClassLoader
private static HashSet
mLibraries
private static Object
mClassLoaderGuard
private static final String
TAG
private static boolean
mLogVerbose
Constructors Summary
Methods Summary
public static voidaddFilterLibrary(java.lang.String libraryPath)
Adds a new Java library to the list to be scanned for filters. libraryPath must be an absolute path of the jar file. This needs to be static because only one classloader per process can open a shared native library, which a filter may well have.

        if (mLogVerbose) Log.v(TAG, "Adding filter library " + libraryPath);
        synchronized(mClassLoaderGuard) {
            if (mLibraries.contains(libraryPath)) {
                if (mLogVerbose) Log.v(TAG, "Library already added");
                return;
            }
            mLibraries.add(libraryPath);
            // Chain another path loader to the current chain
            mCurrentClassLoader = new PathClassLoader(libraryPath, mCurrentClassLoader);
        }
    
public voidaddPackage(java.lang.String packageName)

        if (mLogVerbose) Log.v(TAG, "Adding package " + packageName);
        /* TODO: This should use a getPackage call in the caller's context, but no such method exists.
        Package pkg = Package.getPackage(packageName);
        if (pkg == null) {
            throw new IllegalArgumentException("Unknown filter package '" + packageName + "'!");
        }
        */
        mPackages.add(packageName);
    
public android.filterfw.core.FiltercreateFilterByClass(java.lang.Class filterClass, java.lang.String filterName)

        // Make sure this is a Filter subclass
        try {
            filterClass.asSubclass(Filter.class);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Attempting to allocate class '" + filterClass
                + "' which is not a subclass of Filter!");
        }

        // Look for the correct constructor
        Constructor filterConstructor = null;
        try {
            filterConstructor = filterClass.getConstructor(String.class);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("The filter class '" + filterClass
                + "' does not have a constructor of the form <init>(String name)!");
        }

        // Construct the filter
        Filter filter = null;
        try {
            filter = (Filter)filterConstructor.newInstance(filterName);
        } catch (Throwable t) {
            // Condition checked below
        }

        if (filter == null) {
            throw new IllegalArgumentException("Could not construct the filter '"
                + filterName + "'!");
        }
        return filter;
    
public android.filterfw.core.FiltercreateFilterByClassName(java.lang.String className, java.lang.String filterName)

        if (mLogVerbose) Log.v(TAG, "Looking up class " + className);
        Class filterClass = null;

        // Look for the class in the imported packages
        for (String packageName : mPackages) {
            try {
                if (mLogVerbose) Log.v(TAG, "Trying "+packageName + "." + className);
                synchronized(mClassLoaderGuard) {
                    filterClass = mCurrentClassLoader.loadClass(packageName + "." + className);
                }
            } catch (ClassNotFoundException e) {
                continue;
            }
            // Exit loop if class was found.
            if (filterClass != null) {
                break;
            }
        }
        if (filterClass == null) {
            throw new IllegalArgumentException("Unknown filter class '" + className + "'!");
        }
        return createFilterByClass(filterClass, filterName);
    
public static android.filterfw.core.FilterFactorysharedFactory()


        
        if (mSharedFactory == null) {
            mSharedFactory = new FilterFactory();
        }
        return mSharedFactory;