Search in sources :

Example 11 with ClassException

use of lucee.commons.lang.ClassException in project Lucee by lucee.

the class ConfigImpl method setDefaultResourceProvider.

protected void setDefaultResourceProvider(Class defaultProviderClass, Map arguments) throws ClassException {
    Object o = ClassUtil.loadInstance(defaultProviderClass);
    if (o instanceof ResourceProvider) {
        ResourceProvider rp = (ResourceProvider) o;
        rp.init(null, arguments);
        setDefaultResourceProvider(rp);
    } else
        throw new ClassException("object [" + Caster.toClassName(o) + "] must implement the interface " + ResourceProvider.class.getName());
}
Also used : ResourceProvider(lucee.commons.io.res.ResourceProvider) CompressResourceProvider(lucee.commons.io.res.type.compress.CompressResourceProvider) ClassException(lucee.commons.lang.ClassException)

Example 12 with ClassException

use of lucee.commons.lang.ClassException in project Lucee by lucee.

the class ConfigImpl method addResourceProvider.

protected void addResourceProvider(String strProviderScheme, Class providerClass, Map arguments) throws ClassException {
    Object o = ClassUtil.loadInstance(providerClass);
    if (o instanceof ResourceProvider) {
        ResourceProvider rp = (ResourceProvider) o;
        rp.init(strProviderScheme, arguments);
        addResourceProvider(rp);
    } else
        throw new ClassException("object [" + Caster.toClassName(o) + "] must implement the interface " + ResourceProvider.class.getName());
}
Also used : ResourceProvider(lucee.commons.io.res.ResourceProvider) CompressResourceProvider(lucee.commons.io.res.type.compress.CompressResourceProvider) ClassException(lucee.commons.lang.ClassException)

Example 13 with ClassException

use of lucee.commons.lang.ClassException in project Lucee by lucee.

the class ConfigImpl method addResourceProvider.

protected void addResourceProvider(String strProviderScheme, ClassDefinition cd, Map arguments) throws ClassException, BundleException {
    Object o = ClassUtil.loadInstance(cd.getClazz());
    if (o instanceof ResourceProvider) {
        ResourceProvider rp = (ResourceProvider) o;
        rp.init(strProviderScheme, arguments);
        addResourceProvider(rp);
    } else
        throw new ClassException("object [" + Caster.toClassName(o) + "] must implement the interface " + ResourceProvider.class.getName());
}
Also used : ResourceProvider(lucee.commons.io.res.ResourceProvider) CompressResourceProvider(lucee.commons.io.res.type.compress.CompressResourceProvider) ClassException(lucee.commons.lang.ClassException)

Example 14 with ClassException

use of lucee.commons.lang.ClassException in project Lucee by lucee.

the class JavaProxy method loadClassByPath.

private static Class<?> loadClassByPath(PageContext pc, String className, String[] paths) throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    java.util.List<Resource> resources = new ArrayList<Resource>();
    if (paths != null && paths.length > 0) {
        // load resources
        for (int i = 0; i < paths.length; i++) {
            Resource res = ResourceUtil.toResourceExisting(pc, paths[i]);
            if (res.isDirectory()) {
                // a directory was passed, add all of the jar files from it
                FileResource dir = (FileResource) res;
                Resource[] jars = dir.listResources((ResourceNameFilter) new WildCardFilter("*.jar"));
                for (Resource jar : jars) {
                    resources.add(jar);
                }
            } else {
                resources.add(res);
            }
        }
    // throw new FunctionException(pc, "JavaProxy", 2, "path", "argument path has to be a array of strings or a single string, where every string is defining a path");
    }
    // load class
    try {
        ClassLoader cl = resources.isEmpty() ? pci.getClassLoader() : pci.getClassLoader(resources.toArray(new Resource[resources.size()]));
        Class clazz = null;
        try {
            clazz = ClassUtil.loadClass(cl, className);
        } catch (ClassException ce) {
            // try java.lang if no package definition
            if (className.indexOf('.') == -1) {
                try {
                    clazz = ClassUtil.loadClass(cl, "java.lang." + className);
                } catch (ClassException e) {
                    throw ce;
                }
            } else
                throw ce;
        }
        return clazz;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) ArrayList(java.util.ArrayList) FileResource(lucee.commons.io.res.type.file.FileResource) ClassException(lucee.commons.lang.ClassException) PageContextImpl(lucee.runtime.PageContextImpl) ClassException(lucee.commons.lang.ClassException) SecurityException(lucee.runtime.exp.SecurityException) PageException(lucee.runtime.exp.PageException) WildCardFilter(lucee.commons.io.res.util.WildCardFilter)

Example 15 with ClassException

use of lucee.commons.lang.ClassException in project Lucee by lucee.

the class Duplicator method duplicateMap.

public static Map duplicateMap(Map map, boolean deepCopy) {
    Map other;
    try {
        other = (Map) ClassUtil.loadInstance(map.getClass());
    } catch (ClassException e) {
        other = new HashMap();
    }
    boolean inside = ThreadLocalDuplication.set(map, other);
    try {
        duplicateMap(map, other, deepCopy);
    } finally {
        if (!inside)
            ThreadLocalDuplication.reset();
    }
    return other;
}
Also used : HashMap(java.util.HashMap) ClassException(lucee.commons.lang.ClassException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClassException (lucee.commons.lang.ClassException)15 BundleException (org.osgi.framework.BundleException)4 ArrayList (java.util.ArrayList)3 ResourceProvider (lucee.commons.io.res.ResourceProvider)3 CompressResourceProvider (lucee.commons.io.res.type.compress.CompressResourceProvider)3 PageException (lucee.runtime.exp.PageException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Property (lucee.runtime.component.Property)2 ClassDefinition (lucee.runtime.db.ClassDefinition)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 SecurityException (lucee.runtime.exp.SecurityException)2 TransformerException (lucee.transformer.TransformerException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1