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);
}
}
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);
}
}
Aggregations