Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcvs2svn2006-06-03 13:15:02 +0000
committercvs2svn2006-06-03 13:15:02 +0000
commitee989aad71ac6444c69a4387b162f75f2d460715 (patch)
tree691404cd5dd6d96080759d86ff642befc8cdb2a4
parent2ed294ea54f6c49a8204ccd56ec45bdedd6aeb08 (diff)
downloadrt.equinox.bundles-ee989aad71ac6444c69a4387b162f75f2d460715.tar.gz
rt.equinox.bundles-ee989aad71ac6444c69a4387b162f75f2d460715.tar.xz
rt.equinox.bundles-ee989aad71ac6444c69a4387b162f75f2d460715.zip
This commit was manufactured by cvs2svn to create branch 'R3_2_maintenance'.
Sprout from master 2006-06-03 13:14:58 UTC DJ Houghton <dj> 'Released new about.html files.' Delete: bundles/org.eclipse.equinox.app/schema/containers.exsd bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IAppContext.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IContainer.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistenceUtil.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ContainerManager.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadApplication.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadContainer.java bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/SingletonContainer.java
-rwxr-xr-xbundles/org.eclipse.equinox.app/schema/containers.exsd124
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IAppContext.java76
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IContainer.java40
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistenceUtil.java589
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ContainerManager.java499
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadApplication.java70
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadContainer.java78
-rwxr-xr-xbundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/SingletonContainer.java68
8 files changed, 0 insertions, 1544 deletions
diff --git a/bundles/org.eclipse.equinox.app/schema/containers.exsd b/bundles/org.eclipse.equinox.app/schema/containers.exsd
deleted file mode 100755
index 9f8f736e8..000000000
--- a/bundles/org.eclipse.equinox.app/schema/containers.exsd
+++ /dev/null
@@ -1,124 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.equinox.app">
-<annotation>
- <appInfo>
- <meta.schema plugin="org.eclipse.equinox.app" id="containers" name="Containers"/>
- </appInfo>
- <documentation>
- [Enter description of this extension point.]
- </documentation>
- </annotation>
-
- <element name="extension">
- <complexType>
- <sequence>
- <element ref="container"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="container">
- <complexType>
- <sequence>
- <element ref="run"/>
- </sequence>
- <attribute name="type" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="singleton" type="boolean" use="default" value="false">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="run">
- <complexType>
- <attribute name="class" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- <appInfo>
- <meta.attribute kind="java" basedOn="org.eclipse.equinox.app.IContainer"/>
- </appInfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appInfo>
- <meta.section type="since"/>
- </appInfo>
- <documentation>
- [Enter the first release in which this extension point appears.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="examples"/>
- </appInfo>
- <documentation>
- [Enter extension point usage example here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
- [Enter information about supplied implementation of this extension point.]
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="copyright"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
-</schema>
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IAppContext.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IAppContext.java
deleted file mode 100755
index 9f8c7666d..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IAppContext.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.app;
-
-import java.util.Map;
-import org.eclipse.equinox.registry.IConfigurationElement;
-import org.osgi.service.application.ApplicationDescriptor;
-
-/**
- * A context is used by a container to launch an application using
- * {@link IContainer#launch(IAppContext)}. The initial status of a
- * context is {@link #ACTIVE} when it is given to a container to
- * launch an application.
- * @see IApplication
- * @see IContainer
- * <p>
- * Clients may not implement this interface.
- * </p>
- * @since 3.2
- */
-public interface IAppContext {
- /**
- * Indicates the application is active for this context
- */
- public int ACTIVE = 0x01;
- /**
- * Indicates the application is stopping for this context
- */
- public int STOPPING = 0x02;
- /**
- * Indicates the application is stopped for this context
- */
- public int STOPPED = 0x04;
-
- /**
- * Returns the arguments to use when launching an application.
- * @return the arguments to use when launching an applicaiton, null may be returned.
- */
- public Map getArguments();
-
- /**
- * Returns the application descriptor for this context.
- * @return the application descriptor for this context.
- */
- public ApplicationDescriptor getApplicationDescriptor();
-
- /**
- * Returns the configuration element for this context.
- * @return the configuration element for this context.
- */
- public IConfigurationElement getConfiguration();
-
- /**
- * Called by the container when an application is stopping or has stopped.
- * @param status may be {@link #STOPPING} or {@link #STOPPED}
- * @see #STOPPING
- * @see #STOPPED
- * @throws IllegalArgumentException if {@link #ACTIVE} is used as the status.
- */
- public void setAppStatus(int status);
-
- /**
- * Returns the current app status according to the context
- * @return the current app status according to the context
- */
- public int getAppStatus();
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IContainer.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IContainer.java
deleted file mode 100755
index 6c9d2e5d1..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/app/IContainer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.app;
-
-/**
- * A container is used to launch applications.
- * @see IAppContext
- * @see IApplication
- * <p>
- * Clients may implement this interface.
- * </p>
- * @since 3.2
- */
-public interface IContainer {
- /**
- * Launch an application with the given application context. The given
- * context must have its {@link IAppContext#setAppStatus(int)} method called by
- * the container when the returned application has stopped.
- * @param context the application context to launch an application with
- * @return the application which was launched
- * @throws Exception if any errors occur while launching the application
- */
- IApplication launch(IAppContext context) throws Exception;
-
- /**
- * This method should shutdown the container and free any resources it may have
- * been using. All applications currently active in this container will be
- * asked to stop before this method is called.
- */
- void shutdown();
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistenceUtil.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistenceUtil.java
deleted file mode 100755
index e95118bf0..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/AppPersistenceUtil.java
+++ /dev/null
@@ -1,589 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.internal.app;
-
-import java.io.*;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import org.eclipse.osgi.service.datalocation.Location;
-import org.eclipse.osgi.service.environment.EnvironmentInfo;
-import org.eclipse.osgi.storagemanager.StorageManager;
-import org.osgi.framework.*;
-import org.osgi.service.application.ApplicationDescriptor;
-import org.osgi.service.application.ScheduledApplication;
-import org.osgi.service.event.*;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Manages all persistent data for ApplicationDescriptors (lock status,
- * scheduled applications etc.)
- */
-public class AppPersistenceUtil {
- private static final String PROP_CONFIG_AREA = "osgi.configuration.area"; //$NON-NLS-1$
-
- private static final String FILTER_PREFIX = "(&(objectClass=org.eclipse.osgi.service.datalocation.Location)(type="; //$NON-NLS-1$
- private static final String FILE_APPLOCKS = ".locks"; //$NON-NLS-1$
- private static final String FILE_APPSCHEDULED = ".scheduled"; //$NON-NLS-1$
- private static final String EVENT_HANDLER = "org.osgi.service.event.EventHandler"; //$NON-NLS-1$
- private static final String EVENT_TIMER_TOPIC = "org/osgi/application/timer"; //$NON-NLS-1$
-
- private static final int DATA_VERSION = 1;
- private static final byte NULL = 0;
- private static final int OBJECT = 1;
-
- // obsolete command line args
- private static final String NO_PACKAGE_PREFIXES = "-noPackagePrefixes"; //$NON-NLS-1$
- private static final String CLASSLOADER_PROPERTIES = "-classloaderProperties"; //$NON-NLS-1$
- private static final String PLUGINS = "-plugins"; //$NON-NLS-1$
- private static final String FIRST_USE = "-firstUse"; //$NON-NLS-1$
- private static final String NO_UPDATE = "-noUpdate"; //$NON-NLS-1$
- private static final String NEW_UPDATES = "-newUpdates"; //$NON-NLS-1$
- private static final String UPDATE = "-update"; //$NON-NLS-1$
- private static final String BOOT = "-boot"; //$NON-NLS-1$
-
- // command line args not used by app container
- private static final String KEYRING = "-keyring"; //$NON-NLS-1$
- private static final String PASSWORD = "-password"; //$NON-NLS-1$
-
- // command line args used by app container
- private static final String PRODUCT = "-product"; //$NON-NLS-1$
- private static final String FEATURE = "-feature"; //$NON-NLS-1$
- private static final String APPLICATION = "-application"; //$NON-NLS-1$
-
- private static BundleContext context;
- private static ServiceTracker configuration;
- private static ServiceTracker pkgAdminTracker;
- private static Collection locks = new ArrayList();
- private static Map scheduledApps = new HashMap();
- static ArrayList timerApps = new ArrayList();
- private static StorageManager storageManager;
- private static boolean dirty;
- private static boolean scheduling = false;
- static boolean shutdown = false;
- private static int nextScheduledID = 1;
- private static Thread timerThread;
- private static String[] appArgs;
-
- static synchronized void setBundleContext(BundleContext context) {
- if (context != null) {
- AppPersistenceUtil.context = context;
- init();
- } else {
- shutdown();
- AppPersistenceUtil.context = context;
- }
- }
-
- private static void init() {
- shutdown = false;
- appArgs = processCommandLine();
- initPackageAdmin();
- initConfiguration();
- loadData(FILE_APPLOCKS);
- loadData(FILE_APPSCHEDULED);
- }
-
- private static void shutdown() {
- shutdown = true;
- stopTimer();
- saveData();
- if (storageManager != null) {
- storageManager.close();
- storageManager = null;
- }
- closeConfiguration();
- closePackageAdmin();
- appArgs = null;
- }
-
- private static void initPackageAdmin() {
- closePackageAdmin(); // just incase
- pkgAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
- pkgAdminTracker.open();
- }
-
- private static void closePackageAdmin() {
- if (pkgAdminTracker != null)
- pkgAdminTracker.close();
- pkgAdminTracker = null;
- }
-
- private static void initConfiguration() {
- closeConfiguration(); // just incase
- Filter filter = null;
- try {
- filter = context.createFilter(FILTER_PREFIX + PROP_CONFIG_AREA + "))"); //$NON-NLS-1$
- } catch (InvalidSyntaxException e) {
- // ignore this. It should never happen as we have tested the above format.
- }
- configuration = new ServiceTracker(context, filter, null);
- configuration.open();
- }
-
- private static void closeConfiguration() {
- if (configuration != null)
- configuration.close();
- configuration = null;
- }
-
- /**
- * Used by {@link ApplicationDescriptor} to determine if an application is locked.
- * @param desc the application descriptor
- * @return true if the application is persistently locked.
- */
- public synchronized static boolean isLocked(ApplicationDescriptor desc) {
- return locks.contains(desc.getApplicationId());
- }
-
- /**
- * Used by {@link ApplicationDescriptor} to determine lock and unlock and application.
- * @param desc the application descriptor
- * @param locked the locked flag
- */
- public synchronized static void saveLock(ApplicationDescriptor desc, boolean locked) {
- if (locked) {
- if (!locks.contains(desc.getApplicationId())) {
- dirty = true;
- locks.add(desc.getApplicationId());
- }
- } else if (locks.remove(desc.getApplicationId())) {
- dirty = true;
- }
- }
-
- synchronized static void removeScheduledApp(EclipseScheduledApplication scheduledApp) {
- if (scheduledApps.remove(scheduledApp.getID()) != null) {
- timerApps.remove(scheduledApp);
- dirty = true;
- }
- }
-
- /**
- * Used by {@link ScheduledApplication} to persistently schedule an application launch
- * @param descriptor
- * @param arguments
- * @param topic
- * @param eventFilter
- * @param recurring
- * @return the scheduled application
- * @throws InvalidSyntaxException
- */
- public synchronized static ScheduledApplication addScheduledApp(ApplicationDescriptor descriptor, Map arguments, String topic, String eventFilter, boolean recurring) throws InvalidSyntaxException {
- if (!scheduling && !checkSchedulingSupport())
- throw new UnsupportedOperationException("Cannot support scheduling without org.osgi.service.event package"); //$NON-NLS-1$
- // check the event filter for correct syntax
- context.createFilter(eventFilter);
- EclipseScheduledApplication result = new EclipseScheduledApplication(context, getNextScheduledID(), descriptor.getApplicationId(), arguments, topic, eventFilter, recurring);
- addScheduledApp(result);
- dirty = true;
- return result;
- }
-
- private static void addScheduledApp(EclipseScheduledApplication scheduledApp) {
- if (EVENT_TIMER_TOPIC.equals(scheduledApp.getTopic())) {
- timerApps.add(scheduledApp);
- if (timerThread == null)
- startTimer();
- }
- scheduledApps.put(scheduledApp.getID(), scheduledApp);
- Hashtable serviceProps = new Hashtable();
- if (scheduledApp.getTopic() != null)
- serviceProps.put(EventConstants.EVENT_TOPIC, new String[] {scheduledApp.getTopic()});
- if (scheduledApp.getEventFilter() != null)
- serviceProps.put(EventConstants.EVENT_FILTER, scheduledApp.getEventFilter());
- ServiceRegistration sr = context.registerService(new String[] {ScheduledApplication.class.getName(), EVENT_HANDLER}, scheduledApp, serviceProps);
- scheduledApp.setServiceRegistration(sr);
- }
-
- private static Integer getNextScheduledID() {
- if (nextScheduledID == Integer.MAX_VALUE)
- nextScheduledID = 0;
- Integer result = new Integer(nextScheduledID++);
- while (scheduledApps.get(result) != null && nextScheduledID < Integer.MAX_VALUE)
- result = new Integer(nextScheduledID++);
- if (nextScheduledID == Integer.MAX_VALUE)
- throw new IllegalStateException("Maximum number of scheduled applications reached"); //$NON-NLS-1$
- return result;
- }
-
- private static boolean checkSchedulingSupport() {
- // cannot support scheduling without the event admin package
- try {
- Class.forName(EVENT_HANDLER);
- scheduling = true;
- return true;
- } catch (ClassNotFoundException e) {
- scheduling = false;
- return false;
- }
- }
-
- private synchronized static boolean loadData(String fileName) {
- try {
- Location location = (Location) configuration.getService();
- if (location == null)
- return false;
- File theStorageDir = new File(location.getURL().getPath() + '/' + Activator.PI_APP);
- boolean readOnly = location.isReadOnly();
- storageManager = new StorageManager(theStorageDir, readOnly ? "none" : null, readOnly); //$NON-NLS-1$
- storageManager.open(!readOnly);
- File dataFile = storageManager.lookup(fileName, false);
- if (dataFile == null || !dataFile.isFile()) {
- Location parent = location.getParentLocation();
- if (parent != null) {
- theStorageDir = new File(parent.getURL().getPath() + '/' + Activator.PI_APP);
- StorageManager tmp = new StorageManager(theStorageDir, "none", true); //$NON-NLS-1$
- tmp.open(false);
- dataFile = tmp.lookup(fileName, false);
- tmp.close();
- }
- }
- if (dataFile == null || !dataFile.isFile())
- return true;
- if (fileName.equals(FILE_APPLOCKS))
- loadLocks(dataFile);
- else if (fileName.equals(FILE_APPSCHEDULED))
- loadSchedules(dataFile);
- } catch (IOException e) {
- return false;
- }
- return true;
- }
-
- private static void loadLocks(File locksData) throws IOException {
- ObjectInputStream in = null;
- try {
- in = new ObjectInputStream(new FileInputStream(locksData));
- int dataVersion = in.readInt();
- if (dataVersion != DATA_VERSION)
- return;
- int numLocks = in.readInt();
- for (int i = 0; i < numLocks; i++)
- locks.add(in.readUTF());
- } finally {
- if (in != null)
- in.close();
- }
- }
-
- private static void loadSchedules(File schedulesData) throws IOException {
- ObjectInputStream in = null;
- try {
- in = new ObjectInputStream(new FileInputStream(schedulesData));
- int dataVersion = in.readInt();
- if (dataVersion != DATA_VERSION)
- return;
- int numScheds = in.readInt();
- for (int i = 0; i < numScheds; i++) {
- Integer id = new Integer(in.readInt());
- String appPid = readString(in, false);
- String topic = readString(in, false);
- String eventFilter = readString(in, false);
- boolean recurring = in.readBoolean();
- Map args = (Map) in.readObject();
- EclipseScheduledApplication schedApp = new EclipseScheduledApplication(context, id, appPid, args, topic, eventFilter, recurring);
- addScheduledApp(schedApp);
- }
- } catch (InvalidSyntaxException e) {
- throw new IOException(e.getMessage());
- } catch (NoClassDefFoundError e) {
- throw new IOException(e.getMessage());
- } catch (ClassNotFoundException e) {
- throw new IOException(e.getMessage());
- } finally {
- if (in != null)
- in.close();
- }
- }
-
- private synchronized static void saveData() {
- if (!dirty || storageManager.isReadOnly())
- return;
- try {
- File locksData = storageManager.createTempFile(FILE_APPLOCKS);
- saveLocks(locksData);
- File schedulesData = storageManager.createTempFile(FILE_APPSCHEDULED);
- saveSchedules(schedulesData);
- storageManager.lookup(FILE_APPLOCKS, true);
- storageManager.lookup(FILE_APPSCHEDULED, true);
- storageManager.update(new String[] {FILE_APPLOCKS, FILE_APPSCHEDULED}, new String[] {locksData.getName(), schedulesData.getName()});
- } catch (IOException e) {
- // TODO should log this!!
- }
- dirty = false;
- }
-
- private static void saveLocks(File locksData) throws IOException {
- ObjectOutputStream out = null;
- try {
- out = new ObjectOutputStream(new FileOutputStream(locksData));
- out.writeInt(DATA_VERSION);
- out.writeInt(locks.size());
- for (Iterator iterLocks = locks.iterator(); iterLocks.hasNext();)
- out.writeUTF((String) iterLocks.next());
- } finally {
- if (out != null)
- out.close();
- }
- }
-
- private static void saveSchedules(File schedulesData) throws IOException {
- ObjectOutputStream out = null;
- try {
- out = new ObjectOutputStream(new FileOutputStream(schedulesData));
- out.writeInt(DATA_VERSION);
- out.writeInt(scheduledApps.size());
- for (Iterator apps = scheduledApps.values().iterator(); apps.hasNext();) {
- EclipseScheduledApplication app = (EclipseScheduledApplication) apps.next();
- out.writeInt(app.getID().intValue());
- writeStringOrNull(out, app.getAppPid());
- writeStringOrNull(out, app.getTopic());
- writeStringOrNull(out, app.getEventFilter());
- out.writeBoolean(app.isRecurring());
- out.writeObject(app.getArguments());
- }
- } finally {
- if (out != null)
- out.close();
- }
- }
-
- private static void startTimer() {
- timerThread = new Thread(new AppTimer(), "app schedule timer"); //$NON-NLS-1$
- timerThread.start();
- }
-
- private static void stopTimer() {
- if (timerThread != null)
- timerThread.interrupt();
- timerThread = null;
- }
-
- private static class AppTimer implements Runnable {
- public void run() {
- int lastMin = -1;
- while (!shutdown) {
- try {
- Thread.sleep(30000); // sleeping 30 secs instead of 60 to try to avoid skipping minutes
- Calendar cal = Calendar.getInstance();
- int minute = cal.get(Calendar.MINUTE);
- if (minute == lastMin)
- continue;
- lastMin = minute;
- Hashtable props = new Hashtable();
- props.put("year", new Integer(cal.get(Calendar.YEAR))); //$NON-NLS-1$
- props.put("month", new Integer(cal.get(Calendar.MONTH))); //$NON-NLS-1$
- props.put("day_of_month", new Integer(cal.get(Calendar.DAY_OF_MONTH))); //$NON-NLS-1$
- props.put("day_of_week", new Integer(cal.get(Calendar.DAY_OF_WEEK))); //$NON-NLS-1$
- props.put("hour_of_day", new Integer(cal.get(Calendar.HOUR_OF_DAY))); //$NON-NLS-1$
- props.put("minute", new Integer(minute)); //$NON-NLS-1$
- Event timerEvent = new Event(EVENT_TIMER_TOPIC, props);
- synchronized (AppPersistenceUtil.class) {
- // poor mans implementation of dispatching events; the spec will not allow us to use event admin to dispatch the virtual timer events; boo!!
- if (timerApps.size() == 0)
- continue;
- EclipseScheduledApplication[] apps = (EclipseScheduledApplication[]) timerApps.toArray(new EclipseScheduledApplication[timerApps.size()]);
- for (int i = 0; i < apps.length; i++) {
- try {
- String filterString = apps[i].getEventFilter();
- Filter filter = filterString == null ? null : FrameworkUtil.createFilter(filterString);
- if (filter == null || filter.match(props))
- apps[i].handleEvent(timerEvent);
- } catch (Throwable t) {
- t.printStackTrace();
- // TODO should log this
- }
- }
- }
- } catch (InterruptedException e) {
- // do nothing;
- }
- }
- }
- }
-
- private static String readString(ObjectInputStream in, boolean intern) throws IOException {
- byte type = in.readByte();
- if (type == NULL)
- return null;
- return intern ? in.readUTF().intern() : in.readUTF();
- }
-
- private static void writeStringOrNull(ObjectOutputStream out, String string) throws IOException {
- if (string == null)
- out.writeByte(NULL);
- else {
- out.writeByte(OBJECT);
- out.writeUTF(string);
- }
- }
-
- public static Bundle getBundle(String symbolicName) {
- PackageAdmin packageAdmin = (PackageAdmin) getService(pkgAdminTracker);
- if (packageAdmin == null)
- return null;
- Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
- if (bundles == null)
- return null;
- //Return the first bundle that is not installed or uninstalled
- for (int i = 0; i < bundles.length; i++)
- if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0)
- return bundles[i];
- return null;
- }
-
- /**
- * Returns the default application args that should be used to launch an application
- * when args are not supplied.
- * @return the default application args.
- */
- public static String[] getApplicationArgs() {
- return appArgs;
- }
-
- private static String[] processCommandLine() {
- ServiceReference infoRef = context.getServiceReference(EnvironmentInfo.class.getName());
- if (infoRef == null)
- return null;
- EnvironmentInfo envInfo = (EnvironmentInfo) context.getService(infoRef);
- if (envInfo == null)
- return null;
- String[] args = envInfo.getNonFrameworkArgs();
- context.ungetService(infoRef);
- if (args == null)
- return args;
- if (args.length == 0)
- return args;
-
- int[] configArgs = new int[args.length];
- //need to initialize the first element to something that could not be an index.
- configArgs[0] = -1;
- int configArgIndex = 0;
- for (int i = 0; i < args.length; i++) {
- boolean found = false;
- // check for args without parameters (i.e., a flag arg)
-
- // consume obsolete args
- if (args[i].equalsIgnoreCase(CLASSLOADER_PROPERTIES))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(NO_PACKAGE_PREFIXES))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(PLUGINS))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(FIRST_USE))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(NO_UPDATE))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(NEW_UPDATES))
- found = true; // ignored
- if (args[i].equalsIgnoreCase(UPDATE))
- found = true; // ignored
-
- // done checking for args. Remember where an arg was found
- if (found) {
- configArgs[configArgIndex++] = i;
- continue;
- }
- // check for args with parameters
- if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$
- continue;
- String arg = args[++i];
-
- // consume args not used by app container
- if (args[i - 1].equalsIgnoreCase(KEYRING))
- found = true;
- if (args[i - 1].equalsIgnoreCase(PASSWORD))
- found = true;
-
- // consume obsolete args for compatibilty
- if (args[i - 1].equalsIgnoreCase(CLASSLOADER_PROPERTIES))
- found = true; // ignore
- if (args[i - 1].equalsIgnoreCase(BOOT))
- found = true; // ignore
-
- // look for the product to run
- // treat -feature as a synonym for -product for compatibility.
- if (args[i - 1].equalsIgnoreCase(PRODUCT) || args[i - 1].equalsIgnoreCase(FEATURE)) {
- // use the long way to set the property to compile against eeminimum
- System.getProperties().setProperty(ContainerManager.PROP_PRODUCT, arg);
- found = true;
- }
-
- // look for the application to run.
- if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
- // use the long way to set the property to compile against eeminimum
- System.getProperties().setProperty(ContainerManager.PROP_ECLIPSE_APPLICATION, arg);
- found = true;
- }
-
- // done checking for args. Remember where an arg was found
- if (found) {
- configArgs[configArgIndex++] = i - 1;
- configArgs[configArgIndex++] = i;
- }
- }
-
- // remove all the arguments consumed by this argument parsing
- if (configArgIndex == 0) {
- appArgs = args;
- return args;
- }
- appArgs = new String[args.length - configArgIndex];
- configArgIndex = 0;
- int j = 0;
- for (int i = 0; i < args.length; i++) {
- if (i == configArgs[configArgIndex])
- configArgIndex++;
- else
- appArgs[j++] = args[i];
- }
- return appArgs;
- }
-
- static void openTracker(final ServiceTracker tracker, final boolean allServices) {
- if (System.getSecurityManager() == null)
- tracker.open(allServices);
- else
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- tracker.open(allServices);
- return null;
- }
- });
- }
-
- static Object getService(final ServiceTracker tracker) {
- if (System.getSecurityManager() == null)
- return tracker.getService();
- return AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return tracker.getService();
- }
- });
- }
-
- static String getLocation(final Bundle bundle) {
- if (System.getSecurityManager() == null)
- return bundle.getLocation();
- return (String) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return bundle.getLocation();
- }
- });
- }
-
- static BundleContext getContext() {
- return context;
- }
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ContainerManager.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ContainerManager.java
deleted file mode 100755
index 8920964fd..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/ContainerManager.java
+++ /dev/null
@@ -1,499 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.internal.app;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.equinox.app.IContainer;
-import org.eclipse.equinox.registry.*;
-import org.eclipse.osgi.framework.log.FrameworkLog;
-import org.eclipse.osgi.framework.log.FrameworkLogEntry;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.*;
-import org.osgi.service.application.ApplicationDescriptor;
-import org.osgi.service.application.ApplicationHandle;
-import org.osgi.util.tracker.ServiceTracker;
-
-/*
- * A MEG application container that understands eclipse applications. This
- * container will discover installed eclipse applications and register the
- * appropriate ApplicatoinDescriptor service with the service registry.
- * It also manages container extensions which are uses to launch
- * different application types.
- */
-public class ContainerManager implements IRegistryChangeListener, SynchronousBundleListener {
- private static final String PI_RUNTIME = "org.eclipse.core.runtime"; //$NON-NLS-1$
- private static final String PT_APPLICATIONS = "applications"; //$NON-NLS-1$
- private static final String PT_APP_TYPE = "type"; //$NON-NLS-1$
- private static final String PT_APP_VISIBLE = "visible"; //$NON-NLS-1$
- private static final String PT_APP_SINGLETON = "singleton"; //$NON-NLS-1$
- private static final String PT_RUN = "run"; //$NON-NLS-1$
- private static final String PT_PRODUCTS = "products"; //$NON-NLS-1$
- private static final String PT_CONTAINERS = "containers"; //$NON-NLS-1$
- private static final String ATTR_APPLICATION = "application"; //$NON-NLS-1$
- private static final String EXT_ERROR_APP = "org.eclipse.equinox.app.error"; //$NON-NLS-1$
- static final String APP_TYPE_MAIN_THREAD = "main.thread"; //$NON-NLS-1$
-
- public static final String PROP_PRODUCT = "eclipse.product"; //$NON-NLS-1$
- public static final String PROP_ECLIPSE_APPLICATION = "eclipse.application"; //$NON-NLS-1$
- public static final String PROP_ECLIPSE_APPLICATION_ARGS = "eclipse.application.args"; //$NON-NLS-1$
- public static final String PROP_ECLIPSE_APPLICATION_NODEFAULT = "eclipse.application.noDefault"; //$NON-NLS-1$
-
- BundleContext context;
- // A map of ApplicationDescriptors keyed by eclipse application ID
- private HashMap apps = new HashMap();
- // A map of containers keyed by application type
- private HashMap containers = new HashMap();
- // tracks the FrameworkLog
- private ServiceTracker frameworkLog;
- private boolean missingProductReported;
- private IExtensionRegistry extensionRegistry;
-
- public ContainerManager(BundleContext context, IExtensionRegistry extensionRegistry) {
- this.context = context;
- this.extensionRegistry = extensionRegistry;
- }
-
- void startManager() {
- frameworkLog = new ServiceTracker(context, FrameworkLog.class.getName(), null);
- frameworkLog.open();
- getExtensionRegistry().addRegistryChangeListener(this);
- registerAppDecriptors();
- // need to listen for system bundle stopping
- context.addBundleListener(this);
- // Start the default application
- startDefaultApp();
- }
-
- void stopManager() {
- // stop all applications and containers first
- stopAll();
- context.removeBundleListener(this);
- getExtensionRegistry().removeRegistryChangeListener(this);
- frameworkLog.close();
- frameworkLog = null;
- // flush the apps and containers
- apps.clear();
- containers.clear();
- }
-
- /*
- * Only used to find the default application
- */
- private EclipseAppDescriptor getAppDescriptor(String applicationId) {
- EclipseAppDescriptor result = null;
- synchronized (apps) {
- result = (EclipseAppDescriptor) apps.get(applicationId);
- }
- if (result == null) {
- registerAppDecriptors(); // try again just in case we are waiting for an event
- synchronized (apps) {
- result = (EclipseAppDescriptor) apps.get(applicationId);
- }
- }
- return result;
- }
-
- EclipseAppDescriptor[] getAppDescriptorsByType(String type) {
- ArrayList result = new ArrayList();
- synchronized (apps) {
- for (Iterator iApps = apps.values().iterator(); iApps.hasNext();) {
- EclipseAppDescriptor app = (EclipseAppDescriptor) iApps.next();
- if (type.equals(app.getType()))
- result.add(app);
- }
- }
- return (EclipseAppDescriptor[]) result.toArray(new EclipseAppDescriptor[result.size()]);
- }
-
- private IContainer getContainer(String type) {
- synchronized (containers) {
- IContainer container = (IContainer) containers.get(type);
- if (container != null)
- return container;
- container = createContainer(type);
- if (container != null)
- containers.put(type, container);
- return container;
- }
- }
-
- private EclipseAppDescriptor createAppDescriptor(IExtension appExtension) {
- synchronized (apps) {
- EclipseAppDescriptor appDescriptor = (EclipseAppDescriptor) apps.get(appExtension.getUniqueIdentifier());
- if (appDescriptor != null)
- return appDescriptor;
- // the appDescriptor does not exist for the app ID; create it
- IConfigurationElement[] configs = appExtension.getConfigurationElements();
- String type = null;
- boolean visible = true;
- if (configs.length > 0) {
- type = configs[0].getAttribute(PT_APP_TYPE);
- String sVisible = configs[0].getAttribute(PT_APP_VISIBLE);
- visible = sVisible == null ? true : Boolean.valueOf(sVisible).booleanValue();
- }
- appDescriptor = new EclipseAppDescriptor(appExtension.getNamespace(), appExtension.getUniqueIdentifier(), type, visible, this);
- // register the appDescriptor as a service
- ServiceRegistration sr = (ServiceRegistration) AccessController.doPrivileged(new RegisterService(ApplicationDescriptor.class.getName(), appDescriptor, appDescriptor.getServiceProperties()));
- appDescriptor.setServiceRegistration(sr);
- // save the app descriptor in the cache
- apps.put(appExtension.getUniqueIdentifier(), appDescriptor);
- return appDescriptor;
- }
- }
-
- private EclipseAppDescriptor removeAppDescriptor(String applicationId) {
- synchronized (apps) {
- EclipseAppDescriptor appDescriptor = (EclipseAppDescriptor) apps.remove(applicationId);
- if (appDescriptor == null)
- return null;
- appDescriptor.unregister();
- return appDescriptor;
- }
- }
-
- /*
- * Gives access to the RegisterService privileged action.
- */
- PrivilegedAction getRegServiceAction(String serviceClass, Object serviceObject, Dictionary serviceProps) {
- return new RegisterService(serviceClass, serviceObject, serviceProps);
- }
-
- /*
- * PrivilegedAction used to register ApplicationDescriptor and ApplicationHandle services
- */
- private class RegisterService implements PrivilegedAction {
- String serviceClass;
- Object serviceObject;
- Dictionary serviceProps;
-
- RegisterService(String serviceClass, Object serviceObject, Dictionary serviceProps) {
- this.serviceClass = serviceClass;
- this.serviceObject = serviceObject;
- this.serviceProps = serviceProps;
- }
-
- public Object run() {
- return context.registerService(serviceClass, serviceObject, serviceProps);
- }
- }
-
- private void startDefaultApp() {
- if (!Boolean.getBoolean(ContainerManager.PROP_ECLIPSE_APPLICATION_NODEFAULT)) {
- // find the default application
- EclipseAppDescriptor defaultDesc = findDefaultApp();
- // if the default app is a main thread one then we have to just tell the
- // main thread container about the default app so it can launch it when it is ready
- if (APP_TYPE_MAIN_THREAD.equals(defaultDesc.getType())) {
- MainThreadContainer container = (MainThreadContainer) ((SingletonContainer) getContainer(APP_TYPE_MAIN_THREAD)).getContainer();
- container.setDefaultApp(defaultDesc);
- } else
- // just launch the default application
- try {
- defaultDesc.launch(null);
- } catch (Exception e) {
- // TODO should log this!!
- }
- }
- }
-
- private EclipseAppDescriptor findDefaultApp() {
- String applicationId = System.getProperty(PROP_ECLIPSE_APPLICATION);
- if (applicationId == null) {
- //Derive the application from the product information
- applicationId = getProductAppId();
- if (applicationId != null)
- // use the long way to set the property to compile against eeminimum
- System.getProperties().setProperty(PROP_ECLIPSE_APPLICATION, applicationId);
- }
- if (applicationId == null) {
- // the application id is not set; return a descriptor that will throw an exception
- // return new EclipseAppDescriptor(Activator.PI_APP, Activator.PI_APP + ".missingapp", null, false, this, new RuntimeException(Messages.application_noIdFound)); //$NON-NLS-1$
- ErrorApplication.setError(new RuntimeException(Messages.application_noIdFound));
- return getAppDescriptor(EXT_ERROR_APP);
- }
- EclipseAppDescriptor defaultApp = getAppDescriptor(applicationId);
- if (defaultApp == null) {
- // the application id is not available in the registry; return a descriptor that will throw an exception
- //return new EclipseAppDescriptor(applicationId, applicationId, null, false, this, new RuntimeException(NLS.bind(Messages.application_notFound, applicationId, getAvailableAppsMsg(getExtensionRegistry()))));
- ErrorApplication.setError(new RuntimeException(NLS.bind(Messages.application_notFound, applicationId, getAvailableAppsMsg(getExtensionRegistry()))));
- return getAppDescriptor(EXT_ERROR_APP);
- }
- return defaultApp;
- }
-
- /*
- * Registers an ApplicationDescriptor service for each eclipse application
- * available in the extension registry.
- */
- private void registerAppDecriptors() {
- // look in the old core.runtime applications extension point
- IExtension[] availableApps = getAvailableApps(getExtensionRegistry(), PI_RUNTIME);
- for (int i = 0; i < availableApps.length; i++)
- createAppDescriptor(availableApps[i]);
- // look in the new equinox.app applications extinsion point
- availableApps = getAvailableApps(getExtensionRegistry(), Activator.PI_APP);
- for (int i = 0; i < availableApps.length; i++)
- createAppDescriptor(availableApps[i]);
- }
-
- private IContainer createContainer(String type) {
- IExtensionPoint extPoint = getExtensionRegistry().getExtensionPoint(Activator.PI_APP, PT_CONTAINERS);
- if (extPoint == null)
- return null;
- IExtension[] availableContainers = extPoint.getExtensions();
- for (int i = 0; i < availableContainers.length; i++) {
- IConfigurationElement[] configs = availableContainers[i].getConfigurationElements();
- if (configs.length == 0)
- return null;
- String containerType = configs[0].getAttribute(PT_APP_TYPE);
- if (type.equals(containerType)) {
- boolean singleton = Boolean.valueOf(configs[0].getAttribute(PT_APP_SINGLETON)).booleanValue();
- return createContainer(configs[0], type, singleton);
- }
- }
- return null;
- }
-
- private IContainer createContainer(IConfigurationElement config, String type, boolean singleton) {
- try {
- IContainer container = (IContainer) config.createExecutableExtension(PT_RUN);
- if (singleton)
- container = new SingletonContainer(container, type, this);
- return container;
- } catch (CoreException e) {
- // TODO should log this
- e.printStackTrace();
- }
- return null;
- }
-
- private IContainer removeContainer(IExtension containerExt) {
- IConfigurationElement[] configs = containerExt.getConfigurationElements();
- if (configs.length == 0)
- return null;
- String type = configs[0].getAttribute(PT_APP_TYPE);
- if (type == null)
- return null;
- // stop all applications for the container first
- stopAllApplications(type);
- IContainer result = null;
- synchronized (containers) {
- result = (IContainer) containers.remove(type);
- }
- // shutdown the container
- if (result != null)
- result.shutdown();
- return result;
- }
-
- /*
- * Returns a list of all the available application IDs which are available
- * in the extension registry.
- */
- private IExtension[] getAvailableApps(IExtensionRegistry registry, String pi) {
- IExtensionPoint point = registry.getExtensionPoint(pi + '.' + PT_APPLICATIONS);
- if (point == null)
- return new IExtension[0];
- return point.getExtensions();
- }
-
- private String getAvailableAppsMsg(IExtensionRegistry registry) {
- IExtension[] availableApps = getAvailableApps(registry, PI_RUNTIME);
- String availableAppsMsg = "<NONE>"; //$NON-NLS-1$
- if (availableApps.length != 0) {
- availableAppsMsg = availableApps[0].getUniqueIdentifier();
- for (int i = 1; i < availableApps.length; i++)
- availableAppsMsg = availableAppsMsg + ", " + availableApps[i].getUniqueIdentifier(); //$NON-NLS-1$
- }
- availableApps = getAvailableApps(registry, Activator.PI_APP);
- if (availableApps.length != 0) {
- if (!availableAppsMsg.equals("<NONE>")) //$NON-NLS-1$
- availableAppsMsg = availableAppsMsg + ", "; //$NON-NLS-1$
- availableAppsMsg = availableAppsMsg + availableApps[0].getUniqueIdentifier();
- for (int i = 1; i < availableApps.length; i++)
- availableAppsMsg = availableAppsMsg + ", " + availableApps[i].getUniqueIdentifier(); //$NON-NLS-1$
- }
- return availableAppsMsg;
- }
-
- /*
- * Returns the application extension for the specified applicaiton ID.
- * A RuntimeException is thrown if the extension does not exist for the
- * given application ID.
- */
- IExtension getAppExtension(String applicationId) {
- IExtensionRegistry registry = getExtensionRegistry();
- IExtension applicationExtension = registry.getExtension(PI_RUNTIME, PT_APPLICATIONS, applicationId);
- if (applicationExtension == null)
- applicationExtension = registry.getExtension(Activator.PI_APP, PT_APPLICATIONS, applicationId);
- if (applicationExtension == null)
- throw new RuntimeException(NLS.bind(Messages.application_notFound, applicationId, getAvailableAppsMsg(registry)));
- return applicationExtension;
- }
-
- private IExtensionRegistry getExtensionRegistry() {
- return extensionRegistry;
- }
-
- private FrameworkLog getFrameworkLog() {
- return (FrameworkLog) AppPersistenceUtil.getService(frameworkLog);
- }
-
- private String getProductAppId() {
- String productId = System.getProperty(PROP_PRODUCT);
- if (productId == null)
- return null;
- IConfigurationElement[] entries = getExtensionRegistry().getConfigurationElementsFor(PI_RUNTIME, PT_PRODUCTS, productId);
- if (entries.length > 0)
- // There should only be one product with the given id so just take the first element
- return entries[0].getAttribute(ATTR_APPLICATION);
- IConfigurationElement[] elements = getExtensionRegistry().getConfigurationElementsFor(PI_RUNTIME, PT_PRODUCTS);
- List logEntries = null;
- for (int i = 0; i < elements.length; i++) {
- IConfigurationElement element = elements[i];
- if (element.getName().equalsIgnoreCase("provider")) { //$NON-NLS-1$
- try {
- Object provider = element.createExecutableExtension(PT_RUN);
- Object[] products = (Object[]) ContainerManager.execMethod(provider, "getProducts", null, null); //$NON-NLS-1$
- for (int j = 0; j < products.length; j++) {
- Object provided = products[j];
- if (productId.equalsIgnoreCase((String) ContainerManager.execMethod(provided, "getId", null, null))) //$NON-NLS-1$
- return (String) ContainerManager.execMethod(provided, "getApplication", null, null); //$NON-NLS-1$
- }
- } catch (CoreException e) {
- if (logEntries == null)
- logEntries = new ArrayList(3);
- logEntries.add(new FrameworkLogEntry(Activator.PI_APP, NLS.bind(Messages.provider_invalid, element.getParent().toString()), 0, e, null));
- }
- }
- }
- if (logEntries != null)
- getFrameworkLog().log(new FrameworkLogEntry(Activator.PI_APP, Messages.provider_invalid_general, 0, null, (FrameworkLogEntry[]) logEntries.toArray()));
-
- if (!missingProductReported) {
- getFrameworkLog().log(new FrameworkLogEntry(Activator.PI_APP, NLS.bind(Messages.product_notFound, productId), 0, null, null));
- missingProductReported = true;
- }
- return null;
- }
-
- public static Object execMethod(Object obj, String methodName, Class argType, Object arg) {
- try {
- Method method = obj.getClass().getMethod(methodName, argType == null ? null : new Class[] {argType});
- return method.invoke(obj, arg == null ? null : new Object[] {arg});
- } catch (NoSuchMethodException e) {
- throw new IllegalArgumentException(e.getMessage());
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(e.getMessage());
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(e.getMessage());
- } catch (InvocationTargetException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- }
-
- void launch(EclipseAppHandle appHandle) throws Exception {
- String type = ((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getType();
- if (type == null)
- type = APP_TYPE_MAIN_THREAD;
- IContainer container = getContainer(type);
- if (container != null)
- appHandle.setApplication(container.launch(appHandle));
- else
- throw new UnsupportedOperationException(NLS.bind(Messages.container_notFound, appHandle.getApplicationDescriptor().getApplicationId(), type));
- }
-
- public void registryChanged(IRegistryChangeEvent event) {
- processAppDeltas(event.getExtensionDeltas(PI_RUNTIME, PT_APPLICATIONS));
- processAppDeltas(event.getExtensionDeltas(Activator.PI_APP, PT_APPLICATIONS));
- processContainerDeltas(event.getExtensionDeltas(Activator.PI_APP, PT_CONTAINERS));
- }
-
- private void processAppDeltas(IExtensionDelta[] deltas) {
- for (int i = 0; i < deltas.length; i++) {
- switch (deltas[i].getKind()) {
- case IExtensionDelta.ADDED :
- createAppDescriptor(deltas[i].getExtension());
- break;
- case IExtensionDelta.REMOVED :
- removeAppDescriptor(deltas[i].getExtension().getUniqueIdentifier());
- break;
- }
- }
- }
-
- private void processContainerDeltas(IExtensionDelta[] deltas) {
- for (int i = 0; i < deltas.length; i++) {
- switch (deltas[i].getKind()) {
- case IExtensionDelta.ADDED :
- // don't create containers agressively
- break;
- case IExtensionDelta.REMOVED :
- removeContainer(deltas[i].getExtension());
- break;
- }
- }
- }
-
- public void bundleChanged(BundleEvent event) {
- // if this is not the system bundle stopping then ignore the event
- if ((BundleEvent.STOPPING & event.getType()) == 0 || event.getBundle().getBundleId() != 0)
- return;
- // The system bundle is stopping; better stop all applications and containers now
- stopAll();
- }
-
- private void stopAllApplications(String type) {
- try {
- ServiceReference[] runningRefs = context.getServiceReferences(ApplicationHandle.class.getName(), "(&(eclipse.application.type=" + type + ")(!(application.state=STOPPING)))"); //$NON-NLS-1$ //$NON-NLS-2$
- if (runningRefs != null)
- for (int i = 0; i < runningRefs.length; i++) {
- ApplicationHandle handle = (ApplicationHandle) context.getService(runningRefs[i]);
- try {
- handle.destroy();
- } catch (Throwable t) {
- // just ignore; nothing we can really do and we need to continue
- }
- }
- } catch (InvalidSyntaxException e) {
- // do nothing; we already tested the filter string above
- }
- }
-
- private void stopAll() {
- // get a stapshot of running applications
- try {
- ServiceReference[] runningRefs = context.getServiceReferences(ApplicationHandle.class.getName(), "(!(application.state=STOPPING))"); //$NON-NLS-1$
- if (runningRefs != null)
- for (int i = 0; i < runningRefs.length; i++) {
- ApplicationHandle handle = (ApplicationHandle) context.getService(runningRefs[i]);
- try {
- handle.destroy();
- } catch (Throwable t) {
- // TODO should log this
- }
- }
- } catch (InvalidSyntaxException e) {
- // do nothing; we already tested the filter string above
- }
- // shutdown all containers
- synchronized (containers) {
- for (Iterator iContainers = containers.values().iterator(); iContainers.hasNext();)
- ((IContainer) iContainers.next()).shutdown();
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadApplication.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadApplication.java
deleted file mode 100755
index d4a6e7da6..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadApplication.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.app;
-
-import org.eclipse.equinox.app.IAppContext;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.osgi.service.runnable.ApplicationRunnable;
-import org.eclipse.osgi.util.NLS;
-
-public class MainThreadApplication implements ApplicationRunnable {
- private static final String PROP_ECLIPSE_EXITCODE = "eclipse.exitcode"; //$NON-NLS-1$
- private Object application;
- private EclipseAppHandle appContext;
- private Exception launchException;
-
- public MainThreadApplication(EclipseAppHandle appContext) {
- this.appContext = appContext;
- try {
- application = appContext.getConfiguration().createExecutableExtension("run"); //$NON-NLS-1$
- } catch (Exception e) {
- // had an error creating the executable extension
- // save the exception to throw on the main thread (keeping legacy behavior)
- this.launchException = e;
- }
- }
-
- public Object run(Object context) throws Exception {
- // if the given arg is null then pass in the left over command line args.
- if (context == null)
- context = AppPersistenceUtil.getApplicationArgs();
- Object result;
- try {
- if (launchException != null)
- // this is a dummy handle used to throw an exception on the main thread.
- throw launchException;
- if (application instanceof IApplication) {
- result = ((IApplication) application).run(context);
- } else
- result = ContainerManager.execMethod(application, "run", Object.class, context); //$NON-NLS-1$
- } finally {
- application = null;
- // The application exited itself; notify the app context
- appContext.setAppStatus(IAppContext.STOPPED);
- }
- int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
- // use the long way to set the property to compile against eeminimum
- System.getProperties().setProperty(PROP_ECLIPSE_EXITCODE, Integer.toString(exitCode));
- if (Activator.DEBUG)
- System.out.println(NLS.bind(Messages.application_returned, (new String[] {appContext.getApplicationDescriptor().getApplicationId(), result == null ? "null" : result.toString()}))); //$NON-NLS-1$
- return result;
- }
-
- public void stop() {
- // we can only handle forced stops if this application is an IApplication
- if (application instanceof IApplication)
- ((IApplication) application).stop();
- }
-
- IApplication getApplication() {
- return (IApplication) ((application instanceof IApplication) ? application : null);
- }
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadContainer.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadContainer.java
deleted file mode 100755
index 203aa96fb..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/MainThreadContainer.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.app;
-
-import org.eclipse.equinox.app.*;
-import org.eclipse.osgi.service.runnable.ApplicationLauncher;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-public class MainThreadContainer implements IContainer, ServiceTrackerCustomizer {
- // tracks the application launcher
- private ServiceTracker appLauncherTracker;
- // the application launcher used to launch applications on the main thread.
- private ApplicationLauncher appLauncher;
- // the default app to launch once we are ready
- private EclipseAppDescriptor defaultDesc;
-
- public MainThreadContainer() {
- appLauncherTracker = new ServiceTracker(AppPersistenceUtil.getContext(), ApplicationLauncher.class.getName(), this);
- appLauncherTracker.open();
- }
-
- public IApplication launch(IAppContext appContext) {
- // use the ApplicationLauncher provided by the framework
- // to ensure it is launched on the main thread
- if (appLauncher == null)
- throw new IllegalStateException();
- MainThreadApplication app = new MainThreadApplication((EclipseAppHandle) appContext);
- appLauncher.launch(app, appContext.getArguments() == null ? null : appContext.getArguments().get(ContainerManager.PROP_ECLIPSE_APPLICATION_ARGS));
- return app.getApplication();
- }
-
- public Object addingService(ServiceReference reference) {
- if (appLauncher != null)
- return null;
- appLauncher = (ApplicationLauncher) AppPersistenceUtil.getContext().getService(reference);
- if (defaultDesc != null)
- // launch the default application
- try {
- defaultDesc.launch(null);
- defaultDesc = null; // don't want to launch it more than once
- } catch (Exception e) {
- // TODO should log this!!
- }
- return appLauncher;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- // do nothing
- }
-
- public synchronized void removedService(ServiceReference reference, Object service) {
- if (service == appLauncher) {
- appLauncher = null;
- AppPersistenceUtil.getContext().ungetService(reference);
- }
- }
-
- public void shutdown() {
- if (appLauncherTracker != null) {
- appLauncherTracker.close();
- appLauncherTracker = null;
- }
- }
-
- public void setDefaultApp(EclipseAppDescriptor defaultDesc) {
- this.defaultDesc = defaultDesc;
- }
-}
diff --git a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/SingletonContainer.java b/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/SingletonContainer.java
deleted file mode 100755
index 8b61feee9..000000000
--- a/bundles/org.eclipse.equinox.app/src/org/eclipse/equinox/internal/app/SingletonContainer.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.app;
-
-import org.eclipse.equinox.app.*;
-
-public class SingletonContainer implements IContainer {
- private EclipseAppHandle singletonHandle;
- private String type;
- private IContainer singletonContainer;
- private ContainerManager containerManager;
-
- public SingletonContainer(IContainer singletonContainer, String type, ContainerManager containerManager) {
- this.singletonContainer = singletonContainer;
- this.type = type;
- this.containerManager = containerManager;
- }
-
- public synchronized IApplication launch(IAppContext context) throws Exception {
- // attempt to lock this application type; an exception will be thrown if the type cannot be locked
- lock((EclipseAppHandle) context);
- return singletonContainer.launch(context);
- }
-
- public boolean isSingletonContainer() {
- return true;
- }
-
- synchronized boolean isLocked() {
- return singletonHandle != null;
- }
-
- synchronized void lock(EclipseAppHandle appHandle) {
- if (singletonHandle != null)
- throw new IllegalStateException("Only one application of type \"" + type + "\" is allowed to run at a time");
- singletonHandle = appHandle;
- refreshAppDescriptors();
- }
-
- synchronized void unlock() {
- singletonHandle = null;
- refreshAppDescriptors();
- }
-
- private void refreshAppDescriptors() {
- EclipseAppDescriptor[] singletonApps = containerManager.getAppDescriptorsByType(type);
- for (int i = 0; i < singletonApps.length; i++) {
- singletonApps[i].setSingletonMgr(this);
- singletonApps[i].refreshProperties();
- }
- }
-
- public void shutdown() {
- singletonContainer.shutdown();
- }
-
- IContainer getContainer() {
- return singletonContainer;
- }
-}

Back to the top