Search in sources :

Example 1 with FrameworkException

use of org.eclipse.birt.core.framework.FrameworkException 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)

Example 2 with FrameworkException

use of org.eclipse.birt.core.framework.FrameworkException in project head by mifos.

the class OSGILauncher method setupSecurityPolicy.

protected void setupSecurityPolicy() throws FrameworkException {
    String eclipseSecurity = (String) properties.get(PROP_ECLIPSE_SECURITY);
    if (eclipseSecurity != null) {
        // setup a policy that grants the launcher and path for the
        // framework AllPermissions.
        // Do not set the security manager, this will be done by the
        // framework itself.
        ProtectionDomain domain = OSGILauncher.class.getProtectionDomain();
        CodeSource source = null;
        if (domain != null)
            source = OSGILauncher.class.getProtectionDomain().getCodeSource();
        if (domain == null || source == null) {
            throw new FrameworkException("Can not automatically set the security manager. Please use a policy file.");
        }
        // get the list of codesource URLs to grant AllPermission to
        URL[] rootURLs = new URL[] { source.getLocation(), osgiFramework };
        // replace the security policy
        Policy eclipsePolicy = new OSGIPolicy(Policy.getPolicy(), rootURLs);
        Policy.setPolicy(eclipsePolicy);
    }
}
Also used : Policy(java.security.Policy) ProtectionDomain(java.security.ProtectionDomain) FrameworkException(org.eclipse.birt.core.framework.FrameworkException) CodeSource(java.security.CodeSource) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 FrameworkException (org.eclipse.birt.core.framework.FrameworkException)2 File (java.io.File)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 CodeSource (java.security.CodeSource)1 Policy (java.security.Policy)1 ProtectionDomain (java.security.ProtectionDomain)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 IPlatformContext (org.eclipse.birt.core.framework.IPlatformContext)1 URLClassLoader (org.eclipse.birt.core.framework.URLClassLoader)1