Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpnehrer2005-02-16 17:31:01 -0500
committerpnehrer2005-02-16 17:31:01 -0500
commitcbb573994878430ad13a7d61a4af264d5d8747cf (patch)
tree767d979ff970d48ba48142281b5c5a08fbdc8598 /examples/bundles/org.eclipse.ecf.sdo/src/org
parent67381d642155defa5ed87968c112afb24c2c8b2a (diff)
downloadorg.eclipse.ecf-cbb573994878430ad13a7d61a4af264d5d8747cf.tar.gz
org.eclipse.ecf-cbb573994878430ad13a7d61a4af264d5d8747cf.tar.xz
org.eclipse.ecf-cbb573994878430ad13a7d61a4af264d5d8747cf.zip
Started adding extension points.
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.sdo/src/org')
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/DataGraphSharingFactory.java51
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharingManager.java23
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java212
3 files changed, 225 insertions, 61 deletions
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/DataGraphSharingFactory.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/DataGraphSharingFactory.java
new file mode 100644
index 000000000..8e809fe67
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/DataGraphSharingFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * 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:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import java.util.Hashtable;
+
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * @author pnehrer
+ */
+public class DataGraphSharingFactory {
+
+ private static final Hashtable managers = new Hashtable();
+
+ private DataGraphSharingFactory() {
+ }
+
+ public static final IDataGraphSharing getDataGraphSharing(
+ ISharedObjectContainer container, String name) throws ECFException {
+
+ IDataGraphSharingManager instantiator = (IDataGraphSharingManager) managers
+ .get(name);
+ if (instantiator == null)
+ return null;
+ else
+ return instantiator.getInstance(container);
+ }
+
+ public static void registerManager(String name,
+ IDataGraphSharingManager manager) {
+ managers.put(name, manager);
+ }
+
+ public static void unregisterManager(String name) {
+ managers.remove(name);
+ }
+
+ static void unregisterAllManagers() {
+ managers.clear();
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharingManager.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharingManager.java
new file mode 100644
index 000000000..d25add664
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharingManager.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * 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:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * @author pnehrer
+ */
+public interface IDataGraphSharingManager {
+
+ IDataGraphSharing getInstance(ISharedObjectContainer container)
+ throws ECFException;
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java
index b321e143f..4a3b91127 100644
--- a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java
@@ -10,6 +10,12 @@
*******************************************************************************/
package org.eclipse.ecf.sdo;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.ecf.core.ISharedObjectContainer;
import org.eclipse.ecf.core.ISharedObjectManager;
@@ -24,69 +30,153 @@ import org.osgi.framework.BundleContext;
* {@link org.eclipse.ecf.sdo.IDataGraphSharing IDataGraphSharing}factory.
*
* @author pnehrer
+ * @deprecated Use
+ * {@link org.eclipse.ecf.sdo.DataGraphSharingFactory DataGraphSharingFactory}
+ * instead.
*/
public class SDOPlugin extends Plugin {
- // The shared instance.
- private static SDOPlugin plugin;
-
- private boolean debug;
-
- /**
- * The constructor.
- */
- public SDOPlugin() {
- super();
- plugin = this;
- }
-
- /**
- * This method is called upon plug-in activation
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- }
-
- /**
- * This method is called when the plug-in is stopped
- */
- public void stop(BundleContext context) throws Exception {
- super.stop(context);
- }
-
- /**
- * Returns the shared instance.
- */
- public static SDOPlugin getDefault() {
- return plugin;
- }
-
- public IDataGraphSharing getDataGraphSharing(
- ISharedObjectContainer container) throws ECFException {
-
- ISharedObjectManager mgr = container.getSharedObjectManager();
- ID id = IDFactory.makeStringID(DataGraphSharing.DATA_GRAPH_SHARING_ID);
- synchronized (container) {
- DataGraphSharing result = (DataGraphSharing) mgr
- .getSharedObject(id);
- if (result == null) {
- result = new DataGraphSharing();
- result.setDebug(debug);
- mgr.addSharedObject(id, result, null, null);
- }
-
- return result;
- }
- }
-
- /**
- * Sets the debug flag.
- *
- * @param debug
- * @deprecated Use Eclipse plug-in tracing support instead.
- */
- public void setDebug(boolean debug) {
- this.debug = debug;
- }
+ private static final String MANAGER_EXTENSION_POINT = "manager";
+
+ private static final String MANAGER_EXTENSION = "manager";
+
+ private static final String ATTR_NAME = "name";
+
+ private static final String ATTR_CLASS = "class";
+
+ // The shared instance.
+ private static SDOPlugin plugin;
+
+ private IRegistryChangeListener registryChangeListener;
+
+ private boolean debug;
+
+ /**
+ * The constructor.
+ */
+ public SDOPlugin() {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ registryChangeListener = new IRegistryChangeListener() {
+ public void registryChanged(IRegistryChangeEvent event) {
+ IExtensionDelta[] deltas = event.getExtensionDeltas(getBundle()
+ .getSymbolicName(), MANAGER_EXTENSION_POINT);
+ for (int i = 0; i < deltas.length; ++i) {
+ switch (deltas[i].getKind()) {
+ case IExtensionDelta.ADDED:
+ registerManagers(deltas[i].getExtension()
+ .getConfigurationElements());
+ break;
+
+ case IExtensionDelta.REMOVED:
+ IConfigurationElement[] elems = deltas[i]
+ .getExtension().getConfigurationElements();
+ for (int j = 0; j < elems.length; ++j) {
+ IConfigurationElement[] children = elems[j]
+ .getChildren(MANAGER_EXTENSION);
+ for (int k = 0; k < children.length; ++k) {
+ String name = children[k]
+ .getAttribute(ATTR_NAME);
+ if (name != null && name.length() > 0)
+ DataGraphSharingFactory
+ .unregisterManager(name);
+ }
+ }
+
+ break;
+ }
+ }
+ }
+ };
+
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ IConfigurationElement[] elems = reg.getConfigurationElementsFor(
+ getBundle().getSymbolicName(), MANAGER_EXTENSION_POINT);
+ registerManagers(elems);
+ }
+
+ private void registerManagers(IConfigurationElement[] elems) {
+ for (int i = 0; i < elems.length; ++i) {
+ IConfigurationElement[] children = elems[i]
+ .getChildren(MANAGER_EXTENSION);
+ for (int j = 0; j < children.length; ++j) {
+ String name = children[j].getAttribute(ATTR_NAME);
+ if (name == null || name.length() == 0)
+ continue;
+
+ IDataGraphSharingManager mgr;
+ try {
+ mgr = (IDataGraphSharingManager) children[j]
+ .createExecutableExtension(ATTR_CLASS);
+ } catch (Exception ex) {
+ continue;
+ }
+
+ DataGraphSharingFactory.registerManager(name, mgr);
+ }
+ }
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ if (registryChangeListener != null)
+ Platform.getExtensionRegistry().removeRegistryChangeListener(
+ registryChangeListener);
+
+ DataGraphSharingFactory.unregisterAllManagers();
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static SDOPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * @param container
+ * @return
+ * @throws ECFException
+ * @deprecated Use
+ * {@link DataGraphSharingFactory#getDataGraphSharing(ISharedObjectContainer, String) DataGraphSharingFactory.getDataGraphSharing(ISharedObjectContainer, String)}
+ * instead.
+ */
+ public IDataGraphSharing getDataGraphSharing(
+ ISharedObjectContainer container) throws ECFException {
+
+ ISharedObjectManager mgr = container.getSharedObjectManager();
+ ID id = IDFactory.makeStringID(DataGraphSharing.DATA_GRAPH_SHARING_ID);
+ synchronized (container) {
+ DataGraphSharing result = (DataGraphSharing) mgr
+ .getSharedObject(id);
+ if (result == null) {
+ result = new DataGraphSharing();
+ result.setDebug(debug);
+ mgr.addSharedObject(id, result, null, null);
+ }
+
+ return result;
+ }
+ }
+
+ /**
+ * Sets the debug flag.
+ *
+ * @param debug
+ * @deprecated Use Eclipse plug-in tracing support instead.
+ */
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
} \ No newline at end of file

Back to the top