Search in sources :

Example 6 with CFMLEngineFactory

use of lucee.loader.engine.CFMLEngineFactory in project Lucee by lucee.

the class OSGiUtil method getBundleFile.

public static BundleFile getBundleFile(String name, Version version, Identification id, boolean downloadIfNecessary, BundleFile defaultValue) {
    name = name.trim();
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    StringBuilder versionsFound = new StringBuilder();
    // is it in jar directory but not loaded
    BundleFile bf = _getBundleFile(factory, name, version, versionsFound);
    if (bf != null)
        return bf;
    // if not found try to download
    if (downloadIfNecessary && version != null) {
        try {
            bf = new BundleFile(factory.downloadBundle(name, version.toString(), id));
            if (bf.isBundle())
                return bf;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    return defaultValue;
}
Also used : CFMLEngine(lucee.loader.engine.CFMLEngine) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 7 with CFMLEngineFactory

use of lucee.loader.engine.CFMLEngineFactory in project Lucee by lucee.

the class OSGiUtil method loadClass.

/*public static FrameworkFactory getFrameworkFactory() throws Exception {
		ClassLoader cl = OSGiUtil.class.getClassLoader();
        java.net.URL url = cl.getResource("META-INF/services/org.osgi.framework.launch.FrameworkFactory");
        if (url != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            try {
                for (String s = br.readLine(); s != null; s = br.readLine()) {
                    s = s.trim();
                    // Try to load first non-empty, non-commented line.
                    if ((s.length() > 0) && (s.charAt(0) != '#')) {
                        return (FrameworkFactory) ClassUtil.loadInstance(cl, s);
                    }
                }
            }
            finally {
                if (br != null) br.close();
            }
        }
        throw new Exception("Could not find framework factory.");
    }*/
/**
 * tries to load a class with ni bundle defintion
 * @param name
 * @param version
 * @param id
 * @param startIfNecessary
 * @return
 * @throws BundleException
 */
public static Class loadClass(String className, Class defaultValue) {
    className = className.trim();
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    BundleCollection bc = engine.getBundleCollection();
    // first we try to load the class from the Lucee core
    try {
        // load from core
        return bc.core.loadClass(className);
    }// class is not visible to the Lucee core
     catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    // now we check all started bundled (not only bundles used by core)
    Bundle[] bundles = bc.getBundleContext().getBundles();
    for (Bundle b : bundles) {
        if (b == bc.core)
            continue;
        try {
            return b.loadClass(className);
        }// class is not visible to that bundle
         catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    // now we check lucee loader (SystemClassLoader?)
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    try {
        // print.e("loader:");
        return factory.getClass().getClassLoader().loadClass(className);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    /*
    	try {
			return Class.forName(className);
		} catch (Throwable t3) {
			
		}*/
    // now we check bundles not loaded
    Set<String> loaded = new HashSet<String>();
    for (Bundle b : bundles) {
        loaded.add(b.getSymbolicName() + "|" + b.getVersion());
    }
    try {
        File dir = factory.getBundleDirectory();
        File[] children = dir.listFiles(JAR_EXT_FILTER);
        BundleFile bf;
        for (int i = 0; i < children.length; i++) {
            try {
                bf = new BundleFile(children[i]);
                if (bf.isBundle() && !loaded.contains(bf.getSymbolicName() + "|" + bf.getVersion()) && bf.hasClass(className)) {
                    Bundle b = null;
                    try {
                        b = _loadBundle(bc.getBundleContext(), bf.getFile());
                    } catch (IOException e) {
                    }
                    if (b != null) {
                        startIfNecessary(b);
                        return b.loadClass(className);
                    }
                }
            } catch (Throwable t2) {
                ExceptionUtil.rethrowIfNecessary(t2);
            }
        }
    } catch (Throwable t1) {
        ExceptionUtil.rethrowIfNecessary(t1);
    }
    return defaultValue;
}
Also used : Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) BundleCollection(lucee.loader.osgi.BundleCollection) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory) HashSet(java.util.HashSet)

Example 8 with CFMLEngineFactory

use of lucee.loader.engine.CFMLEngineFactory in project Lucee by lucee.

the class OSGiUtil method loadBundleByPackage.

public static Bundle loadBundleByPackage(String packageName, List<VersionDefinition> versionDefinitions, Set<Bundle> loadedBundles, boolean startIfNecessary, Set<String> parents) throws BundleException, IOException {
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    // if part of bootdelegation we ignore
    if (OSGiUtil.isPackageInBootelegation(packageName)) {
        return null;
    }
    // is it in jar directory but not loaded
    File dir = factory.getBundleDirectory();
    File[] children = dir.listFiles(JAR_EXT_FILTER);
    List<PackageDefinition> pds;
    for (File child : children) {
        BundleFile bf = new BundleFile(child);
        if (bf.isBundle()) {
            if (parents.contains(toString(bf)))
                continue;
            pds = toPackageDefinitions(bf.getExportPackage(), packageName, versionDefinitions);
            if (pds != null && !pds.isEmpty()) {
                Bundle b = exists(loadedBundles, bf);
                if (b != null) {
                    if (startIfNecessary)
                        _startIfNecessary(b, parents);
                    return null;
                }
                b = loadBundle(bf);
                if (b != null) {
                    loadedBundles.add(b);
                    if (startIfNecessary)
                        _startIfNecessary(b, parents);
                    return b;
                }
            }
        }
    }
    return null;
}
Also used : Bundle(org.osgi.framework.Bundle) CFMLEngine(lucee.loader.engine.CFMLEngine) File(java.io.File) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Example 9 with CFMLEngineFactory

use of lucee.loader.engine.CFMLEngineFactory in project Lucee by lucee.

the class OSGiUtil method _loadBundle.

public static Bundle _loadBundle(String name, Version version, Identification id, boolean startIfNecessary, Set<String> parents) throws BundleException, StartFailedException {
    name = name.trim();
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    CFMLEngineFactory factory = engine.getCFMLEngineFactory();
    // check in loaded bundles
    BundleContext bc = engine.getBundleContext();
    Bundle[] bundles = bc.getBundles();
    StringBuilder versionsFound = new StringBuilder();
    for (Bundle b : bundles) {
        if (name.equalsIgnoreCase(b.getSymbolicName())) {
            if (version == null || version.equals(b.getVersion())) {
                if (startIfNecessary) {
                    try {
                        _startIfNecessary(b, parents);
                    } catch (BundleException be) {
                        throw new StartFailedException(be, b);
                    }
                }
                return b;
            }
            if (versionsFound.length() > 0)
                versionsFound.append(", ");
            versionsFound.append(b.getVersion().toString());
        }
    }
    // is it in jar directory but not loaded
    BundleFile bf = _getBundleFile(factory, name, version, versionsFound);
    if (bf != null && bf.isBundle()) {
        Bundle b = null;
        try {
            b = _loadBundle(bc, bf.getFile());
        } catch (IOException e) {
            SystemOut.printDate(e);
        }
        if (b != null) {
            if (startIfNecessary) {
                try {
                    startIfNecessary(b);
                } catch (BundleException be) {
                    throw new StartFailedException(be, b);
                }
            }
            return b;
        }
    }
    // if not found try to download
    {
        try {
            Bundle b;
            if (version != null) {
                File f = factory.downloadBundle(name, version.toString(), id);
                b = _loadBundle(bc, f);
            } else {
                // MUST find out why this breaks at startup with commandbox if version exists
                Resource r = downloadBundle(factory, name, null, id);
                b = _loadBundle(bc, r);
            }
            if (startIfNecessary) {
                try {
                    _start(b, parents);
                } catch (BundleException be) {
                    throw new StartFailedException(be, b);
                }
            }
            return b;
        } catch (Exception e) {
            log(e);
        }
    }
    String localDir = "";
    try {
        localDir = " (" + factory.getBundleDirectory() + ")";
    } catch (IOException e) {
    }
    String upLoc = "";
    try {
        upLoc = " (" + factory.getUpdateLocation() + ")";
    } catch (IOException e) {
    }
    if (versionsFound.length() > 0)
        throw new BundleException("The OSGi Bundle with name [" + name + "] is not available in version [" + version + "] locally" + localDir + " or from the update provider" + upLoc + ", the following versions are available locally [" + versionsFound + "].");
    if (version != null)
        throw new BundleException("The OSGi Bundle with name [" + name + "] in version [" + version + "] is not available locally" + localDir + " or from the update provider" + upLoc + ".");
    throw new BundleException("The OSGi Bundle with name [" + name + "] is not available locally" + localDir + " or from the update provider" + upLoc + ".");
}
Also used : Bundle(org.osgi.framework.Bundle) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) PageException(lucee.runtime.exp.PageException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleException(org.osgi.framework.BundleException) File(java.io.File) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory) BundleContext(org.osgi.framework.BundleContext)

Example 10 with CFMLEngineFactory

use of lucee.loader.engine.CFMLEngineFactory in project Lucee by lucee.

the class CFMLEngineImpl method shutdownFelix.

private void shutdownFelix() {
    CFMLEngineFactory f = getCFMLEngineFactory();
    try {
        Method m = f.getClass().getMethod("shutdownFelix", new Class[0]);
        m.invoke(f, new Object[0]);
    }// this will for sure fail if CFMLEngineFactory does not have this method
     catch (Exception e) {
    }
}
Also used : Method(java.lang.reflect.Method) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) PageException(lucee.runtime.exp.PageException) JspException(javax.servlet.jsp.JspException) NativeException(lucee.runtime.exp.NativeException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PageServletException(lucee.runtime.exp.PageServletException) MalformedURLException(java.net.MalformedURLException) RequestTimeoutException(lucee.runtime.exp.RequestTimeoutException) ApplicationException(lucee.runtime.exp.ApplicationException) CFMLEngineFactory(lucee.loader.engine.CFMLEngineFactory)

Aggregations

CFMLEngineFactory (lucee.loader.engine.CFMLEngineFactory)15 IOException (java.io.IOException)10 CFMLEngine (lucee.loader.engine.CFMLEngine)9 PageException (lucee.runtime.exp.PageException)8 BundleException (org.osgi.framework.BundleException)8 UnknownHostException (java.net.UnknownHostException)7 File (java.io.File)6 MalformedURLException (java.net.MalformedURLException)6 ApplicationException (lucee.runtime.exp.ApplicationException)6 Bundle (org.osgi.framework.Bundle)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 ClassException (lucee.commons.lang.ClassException)5 CFXTagException (lucee.runtime.cfx.CFXTagException)5 ConverterException (lucee.runtime.converter.ConverterException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 HTTPException (lucee.runtime.exp.HTTPException)5 SecurityException (lucee.runtime.exp.SecurityException)5 FunctionLibException (lucee.transformer.library.function.FunctionLibException)5 TagLibException (lucee.transformer.library.tag.TagLibException)5 DOMException (org.w3c.dom.DOMException)5