diff options
author | Uwe Stieber | 2012-02-20 07:05:24 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-02-20 08:38:56 +0000 |
commit | ab8cd8c246dbb93b06f732f5a690114c77b8d4f4 (patch) | |
tree | 2b05fe06185529d356612bce07b8ccb010d5b47b | |
parent | 5e7e69a25a56b5a37634056d65c32e13c93ea3ad (diff) | |
download | org.eclipse.tcf-ab8cd8c246dbb93b06f732f5a690114c77b8d4f4.tar.gz org.eclipse.tcf-ab8cd8c246dbb93b06f732f5a690114c77b8d4f4.tar.xz org.eclipse.tcf-ab8cd8c246dbb93b06f732f5a690114c77b8d4f4.zip |
Target Explorer: Decode peer model type launch context
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java | 24 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepContext.java | 5 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/StepContextAdapter.java | 67 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java | 4 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/InvalidPeerModel.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/IllegalPeerModel.java) | 4 |
5 files changed, 89 insertions, 15 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java index ac1f84bd0..f81436419 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java @@ -151,7 +151,7 @@ public class ContextSelectorPersistenceDelegate { } catch (IOException e) { // Export to the string writer failed --> remove attribute from launch configuration - if (CoreBundleActivator.getTraceHandler().getDebugMode() > 0) { + if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); @@ -292,7 +292,7 @@ public class ContextSelectorPersistenceDelegate { } catch (Exception e) { // Import failed --> remove attribute from launch configuration - if (CoreBundleActivator.getTraceHandler().getDebugMode() > 0) { + if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); @@ -400,7 +400,7 @@ public class ContextSelectorPersistenceDelegate { try { clazz = (Class<IModelNode>)CoreBundleActivator.getContext().getBundle().loadClass(lastType); } catch (ClassNotFoundException e) { - if (CoreBundleActivator.getTraceHandler().getDebugMode() > 0) { + if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); @@ -428,7 +428,7 @@ public class ContextSelectorPersistenceDelegate { try { clazz = (Class<IModelNode>)bundle.loadClass(lastType); } catch (ClassNotFoundException e) { - if (CoreBundleActivator.getTraceHandler().getDebugMode() > 0) { + if (Platform.inDebugMode()) { IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); @@ -443,10 +443,18 @@ public class ContextSelectorPersistenceDelegate { if (object != null) { IStepContext context = (IStepContext)Platform.getAdapterManager().loadAdapter(object, IStepContext.class.getName()); if (context != null) { - // Decodes the context object - context.decode(lastData); - if (!contexts.contains(context)) { - contexts.add(context); + try { + // Decodes the context object + context.decode(lastData); + if (!contexts.contains(context)) { + contexts.add(context); + } + } catch (IOException e) { + if (Platform.inDebugMode()) { + IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$ + Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); + } } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepContext.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepContext.java index 47c9782ca..95afe26aa 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepContext.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.stepper/src/org/eclipse/tcf/te/runtime/stepper/interfaces/IStepContext.java @@ -9,6 +9,8 @@ *******************************************************************************/
package org.eclipse.tcf.te.runtime.stepper.interfaces;
+import java.io.IOException;
+
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNodeProvider;
@@ -71,6 +73,7 @@ public interface IStepContext extends IModelNodeProvider { * in the context.
*
* @param value The persistable representation of the context. Must not be <code>null</code>.
+ * @throws IOException - if the decode operation fails
*/
- public void decode(String value);
+ public void decode(String value) throws IOException;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/StepContextAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/StepContextAdapter.java index 06860df9c..2e21b7c3a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/StepContextAdapter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/StepContextAdapter.java @@ -16,17 +16,28 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.core.TransientPeer;
+import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.JSON;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
+import org.eclipse.tcf.te.tcf.launch.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+import org.eclipse.tcf.te.tcf.locator.internal.nodes.InvalidPeerModel;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
/**
* Peer model step context adapter implementation.
*/
+@SuppressWarnings("restriction")
public class StepContextAdapter extends PlatformObject implements IStepContext {
// Reference to the wrapped peer model
/* default */ IPeerModel peerModel;
@@ -133,7 +144,13 @@ public class StepContextAdapter extends PlatformObject implements IStepContext { encoded.set(JSON.toJSON(attrs));
}
- catch (IOException e) { /* ignored on purpose */ }
+ catch (IOException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "StepContextAdapter encode failure: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
}
};
@@ -155,7 +172,53 @@ public class StepContextAdapter extends PlatformObject implements IStepContext { * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext#decode(java.lang.String)
*/
@Override
- public void decode(String value) {
+ public void decode(final String value) throws IOException {
Assert.isNotNull(value);
+
+ final AtomicReference<IOException> error = new AtomicReference<IOException>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Object o = JSON.parseOne(value.getBytes("UTF-8")); //$NON-NLS-1$
+ // The decoded object should be a map
+ if (o instanceof Map) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> attrs = (Map<String, String>)o;
+
+ // Get the id of the decoded attributes
+ String id = attrs.get("ID"); //$NON-NLS-1$
+ if (id == null) throw new IOException("StepContextAdapter#decode: Mandatory attribure 'ID' is missing."); //$NON-NLS-1$
+
+ // If the ID is matching the associated peer model, than we are done here
+ if (peerModel != null && !(peerModel instanceof InvalidPeerModel) && peerModel.getPeerId().equals(id)) {
+ return;
+ }
+
+ // Lookup the id within the model
+ IPeerModel candidate = Model.getModel().getService(ILocatorModelLookupService.class).lkupPeerModelById(id);
+ if (candidate != null) {
+ peerModel = candidate;
+ return;
+ }
+
+ // Not found in the model -> create a ghost object
+ IPeer peer = new TransientPeer(attrs);
+ peerModel = new PeerModel(Model.getModel(), peer);
+ peerModel.setProperty(IModelNode.PROPERTY_IS_GHOST, true);
+ } else {
+ throw new IOException("StepContextAdapter#decode: Object not of map type."); //$NON-NLS-1$
+ }
+ } catch (IOException e) {
+ error.set(e);
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ if (error.get() != null) throw error.get();
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java index 1c20c3488..1c26f16e4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/ModelNodeFactoryDelegate.java @@ -14,7 +14,7 @@ import org.eclipse.tcf.te.runtime.model.factory.AbstractFactoryDelegate2; import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
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.internal.nodes.IllegalPeerModel;
+import org.eclipse.tcf.te.tcf.locator.internal.nodes.InvalidPeerModel;
import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel;
/**
@@ -29,7 +29,7 @@ public class ModelNodeFactoryDelegate extends AbstractFactoryDelegate2 { @Override
public <V extends IModelNode> V newInstance(Class<V> nodeInterface) {
if (IPeerModel.class.equals(nodeInterface)) {
- return (V) new IllegalPeerModel();
+ return (V) new InvalidPeerModel();
}
return null;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/IllegalPeerModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/InvalidPeerModel.java index 9ea71e60a..4d6325a0b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/IllegalPeerModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/nodes/InvalidPeerModel.java @@ -23,13 +23,13 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.internal.ModelNodeFactoryDelegate;
/**
- * Illegal peer model node implementation. All methods does throw an {@link IllegalStateException}.
+ * Invalid peer model node implementation. All methods does throw an {@link IllegalStateException}.
* <p>
* Objects of this class are returned by the {@link ModelNodeFactoryDelegate} if calling
* {@link IFactoryDelegate#newInstance(Class)}. All what objects of this class can be used for is
* loading adapters.
*/
-public final class IllegalPeerModel implements IPeerModel {
+public final class InvalidPeerModel implements IPeerModel {
/* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.model.interfaces.IContainerModelNode#add(org.eclipse.tcf.te.runtime.model.interfaces.IModelNode)
|