Search in sources :

Example 1 with BirtException

use of org.eclipse.birt.core.exception.BirtException in project head by mifos.

the class OSGILauncher method doStartup.

private void doStartup(PlatformConfig config) throws BirtException {
    if (frameworkClassLoader != null) {
        //$NON-NLS-1$
        logger.log(Level.WARNING, "Framework is already started");
        return;
    }
    platformConfig = config;
    IPlatformContext context = config.getPlatformContext();
    if (context == null) {
        throw new FrameworkException("PlatformContext is not setted - {0}", //$NON-NLS-1$
        new Object[] { "PlatformConfig" });
    }
    // process install.area
    String root = context.getPlatform();
    platformDirectory = new File(root);
    if (!platformDirectory.exists() || !platformDirectory.isDirectory()) {
        throw new FrameworkException("Framework {0} doesn't exist or is not a directory", //$NON-NLS-1$
        new Object[] { root });
    }
    //$NON-NLS-1$
    String path = new File(platformDirectory, "plugins").toString();
    //$NON-NLS-1$
    path = searchFor("org.eclipse.osgi", path);
    if (path == null) {
        throw new FrameworkException("Could not find the Framework - {0}", //$NON-NLS-1$
        new Object[] { "org.eclipse.osgi" });
    }
    try {
        osgiFramework = new File(path).toURI().toURL();
    } catch (MalformedURLException ex) {
    //cannot be here
    }
    ClassLoader original = Thread.currentThread().getContextClassLoader();
    try {
        ClassLoader loader = this.getClass().getClassLoader();
        frameworkClassLoader = new ChildFirstURLClassLoader(new URL[] { osgiFramework }, loader);
        // load the class explicitly.
        try {
            loader.loadClass("org.mozilla.javascript.Context");
            loader.loadClass("org.mozilla.javascript.Scriptable");
            loader.loadClass("org.mozilla.javascript.ScriptableObject");
        // frameworkClassLoader.loadClass(
        // "org.mozilla.javascript.Context"
        } catch (Exception ex) {
        }
        Class clazz = frameworkClassLoader.loadClass(ECLIPSE_STARTER);
        setupOSGiProperties();
        setupSecurityPolicy();
        Method initPropertiesMethod = clazz.getMethod("setInitialProperties", //$NON-NLS-1$
        new Class[] { Map.class });
        if (initPropertiesMethod != null) {
            System.setProperty("osgi.framework.useSystemProperties", //$NON-NLS-1$ //$NON-NLS-2$
            "false");
            properties.put("osgi.framework.useSystemProperties", "false");
            initPropertiesMethod.invoke(null, new Object[] { properties });
        } else {
            Iterator iter = properties.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                String key = (String) entry.getKey();
                String value = (String) entry.getValue();
                System.setProperty(key, value);
            }
            System.setProperty("osgi.framework.useSystemProperties", //$NON-NLS-1$ //$NON-NLS-2$
            "true");
        }
        Method runMethod = clazz.getMethod("startup", //$NON-NLS-1$
        new Class[] { String[].class, Runnable.class });
        bundleContext = runMethod.invoke(null, new Object[] { new String[] {}, null });
        frameworkContextClassLoader = Thread.currentThread().getContextClassLoader();
    } catch (BirtException be) {
        throw be;
    } catch (Exception e) {
        throw new FrameworkException("Can not start up OSGI - {0}", new Object[] { e.getMessage() }, e);
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BirtException(org.eclipse.birt.core.exception.BirtException) FrameworkException(org.eclipse.birt.core.framework.FrameworkException) Method(java.lang.reflect.Method) IPlatformContext(org.eclipse.birt.core.framework.IPlatformContext) URL(java.net.URL) FrameworkException(org.eclipse.birt.core.framework.FrameworkException) BirtException(org.eclipse.birt.core.exception.BirtException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CoreException(org.eclipse.birt.core.exception.CoreException) Iterator(java.util.Iterator) URLClassLoader(org.eclipse.birt.core.framework.URLClassLoader) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 BirtException (org.eclipse.birt.core.exception.BirtException)1 CoreException (org.eclipse.birt.core.exception.CoreException)1 FrameworkException (org.eclipse.birt.core.framework.FrameworkException)1 IPlatformContext (org.eclipse.birt.core.framework.IPlatformContext)1 URLClassLoader (org.eclipse.birt.core.framework.URLClassLoader)1