Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2012-01-06 18:32:53 +0000
committerEugene Tarassov2012-01-06 18:32:53 +0000
commit8628e7e335020bf7cc1f5bf5dd39c6a97843464f (patch)
tree1e0cd8a07a2d2b1020ecd659e2c134f5dc53e806
parenta8ba440b1951be24b136d5e0ccb51d32836abd4b (diff)
parent29c85790ed71726b1429a0edfd41d0ffb144d08a (diff)
downloadorg.eclipse.tcf-8628e7e335020bf7cc1f5bf5dd39c6a97843464f.tar.gz
org.eclipse.tcf-8628e7e335020bf7cc1f5bf5dd39c6a97843464f.tar.xz
org.eclipse.tcf-8628e7e335020bf7cc1f5bf5dd39c6a97843464f.zip
Merge branch 'juno-refactoring' of ssh://git.eclipse.org/gitroot/tcf/org.eclipse.tcf into juno-refactoring
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/META-INF/MANIFEST.MF8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/build.properties3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/plugin.xml14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/interfaces/IContexts.java99
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/AdapterFactory.java80
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/ContextsProxy.java96
6 files changed, 298 insertions, 2 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/META-INF/MANIFEST.MF
index d9a7c5455..3d9845938 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/META-INF/MANIFEST.MF
@@ -6,6 +6,12 @@ Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.tcf.te.tcf.services.contexts.activator.CoreBundleActivator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
- org.eclipse.tcf.te.runtime;bundle-version="1.0.0"
+ org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
+ org.eclipse.tcf;bundle-version="1.0.0",
+ org.eclipse.tcf.core;bundle-version="1.0.0",
+ org.eclipse.tcf.te.tcf.locator;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.tcf.te.tcf.services.contexts.activator;x-internal:=true,
+ org.eclipse.tcf.te.tcf.services.contexts.interfaces,
+ org.eclipse.tcf.te.tcf.services.contexts.internal;x-internal:=true
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/build.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/build.properties
index 41eb6ade2..6f20375d6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/build.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ plugin.xml
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/plugin.xml
new file mode 100644
index 000000000..492fc12ee
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+<!-- Adapter factory contributions -->
+ <extension point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.tcf.protocol.IPeer"
+ class="org.eclipse.tcf.te.tcf.services.contexts.internal.AdapterFactory">
+ <adapter type="org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts"/>
+ </factory>
+ </extension>
+
+</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/interfaces/IContexts.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/interfaces/IContexts.java
new file mode 100644
index 000000000..f9bec85d1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/interfaces/IContexts.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.services.contexts.interfaces;
+
+import org.eclipse.tcf.protocol.IService;
+
+/**
+ * TCF contexts service.
+ */
+public interface IContexts extends IService {
+
+ /**
+ * The service name.
+ */
+ public static final String NAME = "Contexts"; //$NON-NLS-1$
+
+ /**
+ * Context handler delegate.
+ */
+ public interface IDelegate {
+
+ /**
+ * Checks if the delegate can handle the context identified by the
+ * given id.
+ *
+ * @param contextID The context id. Must not be <code>null</code>.
+ * @return <code>True</code> if the delegate can handle the context id, <code>false</code> otherwise.
+ */
+ public boolean canHandle(String contextID);
+
+ /**
+ * Returns the name of the context identified by the given id.
+ *
+ * @param contextID The context id. Must not be <code>null</code>.
+ * @return The name of the context, or <code>null</code> if the context does not exist
+ * or is not handled by this delegate.
+ */
+ public String getName(String contextID);
+
+ /**
+ * Checks if the context identified by the given id is available. Available in this
+ * context means other clients can access data for this context.
+ *
+ * @param contextID The context id. Must not be <code>null</code>.
+ * @return <code>True</code> if the context is available, <code>false</code> otherwise.
+ */
+ public boolean isAvailable(String contextID);
+
+ /**
+ * Client call back interface for makeAvailable().
+ */
+ public interface DoneMakeAvailable {
+ /**
+ * Called when context has been made available.
+ *
+ * @param error The error description if the operation failed, <code>null</code> if succeeded.
+ */
+ void doneMakeAvailable(Exception error);
+ }
+
+ /**
+ * Attempt to make the context identified by the given id available to other
+ * clients.
+ *
+ * @param contextID The context id. Must not be <code>null</code>.
+ * @param done The call back interface called when the operation is completed. Must not be <code>null</code>.
+ */
+ public void makeAvailable(String contextID, DoneMakeAvailable done);
+ }
+
+ /**
+ * Returns the first delegate that can handle the given context ID.
+ *
+ * @param contextID The context id. Must not be <code>null</code>.
+ * @return The delegate or <code>null</code>.
+ */
+ public IDelegate getDelegate(String contextID);
+
+ /**
+ * Adds the given context handler delegate to the service.
+ *
+ * @param delegate The context handler delegate. Must not be <code>null</code>.
+ */
+ public void addDelegate(IDelegate delegate);
+
+ /**
+ * Removes the given context handler delegate from the service.
+ *
+ * @param delegate The context handler delegate. Must not be <code>null</code>.
+ */
+ public void removeDelegate(IDelegate delegate);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/AdapterFactory.java
new file mode 100644
index 000000000..d78d2a2cd
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/AdapterFactory.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.services.contexts.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.te.runtime.interfaces.IDisposable;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.listener.ModelAdapter;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts;
+
+/**
+ * Contexts service adapter factory implementation.
+ */
+public class AdapterFactory implements IAdapterFactory {
+ // Maintain a map of contexts service proxy per peer
+ /* default */ Map<IPeer, IContexts> proxies = new HashMap<IPeer, IContexts>();
+
+ private static final Class<?>[] CLASSES = new Class[] {
+ IContexts.class
+ };
+
+ /**
+ * Constructor.
+ */
+ public AdapterFactory() {
+ Model.getModel().addListener(new ModelAdapter() {
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.locator.listener.ModelAdapter#locatorModelChanged(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel, org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel, boolean)
+ */
+ @Override
+ public void locatorModelChanged(ILocatorModel model, IPeerModel peer, boolean added) {
+ // If a peer gets removed, remove the context service proxy
+ if (peer != null && peer.getPeer() != null) {
+ IContexts proxy = proxies.remove(peer.getPeer());
+ if (proxy instanceof IDisposable) ((IDisposable)proxy).dispose();
+ }
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adaptableObject instanceof IPeer) {
+ // Lookup the proxy
+ IContexts proxy = proxies.get(adaptableObject);
+ // No proxy yet -> create a new one for this peer
+ if (proxy == null) {
+ proxy = new ContextsProxy((IPeer)adaptableObject);
+ proxies.put((IPeer)adaptableObject, proxy);
+ }
+ return proxy;
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @Override
+ public Class[] getAdapterList() {
+ return CLASSES;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/ContextsProxy.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/ContextsProxy.java
new file mode 100644
index 000000000..328f3f206
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.services.contexts/src/org/eclipse/tcf/te/tcf/services/contexts/internal/ContextsProxy.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. 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:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.services.contexts.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.protocol.IPeer;
+import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.runtime.interfaces.IDisposable;
+import org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts;
+
+/**
+ * Contexts service proxy implementation.
+ */
+public class ContextsProxy implements IContexts, IDisposable {
+ // The peer instance the proxy is associated with
+ /* default */ final IPeer peer;
+
+ // The list of context handler delegates
+ private final List<IContexts.IDelegate> delegates = new ArrayList<IContexts.IDelegate>();
+
+ /**
+ * Constructor.
+ *
+ * @param peer The peer. Must not be <code>null</code>.
+ */
+ public ContextsProxy(IPeer peer) {
+ Assert.isNotNull(peer);
+ this.peer = peer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.protocol.IService#getName()
+ */
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.interfaces.IDisposable#dispose()
+ */
+ @Override
+ public void dispose() {
+ // Clear out the delegates list
+ delegates.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts#getDelegate(java.lang.String)
+ */
+ @Override
+ public IDelegate getDelegate(String contextID) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(contextID);
+
+ // Make a snapshot of the registered delegates
+ IContexts.IDelegate[] candidates = delegates.toArray(new IContexts.IDelegate[delegates.size()]);
+ for (IContexts.IDelegate candidate : candidates) {
+ if (candidate.canHandle(contextID)) {
+ return candidate;
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts#addDelegate(org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts.IDelegate)
+ */
+ @Override
+ public void addDelegate(IDelegate delegate) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(delegate);
+ if (!delegates.contains(delegate)) delegates.add(delegate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts#removeDelegate(org.eclipse.tcf.te.tcf.services.contexts.interfaces.IContexts.IDelegate)
+ */
+ @Override
+ public void removeDelegate(IDelegate delegate) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ Assert.isNotNull(delegate);
+ delegates.remove(delegate);
+ }
+}

Back to the top